citadel
About: Citadel is an advanced messaging and collaboration system for groupware and BBS applications (preferred OS: Linux).
  Fossies Dox: citadel.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

Loading...
Searching...
No Matches
serv_session.c
Go to the documentation of this file.
1/*
2 * Server functions which perform operations on user objects.
3 *
4 * Copyright (c) 1987-2022 by the citadel.org team
5 *
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.
8 *
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.
13 */
14
15#include <stdio.h>
16#include <libcitadel.h>
17#include "../../citserver.h"
18#include "../../ctdl_module.h"
19#include "../../config.h"
20
21
22void cmd_noop(char *argbuf)
23{
24 cprintf("%d%cok\n", CIT_OK, CtdlCheckExpress() );
25}
26
27
28void cmd_qnop(char *argbuf)
29{
30 /* do nothing, this command returns no response */
31}
32
33
34/*
35 * Set or unset asynchronous protocol mode
36 */
37void cmd_asyn(char *argbuf)
38{
39 int new_state;
40
41 new_state = extract_int(argbuf, 0);
42 if ((new_state == 0) || (new_state == 1)) {
43 CC->is_async = new_state;
44 }
45 cprintf("%d %d\n", CIT_OK, CC->is_async);
46}
47
48
49/*
50 * cmd_info() - Identify this server and its capabilities to the client
51 */
52void cmd_info(char *cmdbuf) {
53 cprintf("%d Server info:\n", LISTING_FOLLOWS);
54 cprintf("%d\n", CC->cs_pid);
55 cprintf("%s\n", CtdlGetConfigStr("c_nodename"));
56 cprintf("%s\n", CtdlGetConfigStr("c_humannode"));
57 cprintf("%s\n", CtdlGetConfigStr("c_fqdn"));
58 cprintf("%s\n", CITADEL);
59 cprintf("%d\n", REV_LEVEL);
60 cprintf("%s\n", CtdlGetConfigStr("c_site_location"));
61 cprintf("%s\n", CtdlGetConfigStr("c_sysadm"));
62 cprintf("%d\n", SERVER_TYPE);
63 cprintf("%s\n", CtdlGetConfigStr("c_moreprompt"));
64 cprintf("1\n"); /* 1 = yes, this system supports floors */
65 cprintf("1\n"); /* 1 = we support the extended paging options */
66 cprintf("\n"); /* no longer used */
67 cprintf("1\n"); /* 1 = yes, this system supports the QNOP command */
68 cprintf("1\n"); /* 1 = yes, this server is LDAP-enabled */
69
70 if ((CtdlGetConfigInt("c_auth_mode") == AUTHMODE_NATIVE) && (CtdlGetConfigInt("c_disable_newu") == 0))
71 {
72 cprintf("%d\n", CtdlGetConfigInt("c_disable_newu"));
73 }
74 else {
75 cprintf("1\n"); /* "create new user" does not work with non-native auth modes */
76 }
77
78 cprintf("%s\n", CtdlGetConfigStr("c_default_cal_zone"));
79
80 cprintf("0\n"); /* no longer used */
81 cprintf("0\n"); /* no longer used */
82 cprintf("0\n"); /* no longer used */
83 cprintf("0\n"); /* no longer used */
84
85 cprintf("%d\n", CtdlGetConfigInt("c_enable_fulltext"));
86 cprintf("%s\n", BUILD_ID);
87
88 if (CtdlGetConfigInt("c_auth_mode") == AUTHMODE_NATIVE) {
89 cprintf("%d\n", openid_level_supported); /* OpenID is enabled when using native auth */
90 }
91 else {
92 cprintf("0\n"); /* OpenID is disabled when using non-native auth */
93 }
94
95 cprintf("%d\n", CtdlGetConfigInt("c_guest_logins"));
96 cprintf("000\n");
97}
98
99
100/*
101 * echo
102 */
103void cmd_echo(char *etext)
104{
105 cprintf("%d %s\n", CIT_OK, etext);
106}
107
108
109/*
110 * get the paginator prompt
111 */
112void cmd_more(char *argbuf) {
113 cprintf("%d %s\n", CIT_OK, CtdlGetConfigStr("c_moreprompt"));
114}
115
116
117/*
118 * the client is identifying itself to the server
119 */
120void cmd_iden(char *argbuf)
121{
122 int dev_code;
123 int cli_code;
124 int rev_level;
125 char desc[128];
126 char from_host[128];
127
128 if (num_parms(argbuf)<4) {
129 cprintf("%d usage error\n", ERROR + ILLEGAL_VALUE);
130 return;
131 }
132
133 dev_code = extract_int(argbuf,0);
134 cli_code = extract_int(argbuf,1);
135 rev_level = extract_int(argbuf,2);
136 extract_token(desc, argbuf, 3, '|', sizeof desc);
137
138 safestrncpy(from_host, CtdlGetConfigStr("c_fqdn"), sizeof from_host);
139 from_host[sizeof from_host - 1] = 0;
140 if (num_parms(argbuf)>=5) extract_token(from_host, argbuf, 4, '|', sizeof from_host);
141
142 CC->cs_clientdev = dev_code;
143 CC->cs_clienttyp = cli_code;
144 CC->cs_clientver = rev_level;
145 safestrncpy(CC->cs_clientname, desc, sizeof CC->cs_clientname);
146 CC->cs_clientname[31] = 0;
147
148 /* For local sockets, allow the client to supply the user's origin address */
149 if ((CC->is_local_client) || (!IsEmptyStr(CC->cs_addr) && (!strcmp(CC->cs_addr, "127.0.0.1")) || (!strcmp(CC->cs_addr, "::1")))) {
150 safestrncpy(CC->cs_host, from_host, sizeof CC->cs_host);
151 CC->cs_host[sizeof CC->cs_host - 1] = 0;
152 CC->cs_addr[0] = 0;
153 }
154
155 syslog(LOG_NOTICE, "session: client %d/%d/%01d.%02d (%s) from %s",
156 dev_code,
157 cli_code,
158 (rev_level / 100),
159 (rev_level % 100),
160 desc,
161 CC->cs_host
162 );
163 cprintf("%d Ok\n",CIT_OK);
164}
165
166
167/*
168 * Terminate another running session
169 */
170void cmd_term(char *cmdbuf)
171{
172 int session_num = extract_int(cmdbuf, 0);
173 int terminated = CtdlTerminateOtherSession(session_num);
174
175 if (terminated < 0) {
176 cprintf("%d You can't kill your own session.\n", ERROR + ILLEGAL_VALUE);
177 return;
178 }
179
180 if (terminated & TERM_FOUND) {
181 if (terminated == TERM_KILLED) {
182 cprintf("%d Session terminated.\n", CIT_OK);
183 }
184 else {
185 cprintf("%d You are not allowed to do that.\n", ERROR + HIGHER_ACCESS_REQUIRED);
186 }
187 }
188 else {
189 cprintf("%d No such session.\n", ERROR + ILLEGAL_VALUE);
190 }
191}
192
193
194void cmd_time(char *argbuf)
195{
196 time_t tv;
197 struct tm tmp;
198
199 tv = time(NULL);
200 localtime_r(&tv, &tmp);
201
202 /* timezone and daylight global variables are not portable. */
203#ifdef HAVE_STRUCT_TM_TM_GMTOFF
204 cprintf("%d %ld|%ld|%d|%ld\n", CIT_OK, (long)tv, tmp.tm_gmtoff, tmp.tm_isdst, server_startup_time);
205#else
206 cprintf("%d %ld|%ld|%d|%ld\n", CIT_OK, (long)tv, timezone, tmp.tm_isdst, server_startup_time);
207#endif
208}
209
210
211// Initialization function, called from modules_init.c
213 if (!threading) {
214 CtdlRegisterProtoHook(cmd_noop, "NOOP", "no operation");
215 CtdlRegisterProtoHook(cmd_qnop, "QNOP", "no operation with no response");
216 CtdlRegisterProtoHook(cmd_asyn, "ASYN", "enable asynchronous server responses");
217 CtdlRegisterProtoHook(cmd_info, "INFO", "fetch server capabilities and configuration");
218 CtdlRegisterProtoHook(cmd_echo, "ECHO", "echo text back to the client");
219 CtdlRegisterProtoHook(cmd_more, "MORE", "fetch the paginator prompt");
220 CtdlRegisterProtoHook(cmd_iden, "IDEN", "identify the client software and location");
221 CtdlRegisterProtoHook(cmd_term, "TERM", "terminate another running session");
222 CtdlRegisterProtoHook(cmd_time, "TIME", "fetch the date and time from the server");
223 }
224 /* return our id for the Log */
225 return "serv_session";
226}
#define CITADEL
Definition: citadel.h:37
#define REV_LEVEL
Definition: citadel.h:28
#define AUTHMODE_NATIVE
Definition: citadel.h:147
#define SERVER_TYPE
Definition: citadel.h:32
char CtdlCheckExpress(void)
Definition: citserver.c:170
time_t server_startup_time
Definition: citserver.c:26
int openid_level_supported
Definition: citserver.c:28
char * CtdlGetConfigStr(char *key)
Definition: config.c:363
int CtdlGetConfigInt(char *key)
Definition: config.c:390
int CtdlTerminateOtherSession(int session_num)
Definition: context.c:75
#define TERM_FOUND
Definition: context.h:167
#define CC
Definition: context.h:140
#define TERM_KILLED
Definition: context.h:169
int threading
Definition: modules_init.c:24
void CtdlRegisterProtoHook(void(*handler)(char *), char *cmd, char *desc)
#define CIT_OK
Definition: ipcdef.h:6
#define ILLEGAL_VALUE
Definition: ipcdef.h:16
#define LISTING_FOLLOWS
Definition: ipcdef.h:5
#define HIGHER_ACCESS_REQUIRED
Definition: ipcdef.h:23
#define ERROR
Definition: ipcdef.h:9
long timezone
void cmd_info(char *cmdbuf)
Definition: serv_session.c:52
char * ctdl_module_init_serv_session(void)
Definition: serv_session.c:212
void cmd_term(char *cmdbuf)
Definition: serv_session.c:170
void cmd_more(char *argbuf)
Definition: serv_session.c:112
void cmd_qnop(char *argbuf)
Definition: serv_session.c:28
void cmd_asyn(char *argbuf)
Definition: serv_session.c:37
void cmd_time(char *argbuf)
Definition: serv_session.c:194
void cmd_iden(char *argbuf)
Definition: serv_session.c:120
void cmd_echo(char *etext)
Definition: serv_session.c:103
void cmd_noop(char *argbuf)
Definition: serv_session.c:22
void cprintf(const char *format,...)
Definition: sysdep.c:369