|
|
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.4 2003/10/24 22:10:00 rswindell 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.4 $", "%*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.qwk=QWK_DEFAULT;
165: user.firston=now;
166: user.laston=now; /* must set this or user may be purged prematurely */
167: user.pwmod=now;
168: user.sex=' ';
169: user.prot=scfg.new_prot;
170:
171: if(scfg.new_expire)
172: user.expire=now+((long)scfg.new_expire*24L*60L*60L);
173:
174: for(i=first_arg;i<argc;i++) {
175: if(argv[i][0]=='-') {
176: switch(toupper(argv[i++][1])) {
177: case 'A':
178: SAFECOPY(user.address,argv[i]);
179: break;
180: case 'B':
181: SAFECOPY(user.birth,argv[i]);
182: break;
183: case 'L':
184: SAFECOPY(user.location,argv[i]);
185: break;
186: case 'C':
187: SAFECOPY(user.comment,argv[i]);
188: break;
189: case 'E':
190: user.expire=now+((long)atoi(argv[i])*24L*60L*60L);
191: break;
192: case 'F':
193: switch(toupper(argv[i-1][2])) {
194: case '1':
195: user.flags1=aftol(argv[i]);
196: break;
197: case '2':
198: user.flags2=aftol(argv[i]);
199: break;
200: case '3':
201: user.flags3=aftol(argv[i]);
202: break;
203: case '4':
204: user.flags4=aftol(argv[i]);
205: break;
206: case 'E':
207: user.exempt=aftol(argv[i]);
208: break;
209: case 'R':
210: user.rest=aftol(argv[i]);
211: break;
212: default:
213: printf("%s",usage);
214: return(1);
215: }
216: break;
217: case 'G':
218: user.sex=toupper(argv[i][0]);
219: break;
220: case 'H':
221: SAFECOPY(user.handle,argv[i]);
222: break;
223: case 'N':
224: SAFECOPY(user.netmail,argv[i]);
225: break;
226: case 'P':
227: SAFECOPY(user.pass,argv[i]);
228: strupr(user.pass);
229: break;
230: case 'R':
231: SAFECOPY(user.name,argv[i]);
232: break;
233: case 'S':
234: user.level=atoi(argv[i]);
235: break;
236: case 'T':
237: SAFECOPY(user.phone,argv[i]);
238: break;
239: case 'Z':
240: SAFECOPY(user.zipcode,argv[i]);
241: break;
242: default:
243: printf("%s",usage);
244: return(1);
245: }
246: }
247: else
248: SAFECOPY(user.alias,argv[i]);
249: }
250:
251: if(user.alias[0]==0) {
252: printf("%s",usage);
253: return(1);
254: }
255:
256: if((i=matchuser(&scfg,user.alias,FALSE))!=0) {
257: printf("!User (%s #%d) already exists\n",user.alias,i);
258: return(2);
259: }
260:
261: if(user.handle[0]==0)
262: SAFECOPY(user.handle,user.alias);
263: if(user.name[0]==0)
264: SAFECOPY(user.name,user.alias);
265:
266: if((i=newuserdat(&scfg, &user))!=0) {
267: fprintf(stderr,"!ERROR %d adding new user record\n",i);
268: return(i);
269: }
270:
271: printf("User record #%d (%s) created successfully.\n",user.number,user.alias);
272:
273: return(0);
274: }
275:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.