X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;f=sbr%2Fruserpass.c;h=882889c374854a387c1d3f68859dcfea22514842;hb=5dd6771b28c257af405d7248639ed0e3bcdce38b;hp=68809df411db399dc166bd3e069ad31ef3cff094;hpb=1691e80890e5d8ba258c51c214a3e91880e1db2b;p=mmh diff --git a/sbr/ruserpass.c b/sbr/ruserpass.c index 68809df..882889c 100644 --- a/sbr/ruserpass.c +++ b/sbr/ruserpass.c @@ -1,4 +1,5 @@ /* + * Portions of this code are * Copyright (c) 1985 Regents of the University of California. * All rights reserved. * @@ -13,11 +14,10 @@ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * - * $Id$ */ #include +#include #include #include @@ -59,13 +59,12 @@ static struct toktab toktabs[] = { static int token(void); -int +void ruserpass(char *host, char **aname, char **apass) { char *hdir, buf[BUFSIZ]; int t, usedefault = 0; struct stat stb; - extern int errno; hdir = getenv("HOME"); if (hdir == NULL) @@ -91,7 +90,7 @@ ruserpass(char *host, char **aname, char **apass) /* * Allow match either for user's host name. */ - if (strcasecmp(host, tokval) == 0) + if (mh_strcasecmp(host, tokval) == 0) goto match; continue; } @@ -100,19 +99,19 @@ match: switch(t) { case LOGIN: if (token() && *aname == 0) { - *aname = malloc((size_t) strlen(tokval) + 1); + *aname = mh_xmalloc((size_t) strlen(tokval) + 1); strcpy(*aname, tokval); } break; case PASSWD: if (fstat(fileno(cfile), &stb) >= 0 && (stb.st_mode & 077) != 0) { - fprintf(stderr, "Error - .netrc file not correct mode.\n"); - fprintf(stderr, "Remove password or correct mode.\n"); - goto bad; + /* We make this a fatal error to force the user to correct it */ + advise(NULL, "Error - ~/.netrc file must not be world or group readable."); + adios(NULL, "Remove password or correct file permissions."); } if (token() && *apass == 0) { - *apass = malloc((size_t) strlen(tokval) + 1); + *apass = mh_xmalloc((size_t) strlen(tokval) + 1); strcpy(*apass, tokval); } break; @@ -153,7 +152,7 @@ done: myname = tmp; } - *aname = malloc((size_t) strlen(myname) + 1); + *aname = mh_xmalloc((size_t) strlen(myname) + 1); strcpy (*aname, myname); } @@ -162,20 +161,16 @@ done: char *mypass; snprintf(prompt, sizeof(prompt), "Password (%s:%s): ", host, *aname); - mypass = getpass (prompt); + mypass = nmh_getpass(prompt); if (*mypass == '\0') { mypass = *aname; } - *apass = malloc((size_t) strlen(mypass) + 1); + *apass = mh_xmalloc((size_t) strlen(mypass) + 1); strcpy (*apass, mypass); } - return(0); -bad: - fclose(cfile); - return(-1); } static int