}
lputuser(&CC->usersupp);
- /* Run any cleanup routines registered by loadable modules */
+ /* Run any startup routines registered by loadable modules */
PerformSessionHooks(EVT_LOGIN);
- usergoto(BASEROOM, 0, NULL, NULL); /* Enter the lobby */
+ /* Create any personal rooms required by the system */
+ create_room(SENTITEMS, 4, "", 0, 1);
+
+ /* Enter the lobby */
+ usergoto(BASEROOM, 0, NULL, NULL);
+
+ /* Record this login in the Citadel log */
rec_log(CL_LOGIN, CC->curr_user);
}
void logged_in_response(void)
{
- cprintf("%d %s|%d|%d|%d|%u|%ld\n",
+ cprintf("%d %s|%d|%ld|%ld|%u|%ld|%ld\n",
OK, CC->usersupp.fullname, CC->usersupp.axlevel,
CC->usersupp.timescalled, CC->usersupp.posted,
- CC->usersupp.flags,
- CC->usersupp.usernum);
+ CC->usersupp.flags, CC->usersupp.usernum,
+ CC->usersupp.lastcall);
}
void logout(struct CitContext *who)
{
who->logged_in = 0;
+
+ /*
+ * If there is a download in progress, abort it.
+ */
if (who->download_fp != NULL) {
fclose(who->download_fp);
who->download_fp = NULL;
}
+
+ /*
+ * If there is an upload in progress, abort it.
+ */
if (who->upload_fp != NULL) {
abort_upl(who);
}
+
+ /*
+ * If we were talking to a network node, we're not anymore...
+ */
+ if (strlen(who->net_node) > 0) {
+ network_talking_to(who->net_node, NTT_REMOVE);
+ }
+
+ /*
+ * Yes, we really need to free EVERY LAST BYTE we allocated.
+ */
+ if (who->cs_inet_email != NULL) {
+ phree(who->cs_inet_email);
+ who->cs_inet_email = NULL;
+ }
+
/* Do modular stuff... */
PerformSessionHooks(EVT_LOGOUT);
}
if (pipe(pipev)) {
lprintf(1, "pipe failed (%s): denying autologin access for "
- "uid %u\n", strerror(errno), uid);
+ "uid %ld\n", strerror(errno), (long)uid);
return 0;
}
switch (pid = fork()) {
case -1:
lprintf(1, "fork failed (%s): denying autologin access for "
- "uid %u\n", strerror(errno), uid);
+ "uid %ld\n", strerror(errno), (long)uid);
close(pipev[0]);
close(pipev[1]);
return 0;
while (waitpid(pid, &status, 0) == -1)
if (errno != EINTR) {
lprintf(1, "waitpid failed (%s): denying autologin "
- "access for uid %u\n",
- strerror(errno), uid);
+ "access for uid %ld\n",
+ strerror(errno), (long)uid);
return 0;
}
if (WIFEXITED(status) && !WEXITSTATUS(status))
/*
* create_user() - back end processing to create a new user
+ *
+ * Set 'newusername' to the desired account name.
+ * Set 'become_user' to nonzero if this is self-service account creation and we want
+ * to actually log in as the user we just created, otherwise set it to 0.
*/
-int create_user(char *newusername)
+int create_user(char *newusername, int become_user)
{
struct usersupp usbuf;
- int a;
struct passwd *p = NULL;
- char username[64];
+ char username[SIZ];
+ char mailboxname[ROOMNAMELEN];
+ uid_t uid;
strcpy(username, newusername);
strproc(username);
p = (struct passwd *) getpwnam(username);
#endif
if (p != NULL) {
- strcpy(username, p->pw_gecos);
- for (a = 0; a < strlen(username); ++a) {
- if (username[a] == ',')
- username[a] = 0;
- }
- CC->usersupp.uid = p->pw_uid;
+ extract_token(username, p->pw_gecos, 0, ',');
+ uid = p->pw_uid;
} else {
- CC->usersupp.uid = BBSUID;
+ uid = BBSUID;
}
if (!getuser(&usbuf, username)) {
return (ERROR + ALREADY_EXISTS);
}
- strcpy(CC->curr_user, username);
- strcpy(CC->usersupp.fullname, username);
- strcpy(CC->usersupp.password, "");
- (CC->logged_in) = 1;
+
+ /* Go ahead and initialize a new user record */
+ memset(&usbuf, 0, sizeof(struct usersupp));
+ strcpy(usbuf.fullname, username);
+ strcpy(usbuf.password, "");
+ usbuf.uid = uid;
/* These are the default flags on new accounts */
- CC->usersupp.flags = US_LASTOLD | US_DISAPPEAR | US_PAGINATOR | US_FLOORS;
+ usbuf.flags = US_LASTOLD | US_DISAPPEAR | US_PAGINATOR | US_FLOORS;
- CC->usersupp.timescalled = 0;
- CC->usersupp.posted = 0;
- CC->usersupp.axlevel = config.c_initax;
- CC->usersupp.USscreenwidth = 80;
- CC->usersupp.USscreenheight = 24;
- time(&CC->usersupp.lastcall);
- CC->usersupp.moderation_filter = config.c_default_filter;
+ usbuf.timescalled = 0;
+ usbuf.posted = 0;
+ usbuf.axlevel = config.c_initax;
+ usbuf.USscreenwidth = 80;
+ usbuf.USscreenheight = 24;
+ usbuf.lastcall = time(NULL);
+ usbuf.moderation_filter = config.c_default_filter;
/* fetch a new user number */
- CC->usersupp.usernum = get_new_user_number();
+ usbuf.usernum = get_new_user_number();
- if (CC->usersupp.usernum == 1L) {
- CC->usersupp.axlevel = 6;
+ /* The very first user created on the system will always be an Aide */
+ if (usbuf.usernum == 1L) {
+ usbuf.axlevel = 6;
}
+
/* add user to userlog */
- putuser(&CC->usersupp);
- if (getuser(&CC->usersupp, CC->curr_user)) {
- return (ERROR + INTERNAL_ERROR);
- }
+ putuser(&usbuf);
+
/* give the user a private mailbox */
- create_room(MAILROOM, 4, "", 0, 1);
+ MailboxName(mailboxname, &usbuf, MAILROOM);
+ create_room(mailboxname, 5, "", 0, 1);
+
+ /*** Everything below this line can be bypassed if we are administratively
+ creating a user, instead of doing self-service account creation
+ ***/
+
+ if (become_user) {
+ /* Now become the user we just created */
+ memcpy(&CC->usersupp, &usbuf, sizeof(struct usersupp));
+ strcpy(CC->curr_user, username);
+ CC->logged_in = 1;
+
+ /* Check to make sure we're still who we think we are */
+ if (getuser(&CC->usersupp, CC->curr_user)) {
+ return (ERROR + INTERNAL_ERROR);
+ }
+
+ rec_log(CL_NEWUSER, CC->curr_user);
+ }
- rec_log(CL_NEWUSER, CC->curr_user);
return (0);
}
/*
- * cmd_newu() - create a new user account
+ * cmd_newu() - create a new user account and log in as that user
*/
void cmd_newu(char *cmdbuf)
{
int a;
char username[SIZ];
- if ((CC->logged_in)) {
+ if (config.c_disable_newu) {
+ cprintf("%d Self-service user account creation "
+ "is disabled on this system.\n", ERROR);
+ return;
+ }
+
+ if (CC->logged_in) {
cprintf("%d Already logged in.\n", ERROR);
return;
}
- if ((CC->nologin)) {
+ if (CC->nologin) {
cprintf("%d %s: Too many users are already online (maximum is %d)\n",
ERROR + MAX_SESSIONS_EXCEEDED,
config.c_nodename, config.c_maxsessions);
cprintf("%d You must supply a user name.\n", ERROR);
return;
}
- a = create_user(username);
+
if ((!strcasecmp(username, "bbs")) ||
(!strcasecmp(username, "new")) ||
(!strcasecmp(username, "."))) {
- cprintf("%d '%s' is an invalid login name.\n", ERROR);
+ cprintf("%d '%s' is an invalid login name.\n", ERROR, username);
return;
}
- if (a == ERROR + ALREADY_EXISTS) {
+
+ a = create_user(username, 1);
+
+ if (a == 0) {
+ session_startup();
+ logged_in_response();
+ } else if (a == ERROR + ALREADY_EXISTS) {
cprintf("%d '%s' already exists.\n",
ERROR + ALREADY_EXISTS, username);
return;
cprintf("%d Internal error - user record disappeared?\n",
ERROR + INTERNAL_ERROR);
return;
- } else if (a == 0) {
- session_startup();
- logged_in_response();
} else {
cprintf("%d unknown error\n", ERROR);
}
*/
void cmd_setp(char *new_pw)
{
- if (CtdlAccessCheck(ac_logged_in))
+ if (CtdlAccessCheck(ac_logged_in)) {
return;
+ }
if (CC->usersupp.uid != BBSUID) {
cprintf("%d Not allowed. Use the 'passwd' command.\n", ERROR);
PerformSessionHooks(EVT_SETPASS);
}
+
+/*
+ * cmd_creu() - administratively create a new user account (do not log in to it)
+ */
+void cmd_creu(char *cmdbuf)
+{
+ int a;
+ char username[SIZ];
+
+ if (CtdlAccessCheck(ac_aide)) {
+ return;
+ }
+
+ extract(username, cmdbuf, 0);
+ username[25] = 0;
+ strproc(username);
+
+ if (strlen(username) == 0) {
+ cprintf("%d You must supply a user name.\n", ERROR);
+ return;
+ }
+
+ a = create_user(username, 0);
+
+ if (a == 0) {
+ cprintf("%d ok\n", OK);
+ return;
+ } else if (a == ERROR + ALREADY_EXISTS) {
+ cprintf("%d '%s' already exists.\n",
+ ERROR + ALREADY_EXISTS, username);
+ return;
+ } else {
+ cprintf("%d An error occured creating the user account.\n", ERROR);
+ }
+ rec_log(CL_NEWUSER, username);
+}
+
+
+
/*
* get user parameters
*/
struct visit vbuf;
/* On some systems, Aides are not allowed to forget rooms */
- if (is_aide() && (config.c_aide_zap == 0)) {
+ if (is_aide() && (config.c_aide_zap == 0)
+ && ((CC->quickroom.QRflags & QR_MAILBOX) == 0) ) {
return(1);
}
if ((CC->usersupp.axlevel >= 6)
|| ((usbuf->flags & US_UNLISTED) == 0)
|| ((CC->internal_pgm))) {
- cprintf("%s|%d|%ld|%ld|%d|%d|",
+ cprintf("%s|%d|%ld|%ld|%ld|%ld|",
usbuf->fullname,
usbuf->axlevel,
usbuf->usernum,
- usbuf->lastcall,
+ (long)usbuf->lastcall,
usbuf->timescalled,
usbuf->posted);
if (CC->usersupp.axlevel >= 6)
cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
return;
}
- cprintf("%d %s|%s|%u|%d|%d|%d|%ld|%ld|%d\n",
+ cprintf("%d %s|%s|%u|%ld|%ld|%d|%ld|%ld|%d\n",
OK,
usbuf.fullname,
usbuf.password,
usbuf.posted,
(int) usbuf.axlevel,
usbuf.usernum,
- usbuf.lastcall,
+ (long)usbuf.lastcall,
usbuf.USuserpurge);
}