]> code.citadel.org Git - citadel.git/blob - citadel/serv_bio.c
* Final bit of patching for the IPGM exploit. Random number generator is
[citadel.git] / citadel / serv_bio.c
1 /*
2  * $Id$
3  *
4  * This module implementsserver commands related to the display and
5  * manipulation of user "bio" files.
6  *
7  */
8
9 #include "sysdep.h"
10 #include <stdlib.h>
11 #include <unistd.h>
12 #include <stdio.h>
13 #include <fcntl.h>
14 #include <signal.h>
15 #include <pwd.h>
16 #include <errno.h>
17 #include <sys/types.h>
18
19 #if TIME_WITH_SYS_TIME
20 # include <sys/time.h>
21 # include <time.h>
22 #else
23 # if HAVE_SYS_TIME_H
24 #  include <sys/time.h>
25 # else
26 #  include <time.h>
27 # endif
28 #endif
29
30 #include <sys/wait.h>
31 #include <string.h>
32 #include <limits.h>
33 #include "citadel.h"
34 #include "server.h"
35 #include "sysdep_decls.h"
36 #include "citserver.h"
37 #include "support.h"
38 #include "config.h"
39 #include "control.h"
40 #include "serv_extensions.h"
41 #include "room_ops.h"
42 #include "user_ops.h"
43 #include "policy.h"
44 #include "database.h"
45 #include "msgbase.h"
46 #include "tools.h"
47
48
49
50
51 /*
52  * enter user bio
53  */
54 void cmd_ebio(char *cmdbuf) {
55         char buf[SIZ];
56         FILE *fp;
57
58         if (!(CC->logged_in)) {
59                 cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
60                 return;
61         }
62
63         snprintf(buf, sizeof buf, "./bio/%ld",CC->user.usernum);
64         fp = fopen(buf,"w");
65         if (fp == NULL) {
66                 cprintf("%d Cannot create file\n",ERROR);
67                 return;
68         }
69         cprintf("%d  \n",SEND_LISTING);
70         while(client_gets(buf), strcmp(buf,"000")) {
71                 if (ftell(fp) < config.c_maxmsglen) {
72                         fprintf(fp,"%s\n",buf);
73                 }
74         }
75         fclose(fp);
76 }
77
78 /*
79  * read user bio
80  */
81 void cmd_rbio(char *cmdbuf)
82 {
83         struct ctdluser ruser;
84         char buf[SIZ];
85         FILE *fp;
86
87         extract(buf,cmdbuf,0);
88         if (getuser(&ruser,buf)!=0) {
89                 cprintf("%d No such user.\n",ERROR+NO_SUCH_USER);
90                 return;
91         }
92         snprintf(buf, sizeof buf, "./bio/%ld",ruser.usernum);
93         
94         cprintf("%d OK|%s|%ld|%d|%ld|%ld|%ld\n", LISTING_FOLLOWS,
95                 ruser.fullname, ruser.usernum, ruser.axlevel,
96                 (long)ruser.lastcall, ruser.timescalled, ruser.posted);
97         fp = fopen(buf,"r");
98         if (fp == NULL)
99                 cprintf("%s has no bio on file.\n", ruser.fullname);
100         else {
101                 while (fgets(buf,256,fp)!=NULL) cprintf("%s",buf);
102                 fclose(fp);
103         }
104         cprintf("000\n");
105 }
106
107 /*
108  * list of users who have entered bios
109  */
110 void cmd_lbio(char *cmdbuf) {
111         char buf[SIZ];
112         FILE *ls;
113         struct ctdluser usbuf;
114
115         ls=popen("cd ./bio; ls","r");
116         if (ls==NULL) {
117                 cprintf("%d Cannot open listing.\n",ERROR+FILE_NOT_FOUND);
118                 return;
119         }
120
121         cprintf("%d\n",LISTING_FOLLOWS);
122         while (fgets(buf,sizeof buf,ls)!=NULL)
123                 if (getuserbynumber(&usbuf,atol(buf))==0)
124                         cprintf("%s\n",usbuf.fullname);
125         pclose(ls);
126         cprintf("000\n");
127 }
128
129
130
131
132 char *serv_bio_init(void)
133 {
134         CtdlRegisterProtoHook(cmd_ebio, "EBIO", "Enter your bio");
135         CtdlRegisterProtoHook(cmd_rbio, "RBIO", "Read a user's bio");
136         CtdlRegisterProtoHook(cmd_lbio, "LBIO", "List users with bios");
137         return "$Id$";
138 }
139
140