login.c revision 29964
1/* login.c: The opielogin() library function. 2 3%%% copyright-cmetz-96 4This software is Copyright 1996-1997 by Craig Metz, All Rights Reserved. 5The Inner Net License Version 2 applies to this software. 6You should have received a copy of the license with this software. If 7you didn't get a copy, you may request one from <license@inner.net>. 8 9 History: 10 11 Modified by cmetz for OPIE 2.31. If the OS won't tell us where 12 _PATH_WTMP[X] is, try playing the SVID game, then use 13 Autoconf-discovered values. Fixed gettimeofday() call 14 and updwtmpx() call. Call endutxent for utmpx. Added 15 DISABLE_UTMP. 16 Created by cmetz for OPIE 2.3. 17*/ 18 19#include "opie_cfg.h" 20#include <stdio.h> 21#include <sys/types.h> 22#include <utmp.h> 23 24#if DOUTMPX 25#include <utmpx.h> 26#define pututline(x) pututxline(x) 27#define endutent endutxent 28#define utmp utmpx 29#endif /* DOUTMPX */ 30 31#if HAVE_STRING_H 32#include <string.h> 33#endif /* HAVE_STRING_H */ 34#include <sys/stat.h> 35#if DEBUG 36#include <syslog.h> 37#include <errno.h> 38#endif /* DEBUG */ 39#include "opie.h" 40 41int opielogin FUNCTION((line, name, host), char *line AND char *name AND char *host) 42{ 43 struct utmp u; 44 int rval = 0; 45 46#if !DISABLE_UTMP 47 if (__opiegetutmpentry(line, &u)) { 48#if DEBUG 49 syslog(LOG_DEBUG, "opielogin: __opiegetutmpentry(line=%s, &u) failed", line); 50#endif /* DEBUG */ 51 memset(&u, 0, sizeof(struct utmp)); 52 if (!strncmp(line, "/dev/", 5)) 53 strncpy(u.ut_line, line + 5, sizeof(u.ut_line)); 54 else 55 strncpy(u.ut_line, line, sizeof(u.ut_line)); 56#if DEBUG 57 syslog(LOG_DEBUG, "opielogin: continuing with ut_line=%s", u.ut_line); 58#endif /* DEBUG */ 59 } 60 61#if HAVE_UT_TYPE && defined(USER_PROCESS) 62 u.ut_type = USER_PROCESS; 63#endif /* HAVE_UT_TYPE && defined(USER_PROCESS) */ 64#if HAVE_UT_PID 65 u.ut_pid = getpid(); 66#endif /* HAVE_UT_PID */ 67 68#if HAVE_UT_NAME 69 strncpy(u.ut_name, name, sizeof(u.ut_name)); 70 u.ut_name[sizeof(u.ut_name)-1] = 0; 71#else /* HAVE_UT_NAME */ 72#error No ut_name field in struct utmp? (Please send in a bug report) 73#endif /* HAVE_UT_NAME */ 74 75#if HAVE_UT_HOST 76 strncpy(u.ut_host, host, sizeof(u.ut_host)); 77 u.ut_host[sizeof(u.ut_host)-1] = 0; 78#endif /* HAVE_UT_HOST */ 79 80#if DOUTMPX 81#ifdef HAVE_ONE_ARG_GETTIMEOFDAY 82 gettimeofday(&u.ut_tv); 83#else /* HAVE_ONE_ARG_GETTIMEOFDAY */ 84 gettimeofday(&u.ut_tv, NULL); 85#endif /* HAVE_ONE_ARG_GETTIMEOFDAY */ 86#else /* DOUTMPX */ 87 time(&u.ut_time); 88#endif /* DOUTMPX */ 89 90 pututline(&u); 91 endutent(); 92 93#if DEBUG 94 syslog(LOG_DEBUG, "opielogin: utmp suceeded"); 95#endif /* DEBUG */ 96#endif /* !DISABLE_UTMP */ 97 98dowtmp: 99 opielogwtmp(line, name, host); 100 opielogwtmp(NULL, NULL, NULL); 101 102dosetlogin: 103#if HAVE_SETLOGIN 104 setlogin(name); 105#endif /* HAVE_SETLOGIN */ 106 107#if DEBUG 108 syslog(LOG_DEBUG, "opielogin: rval=%d", rval); 109#endif /* DEBUG */ 110 111 return rval; 112} 113