static void loginlist(void) { PERSON *pn; DBT data, key; struct passwd *pw; int r, seqflag; struct utmpentry *ep; for (ep = ehead; ep; ep = ep->next) { if ((pn = find_person(ep->name)) == NULL) { if ((pw = getpwnam(ep->name)) == NULL) continue; pn = enter_person(pw); } enter_where(ep, pn); } if (db && lflag) for (seqflag = R_FIRST;; seqflag = R_NEXT) { PERSON *tmp; r = (*db->seq)(db, &key, &data, seqflag); if (r == -1) err(1, "db seq"); if (r == 1) break; memmove(&tmp, data.data, sizeof tmp); enter_lastlog(tmp); } }
static void loginlist(void) { PERSON *pn; DBT data, key; struct passwd *pw; struct utmpx *user; int r, sflag1; if (kflag) errx(1, "can't list logins without reading utmp"); setutxent(); while ((user = getutxent()) != NULL) { if (user->ut_type != USER_PROCESS) continue; if ((pn = find_person(user->ut_user)) == NULL) { if ((pw = getpwnam(user->ut_user)) == NULL) continue; if (hide(pw)) continue; pn = enter_person(pw); } enter_where(user, pn); } endutxent(); if (db && lflag) for (sflag1 = R_FIRST;; sflag1 = R_NEXT) { PERSON *tmp; r = (*db->seq)(db, &key, &data, sflag1); if (r == -1) err(1, "db seq"); if (r == 1) break; memmove(&tmp, data.data, sizeof tmp); enter_lastlog(tmp); } }
static void userlist(int argc, char **argv) { PERSON *pn; DBT data, key; struct utmpx *user; struct passwd *pw; int r, sflag1, *used, *ip; char **ap, **nargv, **np, **p; FILE *conf_fp; char conf_alias[LINE_MAX]; char *conf_realname; int conf_length; if ((nargv = malloc((argc+1) * sizeof(char *))) == NULL || (used = calloc(argc, sizeof(int))) == NULL) err(1, NULL); /* Pull out all network requests. */ for (ap = p = argv, np = nargv; *p; ++p) if (index(*p, '@')) *np++ = *p; else *ap++ = *p; *np++ = NULL; *ap++ = NULL; if (!*argv) goto net; /* * Mark any arguments beginning with '/' as invalid so that we * don't accidently confuse them with expansions from finger.conf */ for (p = argv, ip = used; *p; ++p, ++ip) if (**p == '/') { *ip = 1; warnx("%s: no such user", *p); } /* * Traverse the finger alias configuration file of the form * alias:(user|alias), ignoring comment lines beginning '#'. */ if ((conf_fp = fopen(_PATH_FINGERCONF, "r")) != NULL) { while(fgets(conf_alias, sizeof(conf_alias), conf_fp) != NULL) { conf_length = strlen(conf_alias); if (*conf_alias == '#' || conf_alias[--conf_length] != '\n') continue; conf_alias[conf_length] = '\0'; /* Remove trailing LF */ if ((conf_realname = strchr(conf_alias, ':')) == NULL) continue; *conf_realname = '\0'; /* Replace : with NUL */ for (p = argv; *p; ++p) { if (strcmp(*p, conf_alias) == 0) { if ((*p = strdup(conf_realname+1)) == NULL) { err(1, NULL); } } } } (void)fclose(conf_fp); } /* * Traverse the list of possible login names and check the login name * and real name against the name specified by the user. If the name * begins with a '/', try to read the file of that name instead of * gathering the traditional finger information. */ if (mflag) for (p = argv, ip = used; *p; ++p, ++ip) { if (**p != '/' || *ip == 1 || !show_text("", *p, "")) { if (((pw = getpwnam(*p)) != NULL) && !hide(pw)) enter_person(pw); else if (!*ip) warnx("%s: no such user", *p); } } else { while ((pw = getpwent()) != NULL) { for (p = argv, ip = used; *p; ++p, ++ip) if (**p == '/' && *ip != 1 && show_text("", *p, "")) *ip = 1; else if (match(pw, *p) && !hide(pw)) { enter_person(pw); *ip = 1; } } for (p = argv, ip = used; *p; ++p, ++ip) if (!*ip) warnx("%s: no such user", *p); } /* Handle network requests. */ net: for (p = nargv; *p;) { netfinger(*p++); if (*p || entries) printf("\n"); } free(used); if (entries == 0) return; if (kflag) return; /* * Scan thru the list of users currently logged in, saving * appropriate data whenever a match occurs. */ setutxent(); while ((user = getutxent()) != NULL) { if (user->ut_type != USER_PROCESS) continue; if ((pn = find_person(user->ut_user)) == NULL) continue; enter_where(user, pn); } endutxent(); if (db) for (sflag1 = R_FIRST;; sflag1 = R_NEXT) { PERSON *tmp; r = (*db->seq)(db, &key, &data, sflag1); if (r == -1) err(1, "db seq"); if (r == 1) break; memmove(&tmp, data.data, sizeof tmp); enter_lastlog(tmp); } }
static void userlist(int argc, char **argv) { PERSON *pn; DBT data, key; struct passwd *pw; int r, seqflag, *used, *ip; char **ap, **nargv, **np, **p; struct utmpentry *ep; if ((nargv = malloc((argc+1) * sizeof(char *))) == NULL || (used = calloc(argc, sizeof(int))) == NULL) err(1, NULL); /* Pull out all network requests. */ for (ap = p = argv, np = nargv; *p; ++p) if (strchr(*p, '@')) *np++ = *p; else *ap++ = *p; *np++ = NULL; *ap++ = NULL; if (!*argv) goto net; /* * Traverse the list of possible login names and check the login name * and real name against the name specified by the user. */ if (mflag) { for (p = argv; *p; ++p) if ((pw = getpwnam(*p)) != NULL) enter_person(pw); else warnx("%s: no such user", *p); } else { while ((pw = getpwent()) != NULL) for (p = argv, ip = used; *p; ++p, ++ip) if (match(pw, *p)) { enter_person(pw); *ip = 1; } for (p = argv, ip = used; *p; ++p, ++ip) if (!*ip) warnx("%s: no such user", *p); } /* Handle network requests. */ net: for (p = nargv; *p;) netfinger(*p++); if (entries == 0) goto done; /* * Scan thru the list of users currently logged in, saving * appropriate data whenever a match occurs. */ for (ep = ehead; ep; ep = ep->next) { if ((pn = find_person(ep->name)) == NULL) continue; enter_where(ep, pn); } if (db != NULL) for (seqflag = R_FIRST;; seqflag = R_NEXT) { PERSON *tmp; r = (*db->seq)(db, &key, &data, seqflag); if (r == -1) err(1, "db seq"); if (r == 1) break; memmove(&tmp, data.data, sizeof tmp); enter_lastlog(tmp); } done: free(nargv); free(used); }