]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
[Lifecycle][ESX] Allow ALL 'admin' users to access Personality Manager APIs
authorOliver Kurth <okurth@vmware.com>
Tue, 5 Jun 2018 22:45:04 +0000 (15:45 -0700)
committerOliver Kurth <okurth@vmware.com>
Tue, 5 Jun 2018 22:45:04 +0000 (15:45 -0700)
1. During the uninstall workflow, NSX-T does not have access to 'root'
   users and uses an admin user created by them to call Personality Manager APIs

2. Added a new PAM module for "settingsd" service and removed "root"
   hardcoding.

2.1 Kept it same as "sshd" module except I removed sending VOB during
    authentication.

3. For this, updated the auth lib to add a new method Auth_AuthenticateUserPAM,i
   which takes the PAM "service-name" to use while authenticating.

4. Modified the existing method Auth_AuthenticateUser to call this API
   when USE_PAM is true.

5. This would be available only on !_WIN32

open-vm-tools/lib/auth/authPosix.c
open-vm-tools/lib/include/auth.h

index 2a19a23907591d9e9b62a7d30e03a519fc293a13..908ac3ff1c5679061b03cd8e0aab531518a83b59 100644 (file)
@@ -366,9 +366,9 @@ Auth_AuthenticateSelf(void)  // IN
 /*
  *----------------------------------------------------------------------
  *
- * Auth_AuthenticateUser --
+ * Auth_AuthenticateUserPAM --
  *
- *      Accept username/password And verfiy it
+ *      Accept username/password, and service and verfiy it with PAM
  *
  * Side effects:
  *      None.
@@ -382,17 +382,21 @@ Auth_AuthenticateSelf(void)  // IN
  */
 
 AuthToken
-Auth_AuthenticateUser(const char *user,  // IN:
-                      const char *pass)  // IN:
+Auth_AuthenticateUserPAM(const char *user,     // IN:
+                         const char *pass,     // IN:
+                         const char *service)  // IN:
 {
-#ifdef USE_PAM
+#ifndef USE_PAM
+   return NULL;
+#else
    pam_handle_t *pamh;
    int pam_error;
-#endif
 
    Bool success = FALSE;
    AuthTokenInternal *ati = NULL;
 
+   ASSERT(service);
+
    if (!CodeSet_Validate(user, strlen(user), "UTF-8")) {
       Log("User not in UTF-8\n");
       goto exit;
@@ -402,7 +406,6 @@ Auth_AuthenticateUser(const char *user,  // IN:
       goto exit;
    }
 
-#ifdef USE_PAM
    if (!AuthLoadPAM()) {
       goto exit;
    }
@@ -422,13 +425,10 @@ Auth_AuthenticateUser(const char *user,  // IN:
    PAM_username = user;
    PAM_password = pass;
 
-#if defined(VMX86_TOOLS)
-   pam_error = dlpam_start("vmtoolsd", PAM_username, &PAM_conversation,
-                           &pamh);
-#else
-   pam_error = dlpam_start("vmware-authd", PAM_username, &PAM_conversation,
+
+   pam_error = dlpam_start(service, PAM_username, &PAM_conversation,
                            &pamh);
-#endif
+
    if (pam_error != PAM_SUCCESS) {
       Log("Failed to start PAM (error = %d).\n", pam_error);
       goto exit;
@@ -442,9 +442,67 @@ Auth_AuthenticateUser(const char *user,  // IN:
    PAM_BAIL;
    dlpam_end(pamh, PAM_SUCCESS);
 
+#undef PAM_BAIL
+
    /* If this point is reached, the user has been authenticated. */
    ati = (AuthTokenInternal *) Auth_GetPwnam(user);
+   success = TRUE;
+
+exit:
+   if (success) {
+      return (AuthToken) ati;
+   } else {
+      Auth_CloseToken((AuthToken) ati);
+      return NULL;
+   }
+
+#endif // USE_PAM
+}
+
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * Auth_AuthenticateUser --
+ *
+ *      Accept username/password And verfiy it
+ *
+ * Side effects:
+ *      None.
+ *
+ * Results:
+ *
+ *      The vmauthToken for the authenticated user, or NULL if
+ *      authentication failed.
+ *
+ *----------------------------------------------------------------------
+ */
+
+AuthToken
+Auth_AuthenticateUser(const char *user,  // IN:
+                      const char *pass)  // IN:
+{
+
+#ifdef USE_PAM
+
+#if defined(VMX86_TOOLS)
+   return Auth_AuthenticateUserPAM(user, pass, "vmtoolsd");
+#else
+   return Auth_AuthenticateUserPAM(user, pass, "vmware-authd");
+#endif
+
 #else /* !USE_PAM */
+   Bool success = FALSE;
+   AuthTokenInternal *ati = NULL;
+
+   if (!CodeSet_Validate(user, strlen(user), "UTF-8")) {
+      Log("User not in UTF-8\n");
+      goto exit;
+   }
+   if (!CodeSet_Validate(pass, strlen(pass), "UTF-8")) {
+      Log("Password not in UTF-8\n");
+      goto exit;
+   }
 
    /* All of the following issues are dealt with in the PAM configuration
       file, so put all authentication/priviledge checks before the
@@ -480,17 +538,17 @@ Auth_AuthenticateUser(const char *user,  // IN:
       // Clear out crypt()'s internal state, too.
       crypt("glurp", pw);
    }
-#endif /* !USE_PAM */
 
    success = TRUE;
 
-  exit:
+exit:
    if (success) {
       return (AuthToken) ati;
    } else {
       Auth_CloseToken((AuthToken) ati);
       return NULL;
    }
+#endif /* !USE_PAM */
 }
 
 
index ce3680b8b18e77b33f2f5549fca28c5944770dba..328aa7962518d32488769492a123fe812c140d04 100644 (file)
@@ -67,6 +67,8 @@ uint32 Auth_RetrieveAccountInformationForVM(const char *filename, uint32 *attrib
 
 AuthToken Auth_GetPwnam(const char *user);
 AuthToken Auth_AuthenticateSelf(void);
+AuthToken Auth_AuthenticateUserPAM(const char *user, const char *pass,
+                                   const char *service);
 
 #endif