opieinfo.c revision 22347
122347Spst/* 222347Spstopieinfo: Print a user's current OPIE sequence number and seed 322347Spst 422347Spst%%% portions-copyright-cmetz 522347SpstPortions of this software are Copyright 1996 by Craig Metz, All Rights 622347SpstReserved. The Inner Net License Version 2 applies to these portions of 722347Spstthe software. 822347SpstYou should have received a copy of the license with this software. If 922347Spstyou didn't get a copy, you may request one from <license@inner.net>. 1022347Spst 1122347SpstPortions of this software are Copyright 1995 by Randall Atkinson and Dan 1222347SpstMcDonald, All Rights Reserved. All Rights under this copyright are assigned 1322347Spstto the U.S. Naval Research Laboratory (NRL). The NRL Copyright Notice and 1422347SpstLicense Agreement applies to this software. 1522347Spst 1622347Spst History: 1722347Spst 1822347Spst Modified by cmetz for OPIE 2.3. Removed unneeded debug message. 1922347Spst Modified by cmetz for OPIE 2.2. Use FUNCTION definition et al. 2022347Spst Fixed include order. Make everything static. Ifdef around 2122347Spst some headers. 2222347Spst Modified at NRL for OPIE 2.1. Substitute @@KEY_FILE@@. Re-write in 2322347Spst C. 2422347Spst Modified at NRL for OPIE 2.01. Remove hard-coded paths for grep and 2522347Spst awk and let PATH take care of it. Substitute for Makefile 2622347Spst variables $(EXISTS) and $(KEY_FILE). Only compute $WHO if 2722347Spst there's a key file. Got rid of grep since awk can do the job 2822347Spst itself. 2922347Spst Modified at NRL for OPIE 2.0. 3022347Spst Written at Bellcore for the S/Key Version 1 software distribution 3122347Spst (keyinfo) 3222347Spst*/ 3322347Spst 3422347Spst#include "opie_cfg.h" 3522347Spst#include <stdio.h> 3622347Spst#if HAVE_UNISTD_H 3722347Spst#include <unistd.h> 3822347Spst#endif /* HAVE_UNISTD_H */ 3922347Spst#if HAVE_PWD_H 4022347Spst#include <pwd.h> 4122347Spst#endif /* HAVE_PWD_H */ 4222347Spst#include "opie.h" 4322347Spst 4422347Spst/* extern char *optarg; */ 4522347Spstextern int errno, optind; 4622347Spst 4722347Spststatic char *getusername FUNCTION_NOARGS 4822347Spst{ 4922347Spst struct passwd *p = getpwuid(getuid()); 5022347Spst 5122347Spst if (!p) 5222347Spst return getlogin(); 5322347Spst 5422347Spst return p->pw_name; 5522347Spst} 5622347Spst 5722347Spstint main FUNCTION((argc, argv), int argc AND char *argv[]) 5822347Spst{ 5922347Spst char *username; 6022347Spst struct opie opie; 6122347Spst int i; 6222347Spst 6322347Spst while ((i = getopt(argc, argv, "hv")) != EOF) { 6422347Spst switch (i) { 6522347Spst case 'v': 6622347Spst opieversion(); 6722347Spst case 'h': 6822347Spst default: 6922347Spst fprintf(stderr, "usage: %s [-h] [-v] [user_name]\n", argv[0]); 7022347Spst exit(0); 7122347Spst } 7222347Spst } 7322347Spst 7422347Spst if (optind < argc) 7522347Spst username = argv[optind]; 7622347Spst else 7722347Spst username = getusername(); 7822347Spst 7922347Spst if ((i = opielookup(&opie, username)) && (i != 2)) { 8022347Spst if (i < 0) 8122347Spst fprintf(stderr, "Error opening database! (errno = %d)\n", errno); 8222347Spst else 8322347Spst fprintf(stderr, "%s not found in database.\n", username); 8422347Spst exit(1); 8522347Spst } 8622347Spst 8722347Spst printf("%d %s\n", opie.opie_n - 1, opie.opie_seed); 8822347Spst 8922347Spst return 0; 9022347Spst} 91