1 /* login.c: The opielogin() library function.
4 This software is Copyright 1996-2001 by Craig Metz, All Rights Reserved.
5 The Inner Net License Version 3 applies to this software.
6 You should have received a copy of the license with this software. If
7 you didn't get a copy, you may request one from <license@inner.net>.
11 Modified by cmetz for OPIE 2.4. Add support for ut_id and
12 ut_syslen. Don't zero-terminate ut_name and ut_host.
13 Modified by cmetz for OPIE 2.31. If the OS won't tell us where
14 _PATH_WTMP[X] is, try playing the SVID game, then use
15 Autoconf-discovered values. Fixed gettimeofday() call
16 and updwtmpx() call. Call endutxent for utmpx. Added
18 Created by cmetz for OPIE 2.3.
23 #include <sys/types.h>
28 #define pututline(x) pututxline(x)
29 #define endutent endutxent
35 #endif /* HAVE_STRING_H */
45 int opielogin
FUNCTION((line
, name
, host
), char *line AND
char *name AND
char *host
)
50 char id
[IDLEN
+ 1] = "";
52 if (__opiegetutmpentry(line
, &u
)) {
54 syslog(LOG_DEBUG
, "opielogin: __opiegetutmpentry(line=%s, &u) failed", line
);
56 memset(&u
, 0, sizeof(struct utmp
));
57 if (!strncmp(line
, "/dev/", 5))
58 strncpy(u
.ut_line
, line
+ 5, sizeof(u
.ut_line
));
60 strncpy(u
.ut_line
, line
, sizeof(u
.ut_line
));
62 syslog(LOG_DEBUG
, "opielogin: continuing with ut_line=%s", u
.ut_line
);
66 #if DOUTMPX || HAVE_UT_ID
67 strncpy(id
, u
.ut_id
, sizeof(u
.ut_id
));
69 #endif /* DOUTMPX || HAVE_UT_ID */
71 #if HAVE_UT_TYPE && defined(USER_PROCESS)
72 u
.ut_type
= USER_PROCESS
;
73 #endif /* HAVE_UT_TYPE && defined(USER_PROCESS) */
76 #endif /* HAVE_UT_PID */
79 strncpy(u
.ut_name
, name
, sizeof(u
.ut_name
));
80 #else /* HAVE_UT_NAME */
81 #error No ut_name field in struct utmp? (Please send in a bug report)
82 #endif /* HAVE_UT_NAME */
85 strncpy(u
.ut_host
, host
, sizeof(u
.ut_host
));
86 #endif /* HAVE_UT_HOST */
87 #if DOUTMPX && HAVE_UTX_SYSLEN
88 u
.ut_syslen
= strlen(host
) + 1;
89 #endif /* DOUTMPX && HAVE_UT_SYSLEN */
92 #ifdef HAVE_ONE_ARG_GETTIMEOFDAY
93 gettimeofday(&u
.ut_tv
);
94 #else /* HAVE_ONE_ARG_GETTIMEOFDAY */
95 gettimeofday(&u
.ut_tv
, NULL
);
96 #endif /* HAVE_ONE_ARG_GETTIMEOFDAY */
105 syslog(LOG_DEBUG
, "opielogin: utmp suceeded");
107 #endif /* !DISABLE_UTMP */
110 opielogwtmp(line
, name
, host
, id
);
111 opielogwtmp(NULL
, NULL
, NULL
);
116 #endif /* HAVE_SETLOGIN */
119 syslog(LOG_DEBUG
, "opielogin: rval=%d", rval
);