|
|
1.1 root 1: /* makeuser.c */
2:
3: /* Program to add a user to a Synchronet user database */
4:
1.1.1.2 ! root 5: /* $Id: makeuser.c,v 1.8 2008/06/04 04:38:47 deuce Exp $ */
1.1 root 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: /****************************************************************************/
1.1.1.2 ! root 45: int lprintf(int level, const char *fmat, ...)
1.1 root 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:
1.1.1.2 ! root 93: sscanf("$Revision: 1.8 $", "%*s %s", revision);
1.1 root 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: now=time(NULL);
129:
130: memset(&user,0,sizeof(user));
131:
132: /****************/
133: /* Set Defaults */
134: /****************/
135:
136: /* security */
137: user.level=scfg.new_level;
138: user.flags1=scfg.new_flags1;
139: user.flags2=scfg.new_flags2;
140: user.flags3=scfg.new_flags3;
141: user.flags4=scfg.new_flags4;
142: user.rest=scfg.new_rest;
143: user.exempt=scfg.new_exempt;
144:
145: user.cdt=scfg.new_cdt;
146: user.min=scfg.new_min;
147: user.freecdt=scfg.level_freecdtperday[user.level];
148:
149: if(scfg.total_fcomps)
150: strcpy(user.tmpext,scfg.fcomp[0]->ext);
151: else
152: strcpy(user.tmpext,"ZIP");
153: for(i=0;i<scfg.total_xedits;i++)
154: if(!stricmp(scfg.xedit[i]->code,scfg.new_xedit))
155: break;
156: if(i<scfg.total_xedits)
157: user.xedit=i+1;
158:
159: user.shell=scfg.new_shell;
160: user.misc=(scfg.new_misc&~(DELETED|INACTIVE|QUIET|NETMAIL));
161: user.misc|=AUTOTERM; /* No way to frob the default value... */
162: user.qwk=QWK_DEFAULT;
163: user.firston=now;
164: user.laston=now; /* must set this or user may be purged prematurely */
165: user.pwmod=now;
166: user.sex=' ';
167: user.prot=scfg.new_prot;
168:
169: if(scfg.new_expire)
170: user.expire=now+((long)scfg.new_expire*24L*60L*60L);
171:
172: for(i=first_arg;i<argc;i++) {
173: if(argv[i][0]=='-') {
174: if(argv[i+1]==NULL) {
175: printf("%s",usage);
176: return(1);
177: }
178: switch(toupper(argv[i++][1])) {
179: case 'A':
180: SAFECOPY(user.address,argv[i]);
181: break;
182: case 'B':
183: SAFECOPY(user.birth,argv[i]);
184: break;
185: case 'L':
186: SAFECOPY(user.location,argv[i]);
187: break;
188: case 'C':
189: SAFECOPY(user.comment,argv[i]);
190: break;
191: case 'E':
192: user.expire=now+((long)atoi(argv[i])*24L*60L*60L);
193: break;
194: case 'F':
195: switch(toupper(argv[i-1][2])) {
196: case '1':
197: user.flags1=aftol(argv[i]);
198: break;
199: case '2':
200: user.flags2=aftol(argv[i]);
201: break;
202: case '3':
203: user.flags3=aftol(argv[i]);
204: break;
205: case '4':
206: user.flags4=aftol(argv[i]);
207: break;
208: case 'E':
209: user.exempt=aftol(argv[i]);
210: break;
211: case 'R':
212: user.rest=aftol(argv[i]);
213: break;
214: default:
215: printf("%s",usage);
216: return(1);
217: }
218: break;
219: case 'G':
220: user.sex=toupper(argv[i][0]);
221: break;
222: case 'H':
223: SAFECOPY(user.handle,argv[i]);
224: break;
225: case 'N':
226: SAFECOPY(user.netmail,argv[i]);
227: break;
228: case 'P':
229: SAFECOPY(user.pass,argv[i]);
230: strupr(user.pass);
231: break;
232: case 'R':
233: SAFECOPY(user.name,argv[i]);
234: break;
235: case 'S':
236: user.level=atoi(argv[i]);
237: break;
238: case 'T':
239: SAFECOPY(user.phone,argv[i]);
240: break;
241: case 'Z':
242: SAFECOPY(user.zipcode,argv[i]);
243: break;
244: default:
245: printf("%s",usage);
246: return(1);
247: }
248: }
249: else
250: SAFECOPY(user.alias,argv[i]);
251: }
252:
253: if(user.alias[0]==0) {
254: printf("%s",usage);
255: return(1);
256: }
257:
258: if((i=matchuser(&scfg,user.alias,FALSE))!=0) {
259: printf("!User (%s #%d) already exists\n",user.alias,i);
260: return(2);
261: }
262:
263: if(user.handle[0]==0)
264: SAFECOPY(user.handle,user.alias);
265: if(user.name[0]==0)
266: SAFECOPY(user.name,user.alias);
267:
268: if((i=newuserdat(&scfg, &user))!=0) {
269: fprintf(stderr,"!ERROR %d adding new user record\n",i);
270: return(i);
271: }
272:
273: printf("User record #%d (%s) created successfully.\n",user.number,user.alias);
274:
275: return(0);
276: }
277:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.