forked from csgauthier/iscabbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shell.c
335 lines (294 loc) · 7.87 KB
/
shell.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
/*
* shell.c - Initializes everything necessary prior to entering the BBS.
*/
#include "defs.h"
#include "ext.h"
/*
* get_name (prompt)
*
* Display the prompt given and then accept a name in the form of "First Last".
* Will automatically capitilize the name. Backspace are allowed. Will not
* allow a blank entry. Control-D quits the program.
*
* quit_priv: 0 - make user enter something 1 - allow ctrl-d to quit program
* 2 - allow blank entry 3 - allow digits & blank entry
*
* 0 & 3 allow MAXNAME characters, 1 & 2 allow MAXALIAS characters
*
*/
char *
get_name(const char *prompt, int quit_priv)
{
char *p;
int c;
int upflag;
int fflag;
int invalid = 0;
for (;;)
{
my_printf("%s", prompt);
if (client)
{
my_putchar(IAC);
my_putchar(G_NAME);
my_putchar(quit_priv);
my_putc((byte >> 16) & 255, stdout);
my_putc((byte >> 8) & 255, stdout);
my_putc(byte & 255, stdout);
block = 1;
}
upflag = fflag = 1;
p = pbuf;
for (;;)
{
c = inkey();
if (c == NL)
break;
if (c == CTRL_D && quit_priv == 1)
{
my_putchar('\n');
my_exit(1);
}
if (c == '_')
c = ' ';
if (c == SP && (fflag || upflag))
continue;
if (c == BS || c == CTRL_X || c == CTRL_W || c == CTRL_R || c == SP || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9' && quit_priv == 3))
invalid = 0;
else
{
if (invalid++)
flush_input(invalid < 6 ? (invalid / 2) : 3);
continue;
}
if (c == CTRL_R)
{
*p = 0;
my_printf("\n%s", pbuf);
continue;
}
do
if ((c == BS || c == CTRL_X || c == CTRL_W) && p > pbuf)
{
my_putchar(BS);
my_putchar(SP);
my_putchar(BS);
--p;
upflag = (p == pbuf || *(p - 1) == SP);
if (upflag && c == CTRL_W)
break;
if (p == pbuf)
fflag = 1;
}
else
if (p < &pbuf[!quit_priv || quit_priv == 3 ? MAXNAME : MAXALIAS] && c != BS && c != CTRL_X && c != CTRL_W)
{
fflag = 0;
if (upflag && c >= 'a')
c -= 32;
if (c >= '0')
upflag = 0;
else if (c == SP)
upflag = 1;
*p++ = c;
if (!client)
my_putchar(c);
}
while ((c == CTRL_X || c == CTRL_W) && p > pbuf);
}
*p = 0;
if (p > pbuf || quit_priv >= 2)
break;
if (quit_priv)
my_printf("\nPress CTRL-D to quit.\n");
else
my_printf("\nThis really isn't optional!\n");
}
if (!client)
my_putchar(NL);
if (p > pbuf && p[-1] == ' ')
p[-1] = 0;
return (pbuf);
}
/*
* do_login()
*
* Prompt the user for his username and password and then call login_user Set the
* global variable ouruser
*/
void
do_login(void)
{
int i;
int users;
char *name;
struct user *tmpuser = 0;
int wrong = 0;
int fd;
char *bbsname;
char pas[9];
char temp[128];
char myname[MAXALIAS + 1];
/* We already checked this from the queue,
* so our back door now is to telnet localhost
*/
if ((fd = open (DOWNFILE, O_RDONLY)) > 0)
{
if (tty)
{
close (fd);
more (DOWNFILE, NO);
my_printf ("\nDOC Version 1.7, Fbrd rev. 0.3, m0n0 (aka vDOC 1.7).\n\n");
my_exit (3);
}
else my_printf ("The BBS is down, but you will be let in.\n\n");
}
my_printf ("\nDOC Version 1.7, Fbrd rev. 0.3, m0n0 (aka vDOC 1.7).\n\n");
if ((fd = open (MOTD, O_RDONLY)) > 0)
{
close (fd);
more (MOTD, NO);
}
more (HELLOFILE, NO);
bbsname = getenv ("BBSNAME");
for (;;)
{
guest = 0;
if (!bbsname)
name = get_name("Name: ", 1);
else
strcpy(name = myname, bbsname);
if (strcmp(name, "New"))
{
if ((tmpuser = getuser(name)))
freeuser(tmpuser);
if (tmpuser && (!bbsname || tty) && strcmp(name, "Guest"))
get_string("Password: ", -8, pas, -1);
if (!tmpuser || !(ouruser = login_user(name, pas)))
{
if (tmpuser)
my_printf("Incorrect login.\n");
else
my_printf("There is no user %s on this BBS.\n", name);
my_exit(3);
// if (++wrong > 3 || bbsname)
// {
// if (!bbsname)
// my_printf("\n\nToo many attempts. Goodbye.\n");
// my_exit(3);
// }
flush_input(wrong);
continue;
}
else
{
xinit(NO);
my_printf("\nWelcome to %s, %s!\n", BBSNAME, ouruser->name);
if (ouruser->f_deleted)
{
if (ouruser->f_namechanged)
my_printf("\a\nThis account has been marked for deletion because of a request to change the\nusername from '%s' to '%s'.\n\nYou may login as '%s' using the same password.\n\n", ouruser->name, ouruser->reminder, ouruser->reminder);
else
my_printf("\a\nThis account has been marked for deletion, either through your choice or\nbecause you violated BBS rules by doing something such as providing\nobviously bogus profile info. You will be logged off.\n\n");
my_exit(10);
}
else if (ouruser->f_inactive)
{
my_printf("You seem to have been denied access to the message system.\n");
// my_printf("Please contact ISCA (e-mail address bbs@bbs.isca.uiowa.edu) for more.\n");
my_exit(10);
}
i = ouruser->time;
users = add_loggedin(ouruser);
if (!guest && ouruser->time)
{
my_printf("Last on: %s ", formtime (3, i));
if (ouruser->timeoff >= i)
my_printf("until %s from %s\n", formtime (4, ouruser->timeoff), ouruser->remote);
else
my_printf("from %s\n", ouruser->remote);
}
strcpy(ouruser->loginname, ARGV[1] && ARGV[2] ? ARGV[2] : "");
/* I added in code that will grab hostnames from tty connections. -JB */
strncpy(ouruser->remote, gethost(), sizeof (ouruser->remote) - 1);
if (ouruser->f_noclient)
{
my_printf("\n\nYou have been disallowed use of the BBS client, you must login using telnet.\n\n");
my_exit(10);
}
checked_snprintf(temp,sizeof(temp), "%s %s%s%s/%d", client ? "CLIENT" : "LOGIN", ARGV[1] && ARGV[2] ? ARGV[2] : "", ARGV[1] && ARGV[2] ? "@" : "", ouruser->remote, mybtmp->remport);
logevent(temp);
++ouruser->timescalled;
if (!guest)
my_printf("This is call %d. There are %d users.\n", ouruser->timescalled, (users-9) );
if (ouruser->f_aide)
validate_users(0);
/*
* Turn off expresses and tell the user this was done if user is
* configured for this
*/
if (!guest && mybtmp->xstat)
my_printf("\nNOTE: You have eXpress messages turned OFF as a default!\n");
if (mybtmp->elf)
my_printf("\nYou are marked as available to help others.\n");
checkmail(ouruser, FALSE);
termset();
if (*ouruser->reminder)
{
my_printf("\n\aREMINDER:\n%s\n\n", ouruser->reminder);
my_printf("Please hit 'Y' to acknowledge having seen this reminder -> ");
get_single_quiet("yY");
}
if (ouruser->f_badinfo || ouruser->f_duplicate)
{
help("badinfo", NO);
sleep(300);
}
if (guest)
{
help("guestwelcome", NO);
hit_return_now();
}
return;
}
}
else
if (!(i = new_user()))
{
my_printf("\n\nSorry, there was some problem setting up your BBS account.\n\nPlease try again later.\n\n");
my_exit(10);
}
else if (i > 0)
return;
}
}
void
profile_user(int all)
{
char *name;
int how = PROF_REG;
my_printf("Profile user\n\nUser to profile? %s", all ? "[FULL PROFILE] " : "");
if (*profile_default)
my_printf("(%s) -> ", profile_default);
else
my_printf("-> ");
name = get_name("", 2);
if (!*name)
{
if (*profile_default)
name = profile_default;
else
strcpy (name, ouruser->name);
}
if (all)
{
if (ouruser->f_admin)
how = PROF_ALL;
else if (!strcmp(name, ouruser->name))
how = PROF_SELF;
else
how = PROF_EXTRA;
}
if (profile(name, NULL, how) < 0)
my_printf("There is no user %s on this BBS.\n", name);
}