1 // Server functions which perform operations on user objects.
3 // Copyright (c) 1987-2024 by the citadel.org team
5 // This program is open source software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License, version 3.
9 #include <libcitadel.h>
10 #include "../../citserver.h"
11 #include "../../ctdl_module.h"
12 #include "../../config.h"
15 void cmd_noop(char *argbuf) {
16 cprintf("%d%cok\n", CIT_OK, CtdlCheckExpress(CC) );
20 void cmd_qnop(char *argbuf) {
21 /* do nothing, this command returns no response */
25 // Set or unset asynchronous protocol mode
26 void cmd_asyn(char *argbuf) {
29 new_state = extract_int(argbuf, 0);
30 if ((new_state == 0) || (new_state == 1)) {
31 CC->is_async = new_state;
33 cprintf("%d %d\n", CIT_OK, CC->is_async);
37 // cmd_info() - Identify this server and its capabilities to the client
38 void cmd_info(char *cmdbuf) {
39 cprintf("%d Server info:\n", LISTING_FOLLOWS);
40 cprintf("%d\n", CC->cs_pid);
41 cprintf("%s\n", CtdlGetConfigStr("c_nodename"));
42 cprintf("%s\n", CtdlGetConfigStr("c_humannode"));
43 cprintf("%s\n", CtdlGetConfigStr("c_fqdn"));
44 cprintf("%s\n", CITADEL);
45 cprintf("%d\n", REV_LEVEL);
46 cprintf("%s\n", CtdlGetConfigStr("c_site_location"));
47 cprintf("%s\n", CtdlGetConfigStr("c_sysadm"));
48 cprintf("%d\n", SERVER_TYPE);
49 cprintf("%s\n", CtdlGetConfigStr("c_moreprompt"));
50 cprintf("1\n"); // 1 = yes, this system supports floors
51 cprintf("1\n"); // 1 = we support the extended paging options
52 cprintf("\n"); // no longer used
53 cprintf("1\n"); // 1 = yes, this system supports the QNOP command
54 cprintf("1\n"); // 1 = yes, this server is LDAP-enabled
56 if ((CtdlGetConfigInt("c_auth_mode") == AUTHMODE_NATIVE) && (CtdlGetConfigInt("c_disable_newu") == 0)) {
57 cprintf("%d\n", CtdlGetConfigInt("c_disable_newu"));
60 cprintf("1\n"); // "create new user" does not work with non-native auth modes
63 cprintf("%s\n", CtdlGetConfigStr("c_default_cal_zone"));
65 cprintf("0\n"); // no longer used
66 cprintf("0\n"); // no longer used
67 cprintf("0\n"); // no longer used
68 cprintf("0\n"); // no longer used
69 cprintf("%d\n", CtdlGetConfigInt("c_enable_fulltext"));
70 cprintf("%s\n", BUILD_ID);
71 cprintf("0\n"); // no longer used (support for OpenID has ended)
72 cprintf("%d\n", CtdlGetConfigInt("c_guest_logins"));
78 void cmd_echo(char *etext) {
79 cprintf("%d %s\n", CIT_OK, etext);
83 // get the paginator prompt
84 void cmd_more(char *argbuf) {
85 cprintf("%d %s\n", CIT_OK, CtdlGetConfigStr("c_moreprompt"));
89 // the client is identifying itself to the server
90 void cmd_iden(char *argbuf) {
97 if (num_parms(argbuf)<4) {
98 cprintf("%d usage error\n", ERROR + ILLEGAL_VALUE);
102 extract_token(desc, argbuf, 3, '|', sizeof desc);
104 safestrncpy(from_host, CtdlGetConfigStr("c_fqdn"), sizeof from_host);
105 from_host[sizeof from_host - 1] = 0;
106 if (num_parms(argbuf)>=5) extract_token(from_host, argbuf, 4, '|', sizeof from_host);
108 safestrncpy(CC->cs_clientname, desc, sizeof CC->cs_clientname);
109 CC->cs_clientname[31] = 0;
111 // For local sockets, allow the client to supply the user's origin address
112 if ((CC->is_local_client) || (!IsEmptyStr(CC->cs_addr) && (!strcmp(CC->cs_addr, "127.0.0.1")) || (!strcmp(CC->cs_addr, "::1")))) {
113 safestrncpy(CC->cs_host, from_host, sizeof CC->cs_host);
114 CC->cs_host[sizeof CC->cs_host - 1] = 0;
118 syslog(LOG_NOTICE, "session: client %d/%d/%01d.%02d (%s) from %s",
126 cprintf("%d Ok\n",CIT_OK);
130 // Terminate another running session
131 void cmd_term(char *cmdbuf) {
132 int session_num = extract_int(cmdbuf, 0);
133 int terminated = CtdlTerminateOtherSession(session_num);
135 if (terminated < 0) {
136 cprintf("%d You can't kill your own session.\n", ERROR + ILLEGAL_VALUE);
140 if (terminated & TERM_FOUND) {
141 if (terminated == TERM_KILLED) {
142 cprintf("%d Session terminated.\n", CIT_OK);
145 cprintf("%d You are not allowed to do that.\n", ERROR + HIGHER_ACCESS_REQUIRED);
149 cprintf("%d No such session.\n", ERROR + ILLEGAL_VALUE);
154 void cmd_time(char *argbuf) {
159 localtime_r(&tv, &tmp);
161 // timezone and daylight global variables are not portable.
162 #ifdef HAVE_STRUCT_TM_TM_GMTOFF
163 cprintf("%d %ld|%ld|%d|%ld\n", CIT_OK, (long)tv, tmp.tm_gmtoff, tmp.tm_isdst, server_startup_time);
165 cprintf("%d %ld|%ld|%d|%ld\n", CIT_OK, (long)tv, timezone, tmp.tm_isdst, server_startup_time);
170 // Initialization function, called from modules_init.c
171 char *ctdl_module_init_serv_session(void) {
173 CtdlRegisterProtoHook(cmd_noop, "NOOP", "no operation");
174 CtdlRegisterProtoHook(cmd_qnop, "QNOP", "no operation with no response");
175 CtdlRegisterProtoHook(cmd_asyn, "ASYN", "enable asynchronous server responses");
176 CtdlRegisterProtoHook(cmd_info, "INFO", "fetch server capabilities and configuration");
177 CtdlRegisterProtoHook(cmd_echo, "ECHO", "echo text back to the client");
178 CtdlRegisterProtoHook(cmd_more, "MORE", "fetch the paginator prompt");
179 CtdlRegisterProtoHook(cmd_iden, "IDEN", "identify the client software and location");
180 CtdlRegisterProtoHook(cmd_term, "TERM", "terminate another running session");
181 CtdlRegisterProtoHook(cmd_time, "TIME", "fetch the date and time from the server");
183 // return our id for the log
184 return "serv_session";