#include <string.h>
#include <syslog.h>
#include <limits.h>
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
-#endif
#ifndef ENABLE_CHKPWD
#include "auth.h"
#endif
}
lowercase_name[sizeof(lowercase_name)-1] = 0;
+ usbuf->version = config.c_setup_level;
cdb_store(CDB_USERSUPP,
lowercase_name, strlen(lowercase_name),
usbuf, sizeof(struct usersupp));
/*
- * USER cmd
+ * Back end for cmd_user() and its ilk
*/
-void cmd_user(char *cmdbuf)
+int CtdlLoginExistingUser(char *username)
{
- char username[256];
char autoname[256];
int found_user = 0;
struct passwd *p;
int a;
- extract(username,cmdbuf,0);
username[25] = 0;
strproc(username);
if ((CC->logged_in)) {
- cprintf("%d Already logged in.\n",ERROR);
- return;
- }
+ return login_already_logged_in;
+ }
found_user = getuser(&CC->usersupp,username);
if (found_user != 0) {
for (a=0; a<strlen(autoname); ++a)
if (autoname[a]==',') autoname[a]=0;
found_user = getuser(&CC->usersupp,autoname);
- }
}
+ }
if (found_user == 0) {
if (((CC->nologin)) && (CC->usersupp.axlevel < 6)) {
- cprintf("%d %s: Too many users are already online (maximum is %d)\n",
- ERROR+MAX_SESSIONS_EXCEEDED,
- config.c_nodename,config.c_maxsessions);
- }
+ return login_too_many_users;
+ }
else {
strcpy(CC->curr_user,CC->usersupp.fullname);
+ return login_ok;
+ }
+ }
+ return login_not_found;
+}
+
+
+
+/*
+ * USER cmd
+ */
+void cmd_user(char *cmdbuf)
+{
+ char username[256];
+ int a;
+
+ extract(username,cmdbuf,0);
+ username[25] = 0;
+ strproc(username);
+
+ a = CtdlLoginExistingUser(username);
+ switch(a) {
+ case login_already_logged_in:
+ cprintf("%d Already logged in.\n",ERROR);
+ return;
+ case login_too_many_users:
+ cprintf("%d %s: "
+ "Too many users are already online "
+ "(maximum is %d)\n",
+ ERROR+MAX_SESSIONS_EXCEEDED,
+ config.c_nodename,config.c_maxsessions);
+ return;
+ case login_ok:
cprintf("%d Password required for %s\n",
MORE_DATA,CC->curr_user);
- }
- }
- else {
- cprintf("%d %s not found.\n",ERROR,username);
- }
+ return;
+ case login_not_found:
+ cprintf("%d %s not found.\n", ERROR, username);
+ return;
+ cprintf("%d Internal error\n", ERROR);
}
+}
/* Run any cleanup routines registered by loadable modules */
PerformSessionHooks(EVT_LOGIN);
- cprintf("%d %s|%d|%d|%d|%u|%ld\n",OK,CC->usersupp.fullname,CC->usersupp.axlevel,
- CC->usersupp.timescalled,CC->usersupp.posted,CC->usersupp.flags,
- CC->usersupp.usernum);
usergoto(BASEROOM,0); /* Enter the lobby */
rec_log(CL_LOGIN,CC->curr_user);
}
+void logged_in_response(void) {
+ cprintf("%d %s|%d|%d|%d|%u|%ld\n",
+ OK, CC->usersupp.fullname, CC->usersupp.axlevel,
+ CC->usersupp.timescalled, CC->usersupp.posted,
+ CC->usersupp.flags,
+ CC->usersupp.usernum);
+}
+
+
+
/*
* misc things to be taken care of when a user is logged out
*/
}
#endif
-void cmd_pass(char *buf)
+
+
+int CtdlTryPassword(char *password)
{
- char password[256];
int code;
- extract(password,buf,0);
-
if ((CC->logged_in)) {
- cprintf("%d Already logged in.\n",ERROR);
- return;
+ return pass_already_logged_in;
}
- if (!strcmp(CC->curr_user,"")) {
- cprintf("%d You must send a name with USER first.\n",ERROR);
- return;
+ if (!strcmp(CC->curr_user, NLI)) {
+ return pass_no_user;
}
- if (getuser(&CC->usersupp,CC->curr_user)) {
- cprintf("%d Can't find user record!\n",ERROR+INTERNAL_ERROR);
- return;
+ if (getuser(&CC->usersupp, CC->curr_user)) {
+ return pass_internal_error;
}
code = (-1);
- if (CC->usersupp.USuid == BBSUID) {
+ if (CC->usersupp.uid == BBSUID) {
strproc(password);
strproc(CC->usersupp.password);
code = strcasecmp(CC->usersupp.password,password);
}
#ifdef ENABLE_AUTOLOGIN
else {
- if (validpw(CC->usersupp.USuid, password)) {
+ if (validpw(CC->usersupp.uid, password)) {
code = 0;
lgetuser(&CC->usersupp, CC->curr_user);
safestrncpy(CC->usersupp.password, password,
if (!code) {
(CC->logged_in) = 1;
session_startup();
+ return pass_ok;
}
else {
- cprintf("%d Wrong password.\n",ERROR);
rec_log(CL_BADPW,CC->curr_user);
+ return pass_wrong_password;
}
}
+void cmd_pass(char *buf)
+{
+ char password[256];
+ int a;
+
+ extract(password, buf, 0);
+ a = CtdlTryPassword(password);
+
+ switch (a) {
+ case pass_already_logged_in:
+ cprintf("%d Already logged in.\n",ERROR);
+ return;
+ case pass_no_user:
+ cprintf("%d You must send a name with USER first.\n",
+ ERROR);
+ return;
+ case pass_wrong_password:
+ cprintf("%d Wrong password.\n", ERROR);
+ return;
+ case pass_ok:
+ logged_in_response();
+ return;
+ cprintf("%d Can't find user record!\n",
+ ERROR+INTERNAL_ERROR);
+ }
+}
+
+
+
/*
* Delete a user record *and* all of its related resources.
*/
for (a=0; a<strlen(username); ++a) {
if (username[a] == ',') username[a] = 0;
}
- CC->usersupp.USuid = p->pw_uid;
+ CC->usersupp.uid = p->pw_uid;
}
else {
- CC->usersupp.USuid = BBSUID;
+ CC->usersupp.uid = BBSUID;
}
if (!getuser(&usbuf,username)) {
CC->usersupp.USscreenwidth = 80;
CC->usersupp.USscreenheight = 24;
time(&CC->usersupp.lastcall);
- strcpy(CC->usersupp.USname, "");
- strcpy(CC->usersupp.USaddr, "");
- strcpy(CC->usersupp.UScity, "");
- strcpy(CC->usersupp.USstate, "");
- strcpy(CC->usersupp.USzip, "");
- strcpy(CC->usersupp.USphone, "");
/* fetch a new user number */
CC->usersupp.usernum = get_new_user_number();
}
else if (a==0) {
session_startup();
+ logged_in_response();
}
else {
cprintf("%d unknown error\n",ERROR);
cprintf("%d Not logged in.\n",ERROR+NOT_LOGGED_IN);
return;
}
- if (CC->usersupp.USuid != BBSUID) {
+ if (CC->usersupp.uid != BBSUID) {
cprintf("%d Not allowed. Use the 'passwd' command.\n",ERROR);
return;
}
char requested_user[256];
int np;
int newax;
+ int deleted = 0;
if ( (CC->internal_pgm==0)
&& ( (CC->logged_in == 0) || (is_aide()==0) ) ) {
lputuser(&usbuf);
if (usbuf.axlevel == 0) {
if (purge_user(requested_user)==0) {
- cprintf("%d %s deleted.\n", OK, requested_user);
+ deleted = 1;
}
}
- cprintf("%d Ok\n", OK);
+ cprintf("%d Ok", OK);
+ if (deleted) cprintf(" (%s deleted)", requested_user);
+ cprintf("\n");
}