start using err & c:o
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@1526 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -40,8 +40,6 @@
|
|||||||
|
|
||||||
RCSID("$Id$");
|
RCSID("$Id$");
|
||||||
|
|
||||||
static char *prog;
|
|
||||||
|
|
||||||
#define USAGE_STRING \
|
#define USAGE_STRING \
|
||||||
"Usage: %s [-r] [-f alg] [-u user] num seed\n" \
|
"Usage: %s [-r] [-f alg] [-u user] num seed\n" \
|
||||||
" or -[d|l] [-u user]\n" \
|
" or -[d|l] [-u user]\n" \
|
||||||
@@ -62,14 +60,14 @@ static char *prog;
|
|||||||
static void
|
static void
|
||||||
help (void)
|
help (void)
|
||||||
{
|
{
|
||||||
fprintf(stderr, USAGE_STRING HELP_STRING, prog);
|
fprintf(stderr, USAGE_STRING HELP_STRING, __progname);
|
||||||
exit (0);
|
exit (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
usage (void)
|
usage (void)
|
||||||
{
|
{
|
||||||
fprintf(stderr, USAGE_STRING, prog);
|
fprintf(stderr, USAGE_STRING, __progname);
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,7 +107,7 @@ renew (int argc, char **argv, OtpAlgorithm *alg, char *user)
|
|||||||
|
|
||||||
dbm = otp_db_open ();
|
dbm = otp_db_open ();
|
||||||
if (dbm == NULL) {
|
if (dbm == NULL) {
|
||||||
fprintf (stderr, "%s: otp_db_open failed\n", prog);
|
warnx ("otp_db_open failed");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
otp_put (dbm, ctx);
|
otp_put (dbm, ctx);
|
||||||
@@ -130,7 +128,7 @@ verify_user_otp(char *username)
|
|||||||
char prompt[128], ss[256];
|
char prompt[128], ss[256];
|
||||||
|
|
||||||
if (otp_challenge (&ctx, username, ss, sizeof(ss)) != 0) {
|
if (otp_challenge (&ctx, username, ss, sizeof(ss)) != 0) {
|
||||||
fprintf(stderr, "%s: no otp challenge found\n", prog);
|
warnx("no otp challenge found for %s", username);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,10 +155,9 @@ set (int argc, char **argv, OtpAlgorithm *alg, char *user)
|
|||||||
|
|
||||||
ctx.alg = alg;
|
ctx.alg = alg;
|
||||||
ctx.user = strdup (user);
|
ctx.user = strdup (user);
|
||||||
if (ctx.user == NULL) {
|
if (ctx.user == NULL)
|
||||||
fprintf (stderr, "%s: Out of memory\n", prog);
|
err (1, "out of memory");
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
ctx.n = atoi (argv[0]);
|
ctx.n = atoi (argv[0]);
|
||||||
strncpy (ctx.seed, argv[1], sizeof(ctx.seed));
|
strncpy (ctx.seed, argv[1], sizeof(ctx.seed));
|
||||||
ctx.seed[sizeof(ctx.seed) - 1] = '\0';
|
ctx.seed[sizeof(ctx.seed) - 1] = '\0';
|
||||||
@@ -177,9 +174,8 @@ set (int argc, char **argv, OtpAlgorithm *alg, char *user)
|
|||||||
ctx.alg->next (ctx.key);
|
ctx.alg->next (ctx.key);
|
||||||
db = otp_db_open ();
|
db = otp_db_open ();
|
||||||
if(db == NULL) {
|
if(db == NULL) {
|
||||||
fprintf (stderr, "%s: otp_db_open failed\n", prog);
|
|
||||||
free (ctx.user);
|
free (ctx.user);
|
||||||
return 1;
|
err (1, "otp_db_open failed");
|
||||||
}
|
}
|
||||||
ret = otp_put (db, &ctx);
|
ret = otp_put (db, &ctx);
|
||||||
otp_db_close (db);
|
otp_db_close (db);
|
||||||
@@ -202,10 +198,8 @@ delete_otp (int argc, char **argv, char *user)
|
|||||||
usage();
|
usage();
|
||||||
|
|
||||||
db = otp_db_open ();
|
db = otp_db_open ();
|
||||||
if(db == NULL) {
|
if(db == NULL)
|
||||||
fprintf (stderr, "%s: otp_db_open failed\n", prog);
|
errx (1, "otp_db_open failed");
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.user = user;
|
ctx.user = user;
|
||||||
ret = otp_delete(db, &ctx);
|
ret = otp_delete(db, &ctx);
|
||||||
@@ -226,7 +220,7 @@ has_an_otp(char *user)
|
|||||||
|
|
||||||
db = otp_db_open ();
|
db = otp_db_open ();
|
||||||
if(db == NULL) {
|
if(db == NULL) {
|
||||||
fprintf (stderr, "%s: otp_db_open failed\n", prog);
|
warnx ("otp_db_open failed");
|
||||||
return 0; /* if no db no otp! */
|
return 0; /* if no db no otp! */
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,9 +262,7 @@ list_otps (int argc, char **argv, char *user)
|
|||||||
|
|
||||||
db = otp_db_open ();
|
db = otp_db_open ();
|
||||||
if(db == NULL) {
|
if(db == NULL) {
|
||||||
fprintf (stderr, "%s: otp_db_open failed\n", prog);
|
errx ("otp_db_open failed");
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (user)
|
if (user)
|
||||||
print_otp_entry_for_name(db, user);
|
print_otp_entry_for_name(db, user);
|
||||||
@@ -292,7 +284,7 @@ main (int argc, char **argv)
|
|||||||
OtpAlgorithm *alg = otp_find_alg (OTP_ALG_DEFAULT);
|
OtpAlgorithm *alg = otp_find_alg (OTP_ALG_DEFAULT);
|
||||||
char *user = NULL;
|
char *user = NULL;
|
||||||
|
|
||||||
prog = argv[0];
|
set_progname (argv[0]);
|
||||||
|
|
||||||
while ((c = getopt (argc, argv, "hrf:u:ld")) != EOF)
|
while ((c = getopt (argc, argv, "hrf:u:ld")) != EOF)
|
||||||
switch (c) {
|
switch (c) {
|
||||||
@@ -303,11 +295,8 @@ main (int argc, char **argv)
|
|||||||
listp = 1;
|
listp = 1;
|
||||||
break;
|
break;
|
||||||
case 'd' :
|
case 'd' :
|
||||||
if (uid != 0) {
|
if (uid != 0)
|
||||||
fprintf (stderr, "%s: Only root can delete OTPs\n",
|
errx (1, "Only root can delete OTPs");
|
||||||
prog);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
deletep = 1;
|
deletep = 1;
|
||||||
break;
|
break;
|
||||||
case 'r' :
|
case 'r' :
|
||||||
@@ -315,16 +304,12 @@ main (int argc, char **argv)
|
|||||||
break;
|
break;
|
||||||
case 'f' :
|
case 'f' :
|
||||||
alg = otp_find_alg (optarg);
|
alg = otp_find_alg (optarg);
|
||||||
if (alg == NULL) {
|
if (alg == NULL)
|
||||||
fprintf (stderr, "%s: Unknown algorithm: %s\n", prog, optarg);
|
errx (1, "Unknown algorithm: %s", optarg);
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 'u' :
|
case 'u' :
|
||||||
if (uid != 0) {
|
if (uid != 0)
|
||||||
fprintf (stderr, "%s: Only root can use `-u'\n", prog);
|
errx (1, "Only root can use `-u'");
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
user = optarg;
|
user = optarg;
|
||||||
break;
|
break;
|
||||||
default :
|
default :
|
||||||
@@ -347,10 +332,8 @@ main (int argc, char **argv)
|
|||||||
struct passwd *pwd;
|
struct passwd *pwd;
|
||||||
|
|
||||||
pwd = k_getpwuid(uid);
|
pwd = k_getpwuid(uid);
|
||||||
if (pwd == NULL) {
|
if (pwd == NULL)
|
||||||
fprintf (stderr, "%s: You don't exist\n", prog);
|
err (1, "You don't exist");
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
user = pwd->pw_name;
|
user = pwd->pw_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -361,12 +344,10 @@ main (int argc, char **argv)
|
|||||||
*/
|
*/
|
||||||
if (uid != 0 && (defaultp || renewp)) {
|
if (uid != 0 && (defaultp || renewp)) {
|
||||||
if (!has_an_otp(user)) {
|
if (!has_an_otp(user)) {
|
||||||
fprintf(stderr, "%s: Only root can set an initial OTP\n", prog);
|
errx (1, "Only root can set an initial OTP");
|
||||||
return 1;
|
|
||||||
} else { /* Check the next OTP (RFC 1938/8.0: SHOULD) */
|
} else { /* Check the next OTP (RFC 1938/8.0: SHOULD) */
|
||||||
if (verify_user_otp(user) != 0) {
|
if (verify_user_otp(user) != 0) {
|
||||||
fprintf(stderr, "%s: User authentification failed\n", prog);
|
errx (1, "User authentification failed");
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user