=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/rusers/rusers.c,v retrieving revision 1.10 retrieving revision 1.11 diff -c -r1.10 -r1.11 *** src/usr.bin/rusers/rusers.c 2001/02/05 21:41:07 1.10 --- src/usr.bin/rusers/rusers.c 2001/02/17 16:52:23 1.11 *************** *** 1,4 **** ! /* $OpenBSD: rusers.c,v 1.10 2001/02/05 21:41:07 deraadt Exp $ */ /*- * Copyright (c) 1993 John Brezak --- 1,4 ---- ! /* $OpenBSD: rusers.c,v 1.11 2001/02/17 16:52:23 pjanzen Exp $ */ /*- * Copyright (c) 1993 John Brezak *************** *** 29,41 **** */ #ifndef lint ! static char rcsid[] = "$OpenBSD: rusers.c,v 1.10 2001/02/05 21:41:07 deraadt Exp $"; #endif /* not lint */ #include #include #include #include #include #include #include --- 29,42 ---- */ #ifndef lint ! static char rcsid[] = "$OpenBSD: rusers.c,v 1.11 2001/02/17 16:52:23 pjanzen Exp $"; #endif /* not lint */ #include #include #include #include + #include #include #include #include *************** *** 52,60 **** #include /* Old version */ #define MAX_INT 0x7fffffff #define HOST_WIDTH 20 #define LINE_WIDTH 8 ! char *argv0; struct timeval timeout = { 25, 0 }; int longopt; --- 53,62 ---- #include /* Old version */ #define MAX_INT 0x7fffffff + /* Preferred formatting */ #define HOST_WIDTH 20 #define LINE_WIDTH 8 ! #define NAME_WIDTH 8 struct timeval timeout = { 25, 0 }; int longopt; *************** *** 65,70 **** --- 67,74 ---- struct in_addr addr; } *hosts; + extern char *__progname; + int search_host(struct in_addr addr) { *************** *** 85,94 **** { struct host_list *hp; ! if (!(hp = (struct host_list *)malloc(sizeof(struct host_list)))) { ! fprintf(stderr, "%s: no memory.\n", argv0); ! exit(1); ! } hp->addr.s_addr = addr.s_addr; hp->next = hosts; hosts = hp; --- 89,96 ---- { struct host_list *hp; ! if (!(hp = (struct host_list *)malloc(sizeof(struct host_list)))) ! err(1, NULL); hp->addr.s_addr = addr.s_addr; hp->next = hosts; hosts = hp; *************** *** 97,107 **** int rusers_reply(char *replyp, struct sockaddr_in *raddrp) { ! int x, idle; ! char date[32], idle_time[64], remote[64], local[64]; struct hostent *hp; utmpidlearr *up = (utmpidlearr *)replyp; ! char *host; int days, hours, minutes, seconds; if (search_host(raddrp->sin_addr)) --- 99,111 ---- int rusers_reply(char *replyp, struct sockaddr_in *raddrp) { ! int x, idle, i; ! char date[32], idle_time[64], remote[UT_HOSTSIZE + 1]; ! char local[HOST_WIDTH + LINE_WIDTH + 2]; ! char utline[UT_LINESIZE + 1]; struct hostent *hp; utmpidlearr *up = (utmpidlearr *)replyp; ! char *host, *tmp; int days, hours, minutes, seconds; if (search_host(raddrp->sin_addr)) *************** *** 121,129 **** printf("%-*.*s ", HOST_WIDTH, HOST_WIDTH, host); for (x = 0; x < up->uia_cnt; x++) { ! strncpy(date, &(ctime((time_t *)&(up->uia_arr[x]->ui_utmp.ut_time))[4]), ! sizeof(date)-1); idle = up->uia_arr[x]->ui_idle; sprintf(idle_time, " :%02d", idle); --- 125,138 ---- printf("%-*.*s ", HOST_WIDTH, HOST_WIDTH, host); for (x = 0; x < up->uia_cnt; x++) { ! strlcpy(date, &(ctime((time_t *)&(up->uia_arr[x]->ui_utmp.ut_time))[4]), ! sizeof(date)); ! /* ctime() adds a trailing \n. Trimming it is only ! * mandatory if the output formatting changes. ! */ ! if ((tmp = strchr(date, '\n')) != NULL) ! *tmp = '\0'; idle = up->uia_arr[x]->ui_idle; sprintf(idle_time, " :%02d", idle); *************** *** 152,173 **** strncpy(remote, up->uia_arr[x]->ui_utmp.ut_host, sizeof(remote)-1); if (strlen(remote) != 0) ! sprintf(remote, "(%.16s)", up->uia_arr[x]->ui_utmp.ut_host); if (longopt) { strncpy(local, host, sizeof(local)); ! local[HOST_WIDTH + LINE_WIDTH + 1 - ! strlen(up->uia_arr[x]->ui_utmp.ut_line) - 1] = 0; strcat(local, ":"); ! strncat(local, up->uia_arr[x]->ui_utmp.ut_line, ! sizeof (local) - strlen (local) - 1); ! local[sizeof (local) - 1] = 0; - #define MAXNAME 8 printf("%-*.*s %-*.*s %-12.12s %8s %.18s\n", ! MAXNAME, UT_NAMESIZE, up->uia_arr[x]->ui_utmp.ut_name, HOST_WIDTH+LINE_WIDTH+1, HOST_WIDTH+LINE_WIDTH+1, local, date, idle_time, remote); --- 161,185 ---- strncpy(remote, up->uia_arr[x]->ui_utmp.ut_host, sizeof(remote)-1); + remote[sizeof(remote) - 1] = '\0'; if (strlen(remote) != 0) ! snprintf(remote, UT_HOSTSIZE + 1, "(%.16s)", up->uia_arr[x]->ui_utmp.ut_host); if (longopt) { strncpy(local, host, sizeof(local)); ! strncpy(utline, up->uia_arr[x]->ui_utmp.ut_line, ! UT_LINESIZE); ! utline[sizeof(utline) - 1] = '\0'; ! i = sizeof(local) - strlen(utline) - 2; ! if (i < 0) ! i = 0; ! local[i] = '\0'; strcat(local, ":"); ! strlcat(local, utline, sizeof(local)); printf("%-*.*s %-*.*s %-12.12s %8s %.18s\n", ! NAME_WIDTH, UT_NAMESIZE, up->uia_arr[x]->ui_utmp.ut_name, HOST_WIDTH+LINE_WIDTH+1, HOST_WIDTH+LINE_WIDTH+1, local, date, idle_time, remote); *************** *** 191,212 **** struct hostent *hp; hp = gethostbyname(host); ! if (hp == NULL) { ! fprintf(stderr, "%s: unknown host \"%s\"\n", ! argv0, host); ! exit(1); ! } rusers_clnt = clnt_create(host, RUSERSPROG, RUSERSVERS_IDLE, "udp"); if (rusers_clnt == NULL) { ! clnt_pcreateerror(argv0); exit(1); } bzero((char *)&up, sizeof(up)); if (clnt_call(rusers_clnt, RUSERSPROC_NAMES, xdr_void, NULL, xdr_utmpidlearr, &up, timeout) != RPC_SUCCESS) { ! clnt_perror(rusers_clnt, argv0); exit(1); } addr.sin_addr.s_addr = *(int *)hp->h_addr; --- 203,221 ---- struct hostent *hp; hp = gethostbyname(host); ! if (hp == NULL) ! errx(1, "unknown host \"%s\"", host); rusers_clnt = clnt_create(host, RUSERSPROG, RUSERSVERS_IDLE, "udp"); if (rusers_clnt == NULL) { ! clnt_pcreateerror(__progname); exit(1); } bzero((char *)&up, sizeof(up)); if (clnt_call(rusers_clnt, RUSERSPROC_NAMES, xdr_void, NULL, xdr_utmpidlearr, &up, timeout) != RPC_SUCCESS) { ! clnt_perror(rusers_clnt, __progname); exit(1); } addr.sin_addr.s_addr = *(int *)hp->h_addr; *************** *** 223,238 **** clnt_stat = clnt_broadcast(RUSERSPROG, RUSERSVERS_IDLE, RUSERSPROC_NAMES, xdr_void, NULL, xdr_utmpidlearr, (char *)&up, rusers_reply); ! if (clnt_stat != RPC_SUCCESS && clnt_stat != RPC_TIMEDOUT) { ! fprintf(stderr, "%s: %s\n", argv0, clnt_sperrno(clnt_stat)); ! exit(1); ! } } void usage(void) { ! fprintf(stderr, "Usage: %s [-la] [hosts ...]\n", argv0); exit(1); } --- 232,245 ---- clnt_stat = clnt_broadcast(RUSERSPROG, RUSERSVERS_IDLE, RUSERSPROC_NAMES, xdr_void, NULL, xdr_utmpidlearr, (char *)&up, rusers_reply); ! if (clnt_stat != RPC_SUCCESS && clnt_stat != RPC_TIMEDOUT) ! errx(1, "%s", clnt_sperrno(clnt_stat)); } void usage(void) { ! fprintf(stderr, "Usage: %s [-la] [hosts ...]\n", __progname); exit(1); } *************** *** 242,252 **** int ch; extern int optind; - if (!(argv0 = strrchr(argv[0], '/'))) - argv0 = argv[0]; - else - argv0++; - while ((ch = getopt(argc, argv, "al")) != -1) switch (ch) { case 'a': --- 249,254 ----