| Line | |
|---|
| 1 | /* finduser.c Copyright Michael Temari 07/22/1996 All Rights Reserved */
|
|---|
| 2 |
|
|---|
| 3 | #include <sys/types.h>
|
|---|
| 4 | #include <stdio.h>
|
|---|
| 5 | #include <string.h>
|
|---|
| 6 | #include <unistd.h>
|
|---|
| 7 | #include <stdlib.h>
|
|---|
| 8 | #include <fcntl.h>
|
|---|
| 9 | #include <time.h>
|
|---|
| 10 | #include <utmp.h>
|
|---|
| 11 | #include <net/gen/in.h>
|
|---|
| 12 |
|
|---|
| 13 | #include "talk.h"
|
|---|
| 14 | #include "finduser.h"
|
|---|
| 15 |
|
|---|
| 16 | int find_user(name, tty)
|
|---|
| 17 | char *name;
|
|---|
| 18 | char *tty;
|
|---|
| 19 | {
|
|---|
| 20 | int fd;
|
|---|
| 21 | int ret;
|
|---|
| 22 | struct utmp utmp;
|
|---|
| 23 |
|
|---|
| 24 | /* Now find out if the requested user is logged in. */
|
|---|
| 25 | if((fd = open(UTMP, O_RDONLY)) < 0) {
|
|---|
| 26 | perror("talkd: opening UTMP file");
|
|---|
| 27 | return(FAILED);
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | ret = NOT_HERE;
|
|---|
| 31 |
|
|---|
| 32 | while(read(fd, &utmp, sizeof(struct utmp)) == sizeof(struct utmp)) {
|
|---|
| 33 | if(utmp.ut_type != USER_PROCESS) continue;
|
|---|
| 34 | if(strncmp(utmp.ut_user, name, sizeof(utmp.ut_user))) continue;
|
|---|
| 35 | if(*tty && strncmp(utmp.ut_line, tty, sizeof(utmp.ut_line))) continue;
|
|---|
| 36 | strcpy(tty, utmp.ut_line);
|
|---|
| 37 | ret = SUCCESS;
|
|---|
| 38 | break;
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | close(fd);
|
|---|
| 42 |
|
|---|
| 43 | return(ret);
|
|---|
| 44 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.