-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathaddacct.c
132 lines (105 loc) · 3.09 KB
/
addacct.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
Eagles Bulletin Board System
Copyright (C) 1995, Ray Rocker, [email protected]
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "server.h"
extern USERDATA user_params;
extern char *optarg;
usage(prog)
char *prog;
{
fprintf(stderr,
"Usage: %s -i userid -p passwd [-u username] [-t termtype]\n", prog);
fprintf(stderr,
" [-e email] [-r realname] [-a address] [-d bbs-dir]\n");
}
main(argc, argv)
int argc;
char *argv[];
{
char *bbshome = NULL;
int iflg, pflg, uflg;
int c;
ACCOUNT acct;
int rc;
memset(&acct, 0, sizeof(acct));
iflg = pflg = uflg = 0;
while ((c = getopt(argc, argv, "a:d:e:i:p:r:t:u:?")) != -1)
{
switch (c)
{
case 'a':
strncpy(acct.address, optarg, sizeof acct.address-1);
break;
case 'd':
bbshome = optarg;
break;
case 'e':
strncpy(acct.email, optarg, sizeof acct.email-1);
break;
case 'i':
iflg++;
strncpy(acct.userid, optarg, sizeof acct.userid-1);
break;
case 'p':
pflg++;
strncpy(acct.passwd, optarg, sizeof acct.passwd-1);
break;
case 'r':
strncpy(acct.realname, optarg, sizeof acct.realname-1);
break;
case 't':
strncpy(acct.terminal, optarg, sizeof acct.terminal-1);
break;
case 'u':
uflg++;
strncpy(acct.username, optarg, sizeof acct.username-1);
break;
case '?':
usage(argv[0]);
return 2;
}
}
if (!iflg || !pflg) {
fprintf(stderr, "%s: userid and passwd args must be given\n", argv[0]);
return 1;
}
if (home_bbs(bbshome) == -1) {
fprintf(stderr, "%s: Cannot chdir to %s\n", argv[0], bbshome);
return 1;
}
if (local_bbs_initialize(NULL) != S_OK) {
fprintf(stderr, "%s: local_bbs_initialize failed\n", argv[0]);
return 1;
}
/* Identify ourself for the log file */
strcpy(user_params.u.userid, "[addacct]");
user_params.perms = ~0;
if (!uflg) strncpy(acct.username, acct.userid, sizeof acct.username-1);
rc = local_bbs_add_account(&acct, 0);
switch (rc) {
case S_BADUSERID:
case S_BADPASSWD:
fprintf(stderr, "%s: invalid userid or password\n", acct.userid);
break;
case S_USEREXISTS:
fprintf(stderr, "%s: userid already exists\n", acct.userid);
break;
case S_SYSERR:
fprintf(stderr, "%s: error creating account\n", acct.userid);
fprintf(stderr, "Wrong -d argument or $BBSHOME?\n");
}
local_bbs_disconnect();
return (rc == S_OK ? 0 : 1);
}