From ce20472e98d18a41cb5900f93911a56e2d86859f Mon Sep 17 00:00:00 2001 From: Michiel Broek Date: Thu, 3 Jan 2002 21:43:29 +0000 Subject: [PATCH] mblogin updates for FreeBSD --- config.h.in | 9 ++++ mbsebbs/Makefile | 7 +-- mbsebbs/limits.c | 2 + mbsebbs/log.c | 8 +--- mbsebbs/mblogin.c | 8 +++- mbsebbs/utent.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++ mbsebbs/utent.h | 12 +++++ mbsebbs/utmp.c | 4 +- mbsebbs/utmp.h | 6 +++ mbsetup/Makefile | 2 +- 10 files changed, 160 insertions(+), 12 deletions(-) create mode 100644 mbsebbs/utent.c create mode 100644 mbsebbs/utent.h diff --git a/config.h.in b/config.h.in index 3c40fdef..3f423496 100644 --- a/config.h.in +++ b/config.h.in @@ -8,6 +8,9 @@ /* Memory debugging */ #undef MEMWATCH +/* Define if you have the snprintf function. */ +#undef HAVE_SNPRINTF + /* Has strcasestr function */ #undef HAVE_STRCASESTR @@ -340,6 +343,12 @@ /* Define if `utime(file, NULL)' sets file's timestamp to the present. */ #undef HAVE_UTIME_NULL +/* Define if you have the header file. */ +#undef HAVE_UTMP_H + +/* Define if you have the header file. */ +#undef HAVE_UTMPX_H + /* Define if you have the header file. */ #undef HAVE_VFORK_H diff --git a/mbsebbs/Makefile b/mbsebbs/Makefile index 3d3a0d9a..dac2e2e2 100644 --- a/mbsebbs/Makefile +++ b/mbsebbs/Makefile @@ -15,7 +15,7 @@ SRCS = bank.c commonio.c filesub.c language.c mbtoberep.c \ door.c dispfile.c userlist.c timestats.c logentry.c pw_util.c \ mblogin.c env.c chowntty.c ttytype.c shell.c basename.c \ failure.c pwdcheck.c pwauth.c loginprompt.c utmp.c limits.c \ - setupenv.c sub.c ulimit.c log.c tz.c setugid.c + setupenv.c sub.c ulimit.c log.c tz.c setugid.c utent.c HDRS = bank.h commonio.h filesub.h language.h mbsebbs.h misc.h offline.h \ putpwent.h salt.h timeout.h bbslist.h email.h fsedit.h lineedit.h \ mbstat.h msgutil.h oneline.h sgetpwent.h user.h bye.h morefile.h \ @@ -26,7 +26,7 @@ HDRS = bank.h commonio.h filesub.h language.h mbsebbs.h misc.h offline.h \ door.h dispfile.h userlist.h timestats.h logentry.h lastcallers.h pw_util.h \ mblogin.h env.h chowntty.h ttytype.h shell.h basename.h \ failure.h pwdcheck.h pwauth.h loginprompt.h utmp.h limits.h \ - setupenv.h sub.h ulimit.h log.h tz.h setugid.h + setupenv.h sub.h ulimit.h log.h tz.h setugid.h utent.h MBSEBBS_OBJS = bank.o bbslist.o chat.o file.o funcs.o mail.o menu.o \ misc.o pinfo.o nextuser.o oneline.o page.o fsedit.o \ bye.o change.o mbsebbs.o safe.o timeout.o user.o timecheck.o \ @@ -57,7 +57,7 @@ MBPASSWD_OBJS = mbpasswd.o commonio.o pwio.o shadowio.o sgetpwent.o \ xmalloc.o myname.o rad64.o salt.o getdef.o encrypt.o putpwent.o pw_util.o MBLOGIN_OBJS = getdef.o env.o chowntty.o ttytype.o shell.o basename.o failure.o \ pwdcheck.o pwauth.o encrypt.o loginprompt.o utmp.o limits.o setupenv.o sub.o \ - xmalloc.o ulimit.o log.o tz.o setugid.o mblogin.o + xmalloc.o ulimit.o log.o tz.o setugid.o utent.o mblogin.o OTHER = Makefile TARGET = mbsebbs mbnewusr mball mblang mbchat mbstat mbtoberep mbuser mbuseradd mbpasswd mblogin @@ -238,4 +238,5 @@ ulimit.o: ../config.h ulimit.h log.o: ../config.h mblogin.h log.h tz.o: ../config.h mblogin.h getdef.h tz.h setugid.o: ../config.h mblogin.h getdef.h setugid.h +utent.o: ../config.h mblogin.h # End of generated dependencies diff --git a/mbsebbs/limits.c b/mbsebbs/limits.c index 1d6c4fdf..af28780a 100644 --- a/mbsebbs/limits.c +++ b/mbsebbs/limits.c @@ -138,10 +138,12 @@ int check_logins(const char *name, const char *maxlogins) if (ut->ut_type != USER_PROCESS) continue; #endif +#ifndef __FreeBSD__ if (ut->ut_user[0] == '\0') continue; if (strncmp(name, ut->ut_user, sizeof(ut->ut_user)) != 0) continue; +#endif if (++count > limit) break; } diff --git a/mbsebbs/log.c b/mbsebbs/log.c index 4dbb499f..076de112 100644 --- a/mbsebbs/log.c +++ b/mbsebbs/log.c @@ -37,11 +37,7 @@ #include #include #include "mblogin.h" -#if HAVE_LASTLOG_H -#include -#else -// #include "lastlog_.h" -#endif +#include #include "log.h" @@ -91,7 +87,7 @@ void dolastlog(struct lastlog *ll, const struct passwd *pw, const char *line, co time(&newlog.ll_time); strncpy(newlog.ll_line, line, sizeof newlog.ll_line); -#if HAVE_LL_HOST +#ifdef HAVE_LL_HOST strncpy(newlog.ll_host, host, sizeof newlog.ll_host); #endif if (lseek(fd, offset, SEEK_SET) == offset) diff --git a/mbsebbs/mblogin.c b/mbsebbs/mblogin.c index 8da83146..d009d607 100644 --- a/mbsebbs/mblogin.c +++ b/mbsebbs/mblogin.c @@ -47,7 +47,7 @@ #endif #include #include -#include +#include #include "getdef.h" #ifdef SVR4_SI86_EUA @@ -725,7 +725,9 @@ auth_ok: else failent_user = "UNKNOWN"; } +#ifndef __FreeBSD__ strncpy(failent.ut_user, failent_user, sizeof(failent.ut_user)); +#endif #ifdef USER_PROCESS failent.ut_type = USER_PROCESS; #endif @@ -780,7 +782,11 @@ auth_ok: if (getenv("IFS")) /* don't export user IFS ... */ addenv("IFS= \t\n", NULL); /* ... instead, set a safe IFS */ +#ifdef __FreeBSD__ + setutmp(username, tty); /* make entry in utmp & wtmp files */ +#else setutmp(username, tty, hostname); /* make entry in utmp & wtmp files */ +#endif if (pwent.pw_shell[0] == '*') { /* subsystem root */ subsystem (&pwent); /* figure out what to execute */ subroot++; /* say i was here again */ diff --git a/mbsebbs/utent.c b/mbsebbs/utent.c new file mode 100644 index 00000000..d2cac037 --- /dev/null +++ b/mbsebbs/utent.c @@ -0,0 +1,114 @@ +/***************************************************************************** + * + * $Id$ + * Purpose ...............: MBSE BBS Shadow Password Suite + * Original Source .......: Shadow Password Suite + * Original Copyright ....: Julianne Frances Haugh and others. + * + ***************************************************************************** + * Copyright (C) 1997-2001 + * + * Michiel Broek FIDO: 2:280/2802 + * Beekmansbos 10 + * 1971 BV IJmuiden + * the Netherlands + * + * This file is part of MBSE BBS. + * + * This BBS 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, or (at your option) any + * later version. + * + * MBSE BBS 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 MBSE BBS; see the file COPYING. If not, write to the Free + * Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + *****************************************************************************/ + +#include "../config.h" + +#ifndef HAVE_GETUTENT + +#include "mblogin.h" +#include +#include +#include + + +static int utmp_fd = -1; +static struct utmp utmp_buf; + +/* + * setutent - open or rewind the utmp file + */ + +void +setutent(void) +{ + if (utmp_fd == -1) + if ((utmp_fd = open (_UTMP_FILE, O_RDWR)) == -1) + utmp_fd = open (_UTMP_FILE, O_RDONLY); + + if (utmp_fd != -1) + lseek (utmp_fd, (off_t) 0L, SEEK_SET); +} + +/* + * endutent - close the utmp file + */ + +void +endutent(void) +{ + if (utmp_fd != -1) + close (utmp_fd); + + utmp_fd = -1; +} + +/* + * getutent - get the next record from the utmp file + */ + +struct utmp * +getutent(void) +{ + if (utmp_fd == -1) + setutent (); + + if (utmp_fd == -1) + return 0; + + if (read (utmp_fd, &utmp_buf, sizeof utmp_buf) != sizeof utmp_buf) + return 0; + + return &utmp_buf; +} + +/* + * getutline - get the utmp entry matching ut_line + */ + +struct utmp * +getutline(const struct utmp *utent) +{ + struct utmp save; + struct utmp *new; + + save = *utent; + while (new = getutent ()) + if (strncmp (new->ut_line, save.ut_line, sizeof new->ut_line)) + continue; + else + return new; + + return (struct utmp *) 0; +} +#else +extern int errno; /* warning: ANSI C forbids an empty source file */ +#endif diff --git a/mbsebbs/utent.h b/mbsebbs/utent.h new file mode 100644 index 00000000..955f1aa7 --- /dev/null +++ b/mbsebbs/utent.h @@ -0,0 +1,12 @@ + + +#include "../config.h" + +#ifndef HAVE_GETUTENT + +void setutent(void); +void endutent(void); +struct utmp *getutent(void); +struct utmp *getutline(const struct utmp *utent); + +#endif diff --git a/mbsebbs/utmp.c b/mbsebbs/utmp.c index e7e05c5d..1151976f 100644 --- a/mbsebbs/utmp.c +++ b/mbsebbs/utmp.c @@ -281,7 +281,7 @@ updwtmpx(const char *filename, const struct utmpx *utx) * USER_PROCESS. the wtmp file will be updated as well. */ -#if defined(__linux__) /* XXX */ +#if defined(__linux__) /* XXX */ void setutmp(const char *name, const char *line, const char *host) @@ -427,7 +427,9 @@ setutmp(const char *name, const char *line) * while System V has the name, PID and a type. */ +#ifndef __FreeBSD__ strncpy(utmp.ut_user, name, sizeof utent.ut_user); +#endif #ifdef USER_PROCESS utmp.ut_type = USER_PROCESS; utmp.ut_pid = getpid (); diff --git a/mbsebbs/utmp.h b/mbsebbs/utmp.h index bf75471b..34d8ecaa 100644 --- a/mbsebbs/utmp.h +++ b/mbsebbs/utmp.h @@ -16,6 +16,12 @@ static void updwtmpx(const char *, const struct utmpx *); #endif /* ! HAVE_UPDWTMPX */ #endif /* ! HAVE_UTMPX_H */ +#if defined(__linux__) /* XXX */ void setutmp(const char *, const char *, const char *); +#elif HAVE_UTMPX_H +void setutmp(const char *, const char *, const char *); +#else /* !SVR4 */ +void setutmp(const char *, const char *); +#endif #endif diff --git a/mbsetup/Makefile b/mbsetup/Makefile index 907a1de9..c71e8a25 100644 --- a/mbsetup/Makefile +++ b/mbsetup/Makefile @@ -74,7 +74,7 @@ grlist.o: ../lib/libs.h ../lib/structs.h ../lib/common.h ../lib/clcomm.h screen. m_domain.o: ../lib/libs.h ../lib/structs.h ../lib/records.h ../lib/common.h ../lib/clcomm.h screen.h mutil.h ledit.h m_global.h m_menu.h m_domain.h m_fgroup.o: ../lib/libs.h ../lib/structs.h ../lib/records.h ../lib/common.h ../lib/clcomm.h screen.h mutil.h ledit.h stlist.h m_global.h m_node.h m_ticarea.h m_fgroup.h m_lang.o: ../lib/libs.h ../lib/structs.h ../lib/records.h ../lib/common.h ../lib/clcomm.h screen.h mutil.h ledit.h stlist.h m_global.h m_lang.h -m_marea.o: ../lib/libs.h ../lib/structs.h ../lib/records.h ../lib/common.h ../lib/clcomm.h screen.h mutil.h ledit.h grlist.h m_global.h m_node.h m_mgroup.h m_marea.h +m_marea.o: ../lib/libs.h ../lib/structs.h ../lib/records.h ../lib/common.h ../lib/clcomm.h ../lib/msg.h screen.h mutil.h ledit.h grlist.h m_global.h m_node.h m_mgroup.h m_marea.h m_new.o: ../lib/libs.h ../lib/structs.h ../lib/records.h ../lib/common.h ../lib/clcomm.h screen.h mutil.h ledit.h stlist.h m_global.h grlist.h m_new.h m_lang.h m_marea.h m_ngroup.h m_protocol.o: ../lib/libs.h ../lib/structs.h ../lib/records.h ../lib/clcomm.h ../lib/common.h screen.h mutil.h ledit.h stlist.h m_global.h m_protocol.h m_ticarea.o: ../lib/libs.h ../lib/structs.h ../lib/records.h ../lib/common.h ../lib/clcomm.h screen.h mutil.h ledit.h stlist.h grlist.h m_global.h m_node.h m_fgroup.h m_farea.h m_archive.h m_ticarea.h