2 * Server functions which perform operations on user objects.
4 * Copyright (c) 1987-2020 by the citadel.org team
6 * This program is open source software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License, version 3.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
16 #include <libcitadel.h>
17 #include "citserver.h"
18 #include "svn_revision.h"
19 #include "ctdl_module.h"
23 void cmd_noop(char *argbuf)
25 cprintf("%d%cok\n", CIT_OK, CtdlCheckExpress() );
29 void cmd_qnop(char *argbuf)
31 /* do nothing, this command returns no response */
36 * Set or unset asynchronous protocol mode
38 void cmd_asyn(char *argbuf)
42 new_state = extract_int(argbuf, 0);
43 if ((new_state == 0) || (new_state == 1)) {
44 CC->is_async = new_state;
46 cprintf("%d %d\n", CIT_OK, CC->is_async);
51 * cmd_info() - Identify this server and its capabilities to the client
53 void cmd_info(char *cmdbuf) {
54 cprintf("%d Server info:\n", LISTING_FOLLOWS);
55 cprintf("%d\n", CC->cs_pid);
56 cprintf("%s\n", CtdlGetConfigStr("c_nodename"));
57 cprintf("%s\n", CtdlGetConfigStr("c_humannode"));
58 cprintf("%s\n", CtdlGetConfigStr("c_fqdn"));
59 cprintf("%s\n", CITADEL);
60 cprintf("%d\n", REV_LEVEL);
61 cprintf("%s\n", CtdlGetConfigStr("c_site_location"));
62 cprintf("%s\n", CtdlGetConfigStr("c_sysadm"));
63 cprintf("%d\n", SERVER_TYPE);
64 cprintf("%s\n", CtdlGetConfigStr("c_moreprompt"));
65 cprintf("1\n"); /* 1 = yes, this system supports floors */
66 cprintf("1\n"); /* 1 = we support the extended paging options */
67 cprintf("\n"); /* no longer used */
68 cprintf("1\n"); /* 1 = yes, this system supports the QNOP command */
69 cprintf("1\n"); /* 1 = yes, this server is LDAP-enabled */
71 if ((CtdlGetConfigInt("c_auth_mode") == AUTHMODE_NATIVE) && (CtdlGetConfigInt("c_disable_newu") == 0))
73 cprintf("%d\n", CtdlGetConfigInt("c_disable_newu"));
76 cprintf("1\n"); /* "create new user" does not work with non-native auth modes */
79 cprintf("%s\n", CtdlGetConfigStr("c_default_cal_zone"));
81 cprintf("0\n"); /* no longer used */
82 cprintf("0\n"); /* no longer used */
83 cprintf("0\n"); /* no longer used */
84 cprintf("0\n"); /* no longer used */
86 cprintf("%d\n", CtdlGetConfigInt("c_enable_fulltext"));
87 cprintf("%s\n", svn_revision());
89 if (CtdlGetConfigInt("c_auth_mode") == AUTHMODE_NATIVE) {
90 cprintf("%d\n", openid_level_supported); /* OpenID is enabled when using native auth */
93 cprintf("0\n"); /* OpenID is disabled when using non-native auth */
96 cprintf("%d\n", CtdlGetConfigInt("c_guest_logins"));
104 void cmd_echo(char *etext)
106 cprintf("%d %s\n", CIT_OK, etext);
111 * get the paginator prompt
113 void cmd_more(char *argbuf) {
114 cprintf("%d %s\n", CIT_OK, CtdlGetConfigStr("c_moreprompt"));
119 * the client is identifying itself to the server
121 void cmd_iden(char *argbuf)
129 if (num_parms(argbuf)<4) {
130 cprintf("%d usage error\n", ERROR + ILLEGAL_VALUE);
134 dev_code = extract_int(argbuf,0);
135 cli_code = extract_int(argbuf,1);
136 rev_level = extract_int(argbuf,2);
137 extract_token(desc, argbuf, 3, '|', sizeof desc);
139 safestrncpy(from_host, CtdlGetConfigStr("c_fqdn"), sizeof from_host);
140 from_host[sizeof from_host - 1] = 0;
141 if (num_parms(argbuf)>=5) extract_token(from_host, argbuf, 4, '|', sizeof from_host);
143 CC->cs_clientdev = dev_code;
144 CC->cs_clienttyp = cli_code;
145 CC->cs_clientver = rev_level;
146 safestrncpy(CC->cs_clientname, desc, sizeof CC->cs_clientname);
147 CC->cs_clientname[31] = 0;
149 /* For local sockets, allow the client to supply the user's origin address */
150 if ((CC->is_local_client) || (!IsEmptyStr(CC->cs_addr) && (!strcmp(CC->cs_addr, "127.0.0.1")) || (!strcmp(CC->cs_addr, "::1")))) {
151 safestrncpy(CC->cs_host, from_host, sizeof CC->cs_host);
152 CC->cs_host[sizeof CC->cs_host - 1] = 0;
156 syslog(LOG_NOTICE, "session: client %d/%d/%01d.%02d (%s) from %s",
164 cprintf("%d Ok\n",CIT_OK);
169 * Terminate another running session
171 void cmd_term(char *cmdbuf)
173 int session_num = extract_int(cmdbuf, 0);
174 int terminated = CtdlTerminateOtherSession(session_num);
176 if (terminated < 0) {
177 cprintf("%d You can't kill your own session.\n", ERROR + ILLEGAL_VALUE);
181 if (terminated & TERM_FOUND) {
182 if (terminated == TERM_KILLED) {
183 cprintf("%d Session terminated.\n", CIT_OK);
186 cprintf("%d You are not allowed to do that.\n", ERROR + HIGHER_ACCESS_REQUIRED);
190 cprintf("%d No such session.\n", ERROR + ILLEGAL_VALUE);
195 void cmd_time(char *argbuf)
201 localtime_r(&tv, &tmp);
203 /* timezone and daylight global variables are not portable. */
204 #ifdef HAVE_STRUCT_TM_TM_GMTOFF
205 cprintf("%d %ld|%ld|%d|%ld\n", CIT_OK, (long)tv, tmp.tm_gmtoff, tmp.tm_isdst, server_startup_time);
207 cprintf("%d %ld|%ld|%d|%ld\n", CIT_OK, (long)tv, timezone, tmp.tm_isdst, server_startup_time);
212 /*****************************************************************************/
213 /* MODULE INITIALIZATION STUFF */
214 /*****************************************************************************/
216 CTDL_MODULE_INIT(serv_session)
219 CtdlRegisterProtoHook(cmd_noop, "NOOP", "no operation");
220 CtdlRegisterProtoHook(cmd_qnop, "QNOP", "no operation with no response");
221 CtdlRegisterProtoHook(cmd_asyn, "ASYN", "enable asynchronous server responses");
222 CtdlRegisterProtoHook(cmd_info, "INFO", "fetch server capabilities and configuration");
223 CtdlRegisterProtoHook(cmd_echo, "ECHO", "echo text back to the client");
224 CtdlRegisterProtoHook(cmd_more, "MORE", "fetch the paginator prompt");
225 CtdlRegisterProtoHook(cmd_iden, "IDEN", "identify the client software and location");
226 CtdlRegisterProtoHook(cmd_term, "TERM", "terminate another running session");
227 CtdlRegisterProtoHook(cmd_time, "TIME", "fetch the date and time from the server");
229 /* return our id for the Log */
230 return "serv_session";