|
|
1.1 root 1: /* makeuser.c */
2:
3: /* Program to add a user to a Synchronet user database */
4:
5: /* $Id: makeuser.c,v 1.6 2006/04/21 04:24:53 deuce Exp $ */
6:
7: /****************************************************************************
8: * @format.tab-size 4 (Plain Text/Source Code File Header) *
9: * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
10: * *
11: * Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html *
12: * *
13: * This program is free software; you can redistribute it and/or *
14: * modify it under the terms of the GNU General Public License *
15: * as published by the Free Software Foundation; either version 2 *
16: * of the License, or (at your option) any later version. *
17: * See the GNU General Public License for more details: gpl.txt or *
18: * http://www.fsf.org/copyleft/gpl.html *
19: * *
20: * Anonymous FTP access to the most recent released source is available at *
21: * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
22: * *
23: * Anonymous CVS access to the development source and modification history *
24: * is available at cvs.synchro.net:/cvsroot/sbbs, example: *
25: * cvs -d :pserver:[email protected]:/cvsroot/sbbs login *
26: * (just hit return, no password is necessary) *
27: * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src *
28: * *
29: * For Synchronet coding style and modification guidelines, see *
30: * http://www.synchro.net/source.html *
31: * *
32: * You are encouraged to submit any modifications (preferably in Unix diff *
33: * format) via e-mail to [email protected] *
34: * *
35: * Note: If this box doesn't appear square, then you need to fix your tabs. *
36: ****************************************************************************/
37:
38: #include "sbbs.h"
39:
40: scfg_t scfg;
41:
42: /****************************************************************************/
43: /* This is needed by load_cfg.c */
44: /****************************************************************************/
45: int lprintf(int level, char *fmat, ...)
46: {
47: va_list argptr;
48: char sbuf[512];
49: int chcount;
50:
51: va_start(argptr,fmat);
52: chcount=vsprintf(sbuf,fmat,argptr);
53: va_end(argptr);
54: truncsp(sbuf);
55: printf("%s\n",sbuf);
56: return(chcount);
57: }
58:
59: char *usage="\nusage: makeuser [ctrl_dir] name [-param value] [...]\n"
60: "\nparams:\n"
61: "\t-P\tPassword\n"
62: "\t-R\tReal name\n"
63: "\t-H\tChat handle\n"
64: "\t-G\tGender (M or F)\n"
65: "\t-B\tBirth date (in MM/DD/YY or DD/MM/YY format)\n"
66: "\t-T\tTelephone number\n"
67: "\t-N\tNetmail (Internet e-mail) address\n"
68: "\t-A\tStreet address\n"
69: "\t-L\tLocation (city, state)\n"
70: "\t-Z\tZip/Postal code\n"
71: "\t-S\tSecurity level\n"
72: "\t-F#\tFlag set #\n"
73: "\t-FE\tExemption flags\n"
74: "\t-FR\tRestriction flags\n"
75: "\t-E\tExpiration days\n"
76: "\t-C\tComment\n"
77: "\nNOTE: multi-word user name and param values must be enclosed in \"quotes\"\n"
78: ;
79:
80: /*********************/
81: /* Entry point (duh) */
82: /*********************/
83: int main(int argc, char **argv)
84: {
85: char* p;
86: char error[512];
87: char revision[16];
88: int i;
89: int first_arg=1;
90: time_t now;
91: user_t user;
92:
93: sscanf("$Revision: 1.6 $", "%*s %s", revision);
94:
95: fprintf(stderr,"\nMAKEUSER v%s-%s - Adds User to Synchronet User Database\n"
96: ,revision
97: ,PLATFORM_DESC
98: );
99:
100: if(argc<2) {
101: printf("%s",usage);
102: return(1);
103: }
104:
105: if(strcspn(argv[first_arg],"/\\")!=strlen(argv[first_arg]))
106: p=argv[first_arg++];
107: else
108: p=getenv("SBBSCTRL");
109: if(p==NULL) {
110: printf("\nSBBSCTRL environment variable not set.\n");
111: printf("\nExample: SET SBBSCTRL=/sbbs/ctrl\n");
112: exit(1);
113: }
114:
115: memset(&scfg,0,sizeof(scfg));
116: scfg.size=sizeof(scfg);
117: SAFECOPY(scfg.ctrl_dir,p);
118:
119: if(chdir(scfg.ctrl_dir)!=0)
120: fprintf(stderr,"!ERROR changing directory to: %s", scfg.ctrl_dir);
121:
122: printf("\nLoading configuration files from %s\n",scfg.ctrl_dir);
123: if(!load_cfg(&scfg,NULL,TRUE,error)) {
124: fprintf(stderr,"!ERROR loading configuration files: %s\n",error);
125: exit(1);
126: }
127:
128: if(!(scfg.sys_misc&SM_LOCAL_TZ))
129: putenv("TZ=UTC0");
130:
131: now=time(NULL);
132:
133: memset(&user,0,sizeof(user));
134:
135: /****************/
136: /* Set Defaults */
137: /****************/
138:
139: /* security */
140: user.level=scfg.new_level;
141: user.flags1=scfg.new_flags1;
142: user.flags2=scfg.new_flags2;
143: user.flags3=scfg.new_flags3;
144: user.flags4=scfg.new_flags4;
145: user.rest=scfg.new_rest;
146: user.exempt=scfg.new_exempt;
147:
148: user.cdt=scfg.new_cdt;
149: user.min=scfg.new_min;
150: user.freecdt=scfg.level_freecdtperday[user.level];
151:
152: if(scfg.total_fcomps)
153: strcpy(user.tmpext,scfg.fcomp[0]->ext);
154: else
155: strcpy(user.tmpext,"ZIP");
156: for(i=0;i<scfg.total_xedits;i++)
157: if(!stricmp(scfg.xedit[i]->code,scfg.new_xedit))
158: break;
159: if(i<scfg.total_xedits)
160: user.xedit=i+1;
161:
162: user.shell=scfg.new_shell;
163: user.misc=(scfg.new_misc&~(DELETED|INACTIVE|QUIET|NETMAIL));
164: user.misc|=AUTOTERM; /* No way to frob the default value... */
165: user.qwk=QWK_DEFAULT;
166: user.firston=now;
167: user.laston=now; /* must set this or user may be purged prematurely */
168: user.pwmod=now;
169: user.sex=' ';
170: user.prot=scfg.new_prot;
171:
172: if(scfg.new_expire)
173: user.expire=now+((long)scfg.new_expire*24L*60L*60L);
174:
175: for(i=first_arg;i<argc;i++) {
176: if(argv[i][0]=='-') {
177: if(argv[i+1]==NULL) {
178: printf("%s",usage);
179: return(1);
180: }
181: switch(toupper(argv[i++][1])) {
182: case 'A':
183: SAFECOPY(user.address,argv[i]);
184: break;
185: case 'B':
186: SAFECOPY(user.birth,argv[i]);
187: break;
188: case 'L':
189: SAFECOPY(user.location,argv[i]);
190: break;
191: case 'C':
192: SAFECOPY(user.comment,argv[i]);
193: break;
194: case 'E':
195: user.expire=now+((long)atoi(argv[i])*24L*60L*60L);
196: break;
197: case 'F':
198: switch(toupper(argv[i-1][2])) {
199: case '1':
200: user.flags1=aftol(argv[i]);
201: break;
202: case '2':
203: user.flags2=aftol(argv[i]);
204: break;
205: case '3':
206: user.flags3=aftol(argv[i]);
207: break;
208: case '4':
209: user.flags4=aftol(argv[i]);
210: break;
211: case 'E':
212: user.exempt=aftol(argv[i]);
213: break;
214: case 'R':
215: user.rest=aftol(argv[i]);
216: break;
217: default:
218: printf("%s",usage);
219: return(1);
220: }
221: break;
222: case 'G':
223: user.sex=toupper(argv[i][0]);
224: break;
225: case 'H':
226: SAFECOPY(user.handle,argv[i]);
227: break;
228: case 'N':
229: SAFECOPY(user.netmail,argv[i]);
230: break;
231: case 'P':
232: SAFECOPY(user.pass,argv[i]);
233: strupr(user.pass);
234: break;
235: case 'R':
236: SAFECOPY(user.name,argv[i]);
237: break;
238: case 'S':
239: user.level=atoi(argv[i]);
240: break;
241: case 'T':
242: SAFECOPY(user.phone,argv[i]);
243: break;
244: case 'Z':
245: SAFECOPY(user.zipcode,argv[i]);
246: break;
247: default:
248: printf("%s",usage);
249: return(1);
250: }
251: }
252: else
253: SAFECOPY(user.alias,argv[i]);
254: }
255:
256: if(user.alias[0]==0) {
257: printf("%s",usage);
258: return(1);
259: }
260:
261: if((i=matchuser(&scfg,user.alias,FALSE))!=0) {
262: printf("!User (%s #%d) already exists\n",user.alias,i);
263: return(2);
264: }
265:
266: if(user.handle[0]==0)
267: SAFECOPY(user.handle,user.alias);
268: if(user.name[0]==0)
269: SAFECOPY(user.name,user.alias);
270:
271: if((i=newuserdat(&scfg, &user))!=0) {
272: fprintf(stderr,"!ERROR %d adding new user record\n",i);
273: return(i);
274: }
275:
276: printf("User record #%d (%s) created successfully.\n",user.number,user.alias);
277:
278: return(0);
279: }
280:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.