home *** CD-ROM | disk | FTP | other *** search
- /* user.c -- functions dealing with logins
- Copyright (C) 1989 David MacKenzie
-
- This program 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 1, or (at your option)
- any later version.
-
- This program 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 this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-
- #include "hint.h"
- #include <utmp.h>
-
- /* Add all ttys where `user' is logged on to the list of ttys to hint.
- Return the number of times `user' is logged on. */
-
- int
- adduser (user)
- char *user;
- {
- struct utmp ut;
- int nfound; /* Number of times `user' is logged on. */
- int fd;
-
- fd = open ("/etc/utmp", O_RDONLY);
- if (fd == -1)
- pfatal ("/etc/utmp");
-
- nfound = 0;
- while (read (fd, &ut, sizeof (struct utmp)) > 0)
- nfound += addmatch (user, &ut);
-
- close (fd);
- return nfound;
- }
-
- /* If the name field in `utp' matches `user' and the tty is hint y,
- add the `utp' tty field to the list of ttys to hint and return 1;
- else,
- return 0. */
-
- int
- addmatch (user, utp)
- char *user;
- struct utmp *utp;
- {
- char temp_line[30]; /* 30 is random number > max. ut_line size. */
-
- /* Make sure it's a valid entry. */
- if (*utp->ut_name == 0)
- return 0;
-
- if (!strncmp (user, utp->ut_name, sizeof (utp->ut_name)))
- {
- strncpy (temp_line, utp->ut_line, sizeof (utp->ut_line));
- temp_line[sizeof (utp->ut_line)] = 0;
- addtty (user, temp_line);
- return 1;
- }
- else
- return 0;
- }
-