* Copyright (c) 1989 The Regents of the University of California.
* %sccs.include.redist.c%
static char sccsid
[] = "@(#)util.c 5.18 (Berkeley) %G%";
static void find_idle_and_ttywrite
__P((WHERE
*));
static void userinfo
__P((PERSON
*, struct passwd
*));
static WHERE
*walloc
__P((PERSON
*));
/* why do we skip asterisks!?!? */
(void)strcpy(p
= tbuf
, pw
->pw_gecos
);
/* ampersands get replaced by the login name */
if (!(p
= strtok(p
, ",")))
for (t
= name
; *t
= *p
; ++p
)
(void)strcpy(t
, pw
->pw_name
);
for (t
= name
; p
= strtok(t
, "\t "); t
= (char *)NULL
)
if (!strcasecmp(p
, user
))
/* some systems may not maintain lastlog, don't report errors. */
fd
= open(_PATH_LASTLOG
, O_RDONLY
, 0);
lseek(fd
, (long)pn
->uid
* sizeof(ll
), SEEK_SET
) !=
(long)pn
->uid
* sizeof(ll
) ||
read(fd
, (char *)&ll
, sizeof(ll
)) != sizeof(ll
)) {
/* as if never logged in */
ll
.ll_line
[0] = ll
.ll_host
[0] = NULL
;
if ((w
= pn
->whead
) == NULL
)
else if (ll
.ll_time
!= 0) {
/* if last login is earlier than some current login */
for (; !doit
&& w
!= NULL
; w
= w
->next
)
if (w
->info
== LOGGEDIN
&& w
->loginat
< ll
.ll_time
)
* and if it's not any of the current logins
* can't use time comparison because there may be a small
* discrepency since login calls time() twice
for (w
= pn
->whead
; doit
&& w
!= NULL
; w
= w
->next
)
if (w
->info
== LOGGEDIN
&&
strncmp(w
->tty
, ll
.ll_line
, UT_LINESIZE
) == 0)
bcopy(ll
.ll_line
, w
->tty
, UT_LINESIZE
);
bcopy(ll
.ll_host
, w
->host
, UT_HOSTSIZE
);
w
->host
[UT_HOSTSIZE
] = 0;
bcopy(ut
->ut_line
, w
->tty
, UT_LINESIZE
);
bcopy(ut
->ut_host
, w
->host
, UT_HOSTSIZE
);
w
->host
[UT_HOSTSIZE
] = 0;
w
->loginat
= (time_t)ut
->ut_time
;
find_idle_and_ttywrite(w
);
register struct passwd
*pw
;
(db
= dbopen(NULL
, O_RDWR
, 0, DB_BTREE
, NULL
)) == NULL
)
err("%s", strerror(errno
));
key
.size
= strlen(pw
->pw_name
);
switch((*db
->get
)(db
, &key
, &data
, 0)) {
return(*(PERSON
**)data
.data
);
err("db get: %s", strerror(errno
));
data
.size
= sizeof(PERSON
*);
if ((*db
->put
)(db
, &key
, &data
, 0))
err("%s", strerror(errno
));
char buf
[UT_NAMESIZE
+ 1];
/* Name may be only UT_NAMESIZE long and not NUL terminated. */
for (cnt
= 0; cnt
< UT_NAMESIZE
&& *name
; ++name
, ++cnt
)
return((*db
->get
)(db
, &key
, &data
, 0) ? NULL
: *(PERSON
**)data
.data
);
if ((p
= malloc((u_int
) sizeof(PERSON
))) == NULL
)
err("%s", strerror(errno
));
if ((w
= malloc((u_int
) sizeof(WHERE
))) == NULL
)
err("%s", strerror(errno
));
pn
->whead
= pn
->wtail
= w
;
/* don't touch anything if the user has their own formatting */
case 11: /* +0-123-456-7890 */
case 10: /* 012-345-6789 */
find_idle_and_ttywrite(w
)
(void)snprintf(tbuf
, sizeof(tbuf
), "%s/%s", _PATH_DEV
, w
->tty
);
if (stat(tbuf
, &sb
) < 0) {
"finger: %s: %s\n", tbuf
, strerror(errno
));
w
->idletime
= now
< sb
.st_atime
? 0 : now
- sb
.st_atime
;
#define TALKABLE 0220 /* tty is writable if 220 mode */
w
->writable
= ((sb
.st_mode
& TALKABLE
) == TALKABLE
);
register struct passwd
*pw
;
pn
->realname
= pn
->office
= pn
->officephone
= pn
->homephone
= NULL
;
pn
->name
= strdup(pw
->pw_name
);
pn
->dir
= strdup(pw
->pw_dir
);
pn
->shell
= strdup(pw
->pw_shell
);
/* why do we skip asterisks!?!? */
(void)strcpy(bp
= tbuf
, pw
->pw_gecos
);
/* ampersands get replaced by the login name */
if (!(p
= strsep(&bp
, ",")))
for (t
= name
; *t
= *p
; ++p
)
(void)strcpy(t
, pw
->pw_name
);
pn
->realname
= strdup(name
);
pn
->office
= ((p
= strsep(&bp
, ",")) && *p
) ?
pn
->officephone
= ((p
= strsep(&bp
, ",")) && *p
) ?
pn
->homephone
= ((p
= strsep(&bp
, ",")) && *p
) ?
err(const char *fmt
, ...)
(void)fprintf(stderr
, "finger: ");
(void)vfprintf(stderr
, fmt
, ap
);
(void)fprintf(stderr
, "\n");