2 * Server functions which perform operations on user objects.
4 * Copyright (c) 1987-2011 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.
24 #include <sys/types.h>
27 #ifdef HAVE_SYS_STAT_H
31 #if TIME_WITH_SYS_TIME
32 # include <sys/time.h>
36 # include <sys/time.h>
44 #include <libcitadel.h>
49 #include "sysdep_decls.h"
52 #include "svn_revision.h"
56 #include "citserver.h"
57 #include "citadel_dirs.h"
60 #include "citadel_ldap.h"
62 #include "ctdl_module.h"
64 void cmd_noop(char *argbuf)
66 cprintf("%d%cok\n", CIT_OK, CtdlCheckExpress() );
70 void cmd_qnop(char *argbuf)
72 /* do nothing, this command returns no response */
76 * Set or unset asynchronous protocol mode
78 void cmd_asyn(char *argbuf)
82 new_state = extract_int(argbuf, 0);
83 if ((new_state == 0) || (new_state == 1)) {
84 CC->is_async = new_state;
86 cprintf("%d %d\n", CIT_OK, CC->is_async);
92 * cmd_info() - tell the client about this server
94 void cmd_info(char *cmdbuf) {
95 cprintf("%d Server info:\n", LISTING_FOLLOWS);
96 cprintf("%d\n", CC->cs_pid);
97 cprintf("%s\n", config.c_nodename);
98 cprintf("%s\n", config.c_humannode);
99 cprintf("%s\n", config.c_fqdn);
100 cprintf("%s\n", CITADEL);
101 cprintf("%d\n", REV_LEVEL);
102 cprintf("%s\n", config.c_site_location);
103 cprintf("%s\n", config.c_sysadm);
104 cprintf("%d\n", SERVER_TYPE);
105 cprintf("%s\n", config.c_moreprompt);
106 cprintf("1\n"); /* 1 = yes, this system supports floors */
107 cprintf("1\n"); /* 1 = we support the extended paging options */
108 cprintf("\n"); /* nonce no longer supported */
109 cprintf("1\n"); /* 1 = yes, this system supports the QNOP command */
112 cprintf("1\n"); /* 1 = yes, this server is LDAP-enabled */
114 cprintf("0\n"); /* 1 = no, this server is not LDAP-enabled */
117 if ((config.c_auth_mode == AUTHMODE_NATIVE) &&
118 (config.c_disable_newu == 0))
120 cprintf("%d\n", config.c_disable_newu);
123 cprintf("1\n"); /* "create new user" does not work with non-native auth modes */
126 cprintf("%s\n", config.c_default_cal_zone);
128 /* thread load averages -- temporarily disabled during refactoring of this code */
129 cprintf("0\n"); /* load average */
130 cprintf("0\n"); /* worker average */
131 cprintf("0\n"); /* thread count */
133 cprintf("1\n"); /* yes, Sieve mail filtering is supported */
134 cprintf("%d\n", config.c_enable_fulltext);
135 cprintf("%s\n", svn_revision());
137 if (config.c_auth_mode == AUTHMODE_NATIVE) {
138 cprintf("%d\n", openid_level_supported); /* OpenID is enabled when using native auth */
141 cprintf("0\n"); /* OpenID is disabled when using non-native auth */
144 cprintf("%d\n", config.c_guest_logins);
152 void cmd_echo(char *etext)
154 cprintf("%d %s\n", CIT_OK, etext);
158 * get the paginator prompt
160 void cmd_more(char *argbuf) {
161 cprintf("%d %s\n", CIT_OK, config.c_moreprompt);
166 * the client is identifying itself to the server
168 void cmd_iden(char *argbuf)
170 CitContext *CCC = MyContext();
177 if (num_parms(argbuf)<4) {
178 cprintf("%d usage error\n", ERROR + ILLEGAL_VALUE);
182 dev_code = extract_int(argbuf,0);
183 cli_code = extract_int(argbuf,1);
184 rev_level = extract_int(argbuf,2);
185 extract_token(desc, argbuf, 3, '|', sizeof desc);
187 safestrncpy(from_host, config.c_fqdn, sizeof from_host);
188 from_host[sizeof from_host - 1] = 0;
189 if (num_parms(argbuf)>=5) extract_token(from_host, argbuf, 4, '|', sizeof from_host);
191 CCC->cs_clientdev = dev_code;
192 CCC->cs_clienttyp = cli_code;
193 CCC->cs_clientver = rev_level;
194 safestrncpy(CCC->cs_clientname, desc, sizeof CCC->cs_clientname);
195 CCC->cs_clientname[31] = 0;
197 /* For local sockets and public clients, trust the hostname supplied by the client */
198 if ( (CCC->is_local_socket) || (CtdlIsPublicClient()) ) {
199 safestrncpy(CCC->cs_host, from_host, sizeof CCC->cs_host);
200 CCC->cs_host[sizeof CCC->cs_host - 1] = 0;
204 syslog(LOG_NOTICE, "Client %d/%d/%01d.%02d (%s) from %s\n",
212 cprintf("%d Ok\n",CIT_OK);
216 * Terminate another running session
218 void cmd_term(char *cmdbuf)
223 session_num = extract_int(cmdbuf, 0);
225 terminated = CtdlTerminateOtherSession(session_num);
227 if (terminated < 0) {
228 cprintf("%d You can't kill your own session.\n", ERROR + ILLEGAL_VALUE);
232 if (terminated & TERM_FOUND) {
233 if (terminated == TERM_KILLED) {
234 cprintf("%d Session terminated.\n", CIT_OK);
237 cprintf("%d You are not allowed to do that.\n",
238 ERROR + HIGHER_ACCESS_REQUIRED);
242 cprintf("%d No such session.\n", ERROR + ILLEGAL_VALUE);
247 void cmd_time(char *argbuf)
253 localtime_r(&tv, &tmp);
255 /* timezone and daylight global variables are not portable. */
256 #ifdef HAVE_STRUCT_TM_TM_GMTOFF
257 cprintf("%d %ld|%ld|%d|%ld\n", CIT_OK, (long)tv, tmp.tm_gmtoff, tmp.tm_isdst, server_startup_time);
259 cprintf("%d %ld|%ld|%d|%ld\n", CIT_OK, (long)tv, timezone, tmp.tm_isdst, server_startup_time);
266 /*****************************************************************************/
267 /* MODULE INITIALIZATION STUFF */
268 /*****************************************************************************/
270 CTDL_MODULE_INIT(serv_session)
273 CtdlRegisterProtoHook(cmd_noop, "NOOP", "no operation");
274 CtdlRegisterProtoHook(cmd_qnop, "QNOP", "no operation with no response");
276 CtdlRegisterProtoHook(cmd_asyn, "ASYN", "enable asynchronous server responses");
277 CtdlRegisterProtoHook(cmd_info, "INFO", "fetch server capabilities and configuration");
278 CtdlRegisterProtoHook(cmd_echo, "ECHO", "echo text back to the client");
279 CtdlRegisterProtoHook(cmd_more, "MORE", "fetch the paginator prompt");
280 CtdlRegisterProtoHook(cmd_iden, "IDEN", "identify the client software and location");
281 CtdlRegisterProtoHook(cmd_term, "TERM", "terminate another running session");
283 CtdlRegisterProtoHook(cmd_time, "TIME", "fetch the date and time from the server");
285 /* return our id for the Log */
286 return "serv_session";