]> granicus.if.org Git - sudo/commitdiff
kill perror("malloc") since we already have a good error messages
authorTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 4 Nov 1998 01:39:18 +0000 (01:39 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 4 Nov 1998 01:39:18 +0000 (01:39 +0000)
pw_ent -> pw for brevity

check.c
getspwuid.c
interfaces.c

diff --git a/check.c b/check.c
index c01b2c3dc7ddc03b041a8e03126553be069815ca..fbf953113861d26f669b7ab642b63da6b5fa248d 100644 (file)
--- a/check.c
+++ b/check.c
@@ -645,8 +645,8 @@ static void check_passwd()
  *
  *  Validate a user via kerberos.
  */
-static int sudo_krb_validate_user(pw_ent, pass)
-    struct passwd *pw_ent;
+static int sudo_krb_validate_user(pw, pass)
+    struct passwd *pw;
     char *pass;
 {
     char realm[REALM_SZ];
@@ -662,7 +662,7 @@ static int sudo_krb_validate_user(pw_ent, pass)
      * wipe out other kerberos tickets.
      */
     (void) sprintf(tkfile, "%s/tkt%ld", _PATH_SUDO_TIMEDIR,
-                  (long) pw_ent->pw_uid);
+                  (long) pw->pw_uid);
     (void) krb_set_tkt_string(tkfile);
 
     /*
@@ -670,7 +670,7 @@ static int sudo_krb_validate_user(pw_ent, pass)
      * the ruid and euid to be the same here so we setuid to root.
      */
     set_perms(PERM_ROOT, 0);
-    k_errno = krb_get_pw_in_tkt(pw_ent->pw_name, "", realm, "krbtgt", realm,
+    k_errno = krb_get_pw_in_tkt(pw->pw_name, "", realm, "krbtgt", realm,
        DEFAULT_TKT_LIFE, pass);
 
     /*
@@ -788,7 +788,6 @@ static char *sudo_skeyprompt(user_skey, p)
        /* allocate space for new prompt */
        np_size = op_len + strlen(challenge) + 7;
        if (!(new_prompt = (char *) malloc(np_size))) {
-           perror("malloc");
            (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
            exit(1);
        }
@@ -797,7 +796,6 @@ static char *sudo_skeyprompt(user_skey, p)
        if (np_size < op_len + strlen(challenge) + 7) {
            np_size = op_len + strlen(challenge) + 7;
            if (!(new_prompt = (char *) realloc(new_prompt, np_size))) {
-               perror("malloc");
                (void) fprintf(stderr, "%s: cannot allocate memory!\n",
                               Argv[0]);
                exit(1);
@@ -863,7 +861,6 @@ static char *sudo_opieprompt(user_opie, p)
        /* allocate space for new prompt */
        np_size = op_len + strlen(challenge) + 7;
        if (!(new_prompt = (char *) malloc(np_size))) {
-           perror("malloc");
            (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
            exit(1);
        }
@@ -872,7 +869,6 @@ static char *sudo_opieprompt(user_opie, p)
        if (np_size < op_len + strlen(challenge) + 7) {
            np_size = op_len + strlen(challenge) + 7;
            if (!(new_prompt = (char *) realloc(new_prompt, np_size))) {
-               perror("malloc");
                (void) fprintf(stderr, "%s: cannot allocate memory!\n",
                               Argv[0]);
                exit(1);
@@ -977,7 +973,6 @@ static char *expand_prompt(old_prompt, user, host)
 
     if (subst) {
        if ((new_prompt = (char *) malloc(len + 1)) == NULL) {
-           perror("malloc");
            (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
            exit(1);
        }
index f60d5747cace4b87d6aa7a918399d0ca533e5ff4..59dbff773c034d1464ab9fbc81bc0fe1dc1e1e89 100644 (file)
@@ -107,13 +107,13 @@ static char *sudo_getepw  __P((struct passwd *));
  *  SHELL evariable or the passwd(5) entry (in that order).
  */
 
-static char *sudo_getshell(pw_ent)
-    struct passwd *pw_ent;
+static char *sudo_getshell(pw)
+    struct passwd *pw;
 {
     char *pw_shell;
 
     if ((pw_shell = getenv("SHELL")) == NULL)
-       pw_shell = pw_ent -> pw_shell;
+       pw_shell = pw -> pw_shell;
 
 #ifdef _PATH_BSHELL
     /* empty string "" means bourne shell */
@@ -130,72 +130,72 @@ static char *sudo_getshell(pw_ent)
  *  sudo_getepw()
  *
  *  This function returns the encrypted password for the user described
- *  by pw_ent.  If there is a shadow password it is returned, else the
+ *  by pw.  If there is a shadow password it is returned, else the
  *  normal UN*X password is returned instead.
  */
 
-static char *sudo_getepw(pw_ent)
-    struct passwd *pw_ent;
+static char *sudo_getepw(pw)
+    struct passwd *pw;
 {
 
     /* if there is a function to check for shadow enabled, use it... */
 #ifdef HAVE_ISCOMSEC
     if (!iscomsec())
-       return(pw_ent->pw_passwd);
+       return(pw->pw_passwd);
 #endif /* HAVE_ISCOMSEC */
 #ifdef HAVE_ISSECURE
     if (!issecure())
-       return(pw_ent->pw_passwd);
+       return(pw->pw_passwd);
 #endif /* HAVE_ISSECURE */
 
 #ifdef HAVE_GETPRPWNAM
     {
-       struct pr_passwd *spw_ent;
+       struct pr_passwd *spw;
 
-       spw_ent = getprpwnam(pw_ent->pw_name);
-       if (spw_ent != NULL && spw_ent->ufld.fd_encrypt != NULL) {
+       spw = getprpwnam(spw->pw_name);
+       if (spw != NULL && spw->ufld.fd_encrypt != NULL) {
 #  ifdef __alpha
-           crypt_type = spw_ent -> ufld.fd_oldcrypt;
+           crypt_type = spw -> ufld.fd_oldcrypt;
 #  endif /* __alpha */
-           return(spw_ent -> ufld.fd_encrypt);
+           return(spw -> ufld.fd_encrypt);
        }
     }
 #endif /* HAVE_GETPRPWNAM */
 #ifdef HAVE_GETSPNAM
     {
-       struct spwd *spw_ent;
+       struct spwd *spw;
 
-       if ((spw_ent = getspnam(pw_ent -> pw_name)) && spw_ent -> sp_pwdp)
-           return(spw_ent -> sp_pwdp);
+       if ((spw = getspnam(pw -> pw_name)) && spw -> sp_pwdp)
+           return(spw -> sp_pwdp);
     }
 #endif /* HAVE_GETSPNAM */
 #ifdef HAVE_GETSPWUID
     {
-       struct s_passwd *spw_ent;
+       struct s_passwd *spw;
 
-       if ((spw_ent = getspwuid(pw_ent -> pw_uid)) && spw_ent -> pw_passwd)
-           return(spw_ent -> pw_passwd);
+       if ((spw = getspwuid(pw -> pw_uid)) && spw -> pw_passwd)
+           return(spw -> pw_passwd);
     }
 #endif /* HAVE_GETSPWUID */
 #ifdef HAVE_GETPWANAM
     {
-       struct passwd_adjunct *spw_ent;
+       struct passwd_adjunct *spw;
 
-       if ((spw_ent = getpwanam(pw_ent -> pw_name)) && spw_ent -> pwa_passwd)
-           return(spw_ent -> pwa_passwd);
+       if ((spw = getpwanam(pw -> pw_name)) && spw -> pwa_passwd)
+           return(spw -> pwa_passwd);
     }
 #endif /* HAVE_GETPWANAM */
 #ifdef HAVE_GETAUTHUID
     {
-       AUTHORIZATION *spw_ent;
+       AUTHORIZATION *spw;
 
-       if ((spw_ent = getauthuid(pw_ent -> pw_uid)) && spw_ent -> a_password)
-           return(spw_ent -> a_password);
+       if ((spw = getauthuid(pw -> pw_uid)) && spw -> a_password)
+           return(spw -> a_password);
     }
 #endif /* HAVE_GETAUTHUID */
 
     /* Fall back on normal passwd */
-    return(pw_ent->pw_passwd);
+    return(pw->pw_passwd);
 }
 
 
@@ -211,15 +211,14 @@ static char *sudo_getepw(pw_ent)
 struct passwd *sudo_getpwuid(uid)
     uid_t uid;
 {
-    struct passwd *pw_ent, *local_pw_ent;
+    struct passwd *pw, *local_pw;
 
-    if ((pw_ent = getpwuid(uid)) == NULL)
+    if ((pw = getpwuid(uid)) == NULL)
        return(NULL);
 
-    /* allocate space for a local copy of pw_ent */
-    local_pw_ent = (struct passwd *) malloc(sizeof(struct passwd));
-    if (local_pw_ent == NULL) {
-       perror("malloc");
+    /* allocate space for a local copy of pw */
+    local_pw = (struct passwd *) malloc(sizeof(struct passwd));
+    if (local_pw == NULL) {
        (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
        exit(1);
     }
@@ -227,37 +226,33 @@ struct passwd *sudo_getpwuid(uid)
     /*
      * Copy the struct passwd and the interesting strings...
      */
-    (void) memcpy(local_pw_ent, pw_ent, sizeof(struct passwd));
+    (void) memcpy(local_pw, pw, sizeof(struct passwd));
 
-    local_pw_ent->pw_name = (char *) strdup(pw_ent->pw_name);
-    if (local_pw_ent->pw_name == NULL) {
-       perror("malloc");
+    local_pw->pw_name = (char *) strdup(pw->pw_name);
+    if (local_pw->pw_name == NULL) {
        (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
        exit(1);
     }
 
-    local_pw_ent->pw_dir = (char *) strdup(pw_ent->pw_dir);
-    if (local_pw_ent->pw_dir == NULL) {
-       perror("malloc");
+    local_pw->pw_dir = (char *) strdup(pw->pw_dir);
+    if (local_pw->pw_dir == NULL) {
        (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
        exit(1);
     }
 
     /* pw_shell is a special case since we overide with $SHELL */
-    local_pw_ent->pw_shell = (char *) strdup(sudo_getshell(pw_ent));
-    if (local_pw_ent->pw_shell == NULL) {
-       perror("malloc");
+    local_pw->pw_shell = (char *) strdup(sudo_getshell(pw));
+    if (local_pw->pw_shell == NULL) {
        (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
        exit(1);
     }
 
     /* pw_passwd gets a shadow password if applicable */
-    local_pw_ent->pw_passwd = (char *) strdup(sudo_getepw(pw_ent));
-    if (local_pw_ent->pw_passwd == NULL) {
-       perror("malloc");
+    local_pw->pw_passwd = (char *) strdup(sudo_getepw(pw));
+    if (local_pw->pw_passwd == NULL) {
        (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
        exit(1);
     }
 
-    return(local_pw_ent);
+    return(local_pw);
 }
index d09883d53fc6d869c33b94966fdab3ee868388e2..ecaf7953d10b483801526afc7dab252e9394d69c 100644 (file)
@@ -125,7 +125,7 @@ void load_interfaces()
     for (;;) {
        ifconf_buf = ifconf_buf ? realloc(ifconf_buf, len) : malloc(len);
        if (ifconf_buf == NULL) {
-           perror("malloc");
+           (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
            exit(1);
        }
        ifconf = (struct ifconf *) ifconf_buf;
@@ -159,7 +159,6 @@ void load_interfaces()
      */
     interfaces = (struct interface *) malloc(sizeof(struct interface) * n);
     if (interfaces == NULL) {
-       perror("malloc");
        (void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
        exit(1);
     }