login.c revision 29964
122347Spst/* login.c: The opielogin() library function. 222347Spst 329964Sache%%% copyright-cmetz-96 429964SacheThis software is Copyright 1996-1997 by Craig Metz, All Rights Reserved. 522347SpstThe Inner Net License Version 2 applies to this software. 622347SpstYou should have received a copy of the license with this software. If 722347Spstyou didn't get a copy, you may request one from <license@inner.net>. 822347Spst 922347Spst History: 1022347Spst 1129964Sache Modified by cmetz for OPIE 2.31. If the OS won't tell us where 1229964Sache _PATH_WTMP[X] is, try playing the SVID game, then use 1329964Sache Autoconf-discovered values. Fixed gettimeofday() call 1429964Sache and updwtmpx() call. Call endutxent for utmpx. Added 1529964Sache DISABLE_UTMP. 1622347Spst Created by cmetz for OPIE 2.3. 1722347Spst*/ 1822347Spst 1922347Spst#include "opie_cfg.h" 2022347Spst#include <stdio.h> 2122347Spst#include <sys/types.h> 2222347Spst#include <utmp.h> 2322347Spst 2422347Spst#if DOUTMPX 2522347Spst#include <utmpx.h> 2622347Spst#define pututline(x) pututxline(x) 2729964Sache#define endutent endutxent 2822347Spst#define utmp utmpx 2922347Spst#endif /* DOUTMPX */ 3022347Spst 3122347Spst#if HAVE_STRING_H 3222347Spst#include <string.h> 3322347Spst#endif /* HAVE_STRING_H */ 3422347Spst#include <sys/stat.h> 3522347Spst#if DEBUG 3622347Spst#include <syslog.h> 3722347Spst#include <errno.h> 3822347Spst#endif /* DEBUG */ 3922347Spst#include "opie.h" 4022347Spst 4122347Spstint opielogin FUNCTION((line, name, host), char *line AND char *name AND char *host) 4222347Spst{ 4322347Spst struct utmp u; 4422347Spst int rval = 0; 4522347Spst 4629964Sache#if !DISABLE_UTMP 4722347Spst if (__opiegetutmpentry(line, &u)) { 4822347Spst#if DEBUG 4922347Spst syslog(LOG_DEBUG, "opielogin: __opiegetutmpentry(line=%s, &u) failed", line); 5022347Spst#endif /* DEBUG */ 5122347Spst memset(&u, 0, sizeof(struct utmp)); 5222347Spst if (!strncmp(line, "/dev/", 5)) 5322347Spst strncpy(u.ut_line, line + 5, sizeof(u.ut_line)); 5422347Spst else 5522347Spst strncpy(u.ut_line, line, sizeof(u.ut_line)); 5622347Spst#if DEBUG 5722347Spst syslog(LOG_DEBUG, "opielogin: continuing with ut_line=%s", u.ut_line); 5822347Spst#endif /* DEBUG */ 5922347Spst } 6022347Spst 6122347Spst#if HAVE_UT_TYPE && defined(USER_PROCESS) 6222347Spst u.ut_type = USER_PROCESS; 6322347Spst#endif /* HAVE_UT_TYPE && defined(USER_PROCESS) */ 6422347Spst#if HAVE_UT_PID 6522347Spst u.ut_pid = getpid(); 6622347Spst#endif /* HAVE_UT_PID */ 6722347Spst 6822347Spst#if HAVE_UT_NAME 6922347Spst strncpy(u.ut_name, name, sizeof(u.ut_name)); 7029964Sache u.ut_name[sizeof(u.ut_name)-1] = 0; 7122347Spst#else /* HAVE_UT_NAME */ 7222347Spst#error No ut_name field in struct utmp? (Please send in a bug report) 7322347Spst#endif /* HAVE_UT_NAME */ 7422347Spst 7522347Spst#if HAVE_UT_HOST 7622347Spst strncpy(u.ut_host, host, sizeof(u.ut_host)); 7729964Sache u.ut_host[sizeof(u.ut_host)-1] = 0; 7822347Spst#endif /* HAVE_UT_HOST */ 7922347Spst 8022347Spst#if DOUTMPX 8122347Spst#ifdef HAVE_ONE_ARG_GETTIMEOFDAY 8229964Sache gettimeofday(&u.ut_tv); 8322347Spst#else /* HAVE_ONE_ARG_GETTIMEOFDAY */ 8429964Sache gettimeofday(&u.ut_tv, NULL); 8522347Spst#endif /* HAVE_ONE_ARG_GETTIMEOFDAY */ 8622347Spst#else /* DOUTMPX */ 8722347Spst time(&u.ut_time); 8822347Spst#endif /* DOUTMPX */ 8922347Spst 9022347Spst pututline(&u); 9122347Spst endutent(); 9222347Spst 9322347Spst#if DEBUG 9422347Spst syslog(LOG_DEBUG, "opielogin: utmp suceeded"); 9522347Spst#endif /* DEBUG */ 9629964Sache#endif /* !DISABLE_UTMP */ 9722347Spst 9822347Spstdowtmp: 9929964Sache opielogwtmp(line, name, host); 10029964Sache opielogwtmp(NULL, NULL, NULL); 10122347Spst 10222347Spstdosetlogin: 10322347Spst#if HAVE_SETLOGIN 10422347Spst setlogin(name); 10522347Spst#endif /* HAVE_SETLOGIN */ 10622347Spst 10722347Spst#if DEBUG 10822347Spst syslog(LOG_DEBUG, "opielogin: rval=%d", rval); 10922347Spst#endif /* DEBUG */ 11022347Spst 11122347Spst return rval; 11222347Spst} 113