Commit | Line | Data |
---|---|---|
6b8910b8 | 1 | /* |
ad787160 C |
2 | * Copyright (c) 1989, 1993 |
3 | * The Regents of the University of California. All rights reserved. | |
6b8910b8 | 4 | * |
1c15e888 C |
5 | * This code is derived from software contributed to Berkeley by |
6 | * Tony Nardo of the Johns Hopkins University/Applied Physics Lab. | |
7 | * | |
ad787160 C |
8 | * Redistribution and use in source and binary forms, with or without |
9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | |
11 | * 1. Redistributions of source code must retain the above copyright | |
12 | * notice, this list of conditions and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | |
15 | * documentation and/or other materials provided with the distribution. | |
16 | * 3. All advertising materials mentioning features or use of this software | |
17 | * must display the following acknowledgement: | |
18 | * This product includes software developed by the University of | |
19 | * California, Berkeley and its contributors. | |
20 | * 4. Neither the name of the University nor the names of its contributors | |
21 | * may be used to endorse or promote products derived from this software | |
22 | * without specific prior written permission. | |
23 | * | |
24 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
32 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
33 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
34 | * SUCH DAMAGE. | |
6b8910b8 KB |
35 | */ |
36 | ||
37 | #ifndef lint | |
fd88f5c5 | 38 | static char sccsid[] = "@(#)sprint.c 8.3 (Berkeley) 4/28/95"; |
6b8910b8 KB |
39 | #endif /* not lint */ |
40 | ||
41 | #include <sys/types.h> | |
42 | #include <sys/time.h> | |
516a0fd6 | 43 | #include <time.h> |
6b8910b8 | 44 | #include <tzfile.h> |
e48ef2de | 45 | #include <db.h> |
185c6ba7 | 46 | #include <err.h> |
516a0fd6 | 47 | #include <pwd.h> |
e48ef2de | 48 | #include <errno.h> |
516a0fd6 | 49 | #include <utmp.h> |
6b8910b8 | 50 | #include <stdio.h> |
516a0fd6 KB |
51 | #include <stdlib.h> |
52 | #include <string.h> | |
6b8910b8 KB |
53 | #include "finger.h" |
54 | ||
516a0fd6 | 55 | static void stimeprint __P((WHERE *)); |
6b8910b8 | 56 | |
516a0fd6 | 57 | void |
6b8910b8 KB |
58 | sflag_print() |
59 | { | |
60 | extern time_t now; | |
61 | register PERSON *pn; | |
7619ff47 | 62 | register WHERE *w; |
e0c4280d | 63 | register int sflag, r; |
6b8910b8 | 64 | register char *p; |
185c6ba7 | 65 | PERSON *tmp; |
e0c4280d | 66 | DBT data, key; |
6b8910b8 | 67 | |
6b8910b8 KB |
68 | /* |
69 | * short format -- | |
70 | * login name | |
71 | * real name | |
72 | * terminal name (the XX of ttyXX) | |
73 | * if terminal writeable (add an '*' to the terminal name | |
74 | * if not) | |
75 | * if logged in show idle time and day logged in, else | |
76 | * show last login date and time. If > 6 moths, | |
77 | * show year instead of time. | |
78 | * office location | |
79 | * office phone | |
80 | */ | |
81 | #define MAXREALNAME 20 | |
82 | (void)printf("%-*s %-*s %s\n", UT_NAMESIZE, "Login", MAXREALNAME, | |
bd3331e3 | 83 | "Name", "Tty Idle Login Time Office Office Phone"); |
e0c4280d KB |
84 | |
85 | for (sflag = R_FIRST;; sflag = R_NEXT) { | |
86 | r = (*db->seq)(db, &key, &data, sflag); | |
87 | if (r == -1) | |
185c6ba7 | 88 | err(1, "db seq"); |
e0c4280d KB |
89 | if (r == 1) |
90 | break; | |
c4573784 | 91 | memmove(&tmp, data.data, sizeof tmp); |
185c6ba7 | 92 | pn = tmp; |
e0c4280d | 93 | |
7619ff47 EW |
94 | for (w = pn->whead; w != NULL; w = w->next) { |
95 | (void)printf("%-*.*s %-*.*s ", UT_NAMESIZE, UT_NAMESIZE, | |
96 | pn->name, MAXREALNAME, MAXREALNAME, | |
97 | pn->realname ? pn->realname : ""); | |
98 | if (!w->loginat) { | |
99 | (void)printf(" * * No logins "); | |
100 | goto office; | |
101 | } | |
102 | (void)putchar(w->info == LOGGEDIN && !w->writable ? | |
103 | '*' : ' '); | |
104 | if (*w->tty) | |
105 | (void)printf("%-2.2s ", | |
106 | w->tty[0] != 't' || w->tty[1] != 't' || | |
107 | w->tty[2] != 'y' ? w->tty : w->tty + 3); | |
108 | else | |
109 | (void)printf(" "); | |
110 | if (w->info == LOGGEDIN) { | |
111 | stimeprint(w); | |
112 | (void)printf(" "); | |
113 | } else | |
114 | (void)printf(" * "); | |
115 | p = ctime(&w->loginat); | |
116 | (void)printf("%.6s", p + 4); | |
117 | if (now - w->loginat >= SECSPERDAY * DAYSPERNYEAR / 2) | |
118 | (void)printf(" %.4s", p + 20); | |
119 | else | |
120 | (void)printf(" %.5s", p + 11); | |
121 | office: if (pn->office) | |
f156ea40 | 122 | (void)printf(" %-10.10s", pn->office); |
7619ff47 | 123 | else if (pn->officephone) |
f156ea40 | 124 | (void)printf(" %-10.10s", " "); |
7619ff47 | 125 | if (pn->officephone) |
f156ea40 KB |
126 | (void)printf(" %-.15s", |
127 | prphone(pn->officephone)); | |
7619ff47 | 128 | putchar('\n'); |
6b8910b8 | 129 | } |
6b8910b8 KB |
130 | } |
131 | } | |
132 | ||
516a0fd6 | 133 | static void |
7619ff47 EW |
134 | stimeprint(w) |
135 | WHERE *w; | |
6b8910b8 KB |
136 | { |
137 | register struct tm *delta; | |
138 | ||
7619ff47 | 139 | delta = gmtime(&w->idletime); |
6b8910b8 KB |
140 | if (!delta->tm_yday) |
141 | if (!delta->tm_hour) | |
142 | if (!delta->tm_min) | |
143 | (void)printf(" "); | |
144 | else | |
145 | (void)printf("%5d", delta->tm_min); | |
146 | else | |
147 | (void)printf("%2d:%02d", | |
148 | delta->tm_hour, delta->tm_min); | |
149 | else | |
150 | (void)printf("%4dd", delta->tm_yday); | |
151 | } |