1 /* This file is part of the Project Athena Zephyr Notification System.
2 * It contains code for the "zlocate" command.
4 * Created by: Robert French
6 * $Id: zlocate.c,v 1.15 1999/01/22 23:18:36 ghudson Exp $
8 * Copyright (c) 1987 by the Massachusetts Institute of Technology.
9 * For copying and distribution information, see the file
14 #include <zephyr/zephyr.h>
15 #include <sys/socket.h>
17 #if !defined(lint) && !defined(SABER)
18 static const char rcsid_zlocate_c[] = "$Id: zlocate.c,v 1.15 1999/01/22 23:18:36 ghudson Exp $";
21 int numusers=0, numleft=0, parallel=0, oneline=0;
24 RETSIGTYPE timeout(sig)
26 fprintf (stderr, "%s: no response from server\n", whoami);
32 printf("Usage: %s [ -a | -d ] [ -p ] [ -1 ] user ... \n",whoami);
36 void print_locs(user,nlocs)
41 ZLocations_t locations;
43 if ((!oneline) && (numusers>1))
44 printf("\t%s:\n",user);
46 if ((!oneline) && (nlocs == 0))
47 printf("Hidden or not logged-in\n");
49 for (;nlocs;nlocs--) {
50 if ((retval = ZGetLocations(&locations,&one)) != ZERR_NONE) {
51 com_err(whoami,retval,"while getting location");
56 printf("%s:\t%s\t%s\t%s\n",user,locations.host,locations.tty,
59 printf("%-42s %-7s %s\n",locations.host, locations.tty, locations.time);
63 if ((!oneline) && (numusers > 1) && (numleft > 0))
72 char user[BUFSIZ],*whichuser;
73 ZAsyncLocateData_t ald;
74 int retval,i,numlocs,numfound,loc,auth,rlen;
86 for (i=0; i < argc; i++)
87 if (argv[i][0] == '-')
90 if (auth != -1) usage();
94 if (auth != -1) usage();
113 if (auth == -1) auth = 1;
115 if ((retval = ZInitialize()) != ZERR_NONE) {
116 com_err(whoami,retval,"while initializing");
122 rlen = strlen(ZGetRealm());
125 for (loc = 0; loc < argc; loc++) {
126 if (argv[loc][0] == '-') continue;
128 (void) strncpy(user,argv[loc],sizeof(user) - rlen - 2);
129 user[sizeof(user) - rlen - 2] = '\0';
130 if (!strchr(user,'@')) {
131 (void) strcat(user,"@");
132 (void) strcat(user,ZGetRealm());
135 if ((retval = ZRequestLocations(user, &ald, i ? UNSAFE : UNACKED,
136 auth?ZAUTH:ZNOAUTH)) != ZERR_NONE) {
137 com_err(whoami,retval,"requesting location of %s",user);
142 if ((retval = ZLocateUser(user,&numlocs,auth?ZAUTH:ZNOAUTH)) != ZERR_NONE) {
143 com_err(whoami,retval,"while locating user %s",user);
146 print_locs(user,numlocs);
152 #ifdef _POSIX_VERSION
153 sigemptyset(&sa.sa_mask);
155 sa.sa_handler = timeout;
156 sigaction(SIGALRM, &sa, (struct sigaction *)0);
158 signal (SIGALRM, timeout);
160 while (numleft-- > 0) {
162 if ((retval = ZReceiveNotice(¬ice, NULL)) != ZERR_NONE) {
163 com_err(whoami,retval,"while searching notice queue");
166 if ((retval = ZParseLocations(¬ice, (ZAsyncLocateData_t *)NULL,
167 &numlocs, &whichuser)) != ZERR_NONE) {
168 com_err(whoami,retval,"while parsing locations");
172 print_locs(whichuser,numlocs);
176 ZFreeNotice(¬ice);
179 return((numfound > 0) ? 0 : 1);