]> andersk Git - nss_nonlocal.git/blobdiff - nonlocal-passwd.c
Fix errno saving and restoring
[nss_nonlocal.git] / nonlocal-passwd.c
index 474db13d93d77ff76fc52c50a6695e52b522ca73..bd9d9ad206e0b700b334fa2ca606c7e9ba9a5445 100644 (file)
@@ -78,9 +78,9 @@ check_nonlocal_uid(const char *user, uid_t uid, int *errnop)
 
     size_t buflen = sysconf(_SC_GETPW_R_SIZE_MAX);
     char *buf = malloc(buflen);
+    errno = old_errno;
     if (buf == NULL) {
        *errnop = ENOMEM;
-       errno = old_errno;
        return NSS_STATUS_TRYAGAIN;
     }
 
@@ -101,9 +101,9 @@ check_nonlocal_uid(const char *user, uid_t uid, int *errnop)
            free(buf);
            buflen *= 2;
            buf = malloc(buflen);
+           errno = old_errno;
            if (buf == NULL) {
                *errnop = ENOMEM;
-               errno = old_errno;
                return NSS_STATUS_TRYAGAIN;
            }
            goto morebuf;
@@ -131,9 +131,12 @@ check_nonlocal_passwd(const char *user, struct passwd *pwd, int *errnop)
 
     errno = 0;
     uid = strtoul(pwd->pw_name, &end, 10);
-    if (errno == 0 && *end == '\0' && (uid_t)uid == uid)
+    if (errno == 0 && *end == '\0' && (uid_t)uid == uid) {
+       errno = old_errno;
        status = check_nonlocal_uid(user, uid, errnop);
-    errno = old_errno;
+    } else {
+       errno = old_errno;
+    }
     if (status != NSS_STATUS_SUCCESS)
        return status;
 
@@ -158,9 +161,9 @@ check_nonlocal_user(const char *user, int *errnop)
 
     size_t buflen = sysconf(_SC_GETPW_R_SIZE_MAX);
     char *buf = malloc(buflen);
+    errno = old_errno;
     if (buf == NULL) {
        *errnop = ENOMEM;
-       errno = old_errno;
        return NSS_STATUS_TRYAGAIN;
     }
 
@@ -181,9 +184,9 @@ check_nonlocal_user(const char *user, int *errnop)
            free(buf);
            buflen *= 2;
            buf = malloc(buflen);
+           errno = old_errno;
            if (buf == NULL) {
                *errnop = ENOMEM;
-               errno = old_errno;
                return NSS_STATUS_TRYAGAIN;
            }
            goto morebuf;
This page took 0.079913 seconds and 4 git commands to generate.