source: trunk/minix/commands/talkd/finduser.c@ 11

Last change on this file since 11 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 906 bytes
RevLine 
[9]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
16int find_user(name, tty)
17char *name;
18char *tty;
19{
20int fd;
21int ret;
22struct 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.