From ae560bddd31613f6ef0e3939306907fed527db0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Love=20H=C3=B6rnquist=20=C3=85strand?= Date: Thu, 10 Apr 2008 09:47:28 +0000 Subject: [PATCH] Remove utmp warning on mac os x git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@22947 ec53bebd-3082-4978-b11e-865c3cabbd6b --- appl/login/utmp_login.c | 87 +++++++++++++++++++++-------------------- 1 file changed, 45 insertions(+), 42 deletions(-) diff --git a/appl/login/utmp_login.c b/appl/login/utmp_login.c index 3b31af0fc..cd05e2c80 100644 --- a/appl/login/utmp_login.c +++ b/appl/login/utmp_login.c @@ -77,7 +77,51 @@ shrink_hostname (const char *hostname, } } -void +#ifdef HAVE_UTMPX_H +void utmp_login(char *tty, const char *username, const char *hostname) +{ + return; +} +#else + +/* update utmp and wtmp - the BSD way */ + +static void prepare_utmp (struct utmp *, char *, const char *, const char *); + +void utmp_login(char *tty, const char *username, const char *hostname) +{ + struct utmp utmp; + int fd; + + prepare_utmp (&utmp, tty, username, hostname); + +#ifdef HAVE_SETUTENT + utmpname(_PATH_UTMP); + setutent(); + pututline(&utmp); + endutent(); +#else + +#ifdef HAVE_TTYSLOT + { + int ttyno; + ttyno = ttyslot(); + if (ttyno > 0 && (fd = open(_PATH_UTMP, O_WRONLY, 0)) >= 0) { + lseek(fd, (long)(ttyno * sizeof(struct utmp)), SEEK_SET); + write(fd, &utmp, sizeof(struct utmp)); + close(fd); + } + } +#endif /* HAVE_TTYSLOT */ +#endif /* HAVE_SETUTENT */ + + if ((fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) >= 0) { + write(fd, &utmp, sizeof(struct utmp)); + close(fd); + } +} + +static void prepare_utmp (struct utmp *utmp, char *tty, const char *username, const char *hostname) { @@ -118,45 +162,4 @@ prepare_utmp (struct utmp *utmp, char *tty, # endif } -#ifdef HAVE_UTMPX_H -void utmp_login(char *tty, const char *username, const char *hostname) -{ - return; -} -#else - -/* update utmp and wtmp - the BSD way */ - -void utmp_login(char *tty, const char *username, const char *hostname) -{ - struct utmp utmp; - int fd; - - prepare_utmp (&utmp, tty, username, hostname); - -#ifdef HAVE_SETUTENT - utmpname(_PATH_UTMP); - setutent(); - pututline(&utmp); - endutent(); -#else - -#ifdef HAVE_TTYSLOT - { - int ttyno; - ttyno = ttyslot(); - if (ttyno > 0 && (fd = open(_PATH_UTMP, O_WRONLY, 0)) >= 0) { - lseek(fd, (long)(ttyno * sizeof(struct utmp)), SEEK_SET); - write(fd, &utmp, sizeof(struct utmp)); - close(fd); - } - } -#endif /* HAVE_TTYSLOT */ -#endif /* HAVE_SETUTENT */ - - if ((fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) >= 0) { - write(fd, &utmp, sizeof(struct utmp)); - close(fd); - } -} #endif /* !HAVE_UTMPX_H */