s4-auth/unix_token: add new function auth_session_info_set_unix()
authorBjörn Baumbach <bb@sernet.de>
Thu, 4 Jun 2020 13:41:34 +0000 (15:41 +0200)
committerRalph Boehme <slow@samba.org>
Fri, 5 Jun 2020 10:32:31 +0000 (10:32 +0000)
Used to fill the unix info in a struct auth_session_info similar to
auth_session_info_fill_unix().

The new auth_session_info_set_unix() receives the uid and gid for
the unix token as an parameter. It does not query the unix token from
winbind (via security_token_to_unix_token()).
This is useful to fill a user session info manually if winbind is not
available.

Bug: https://bugzilla.samba.org/show_bug.cgi?id=14400

Signed-off-by: Björn Baumbach <bb@sernet.de>
Reviewed-by: Ralph Boehme <slow@samba.org>
source4/auth/unix_token.c

index 6cd09aee954420b69ebf0049a748c69322cfa4a9..b3396b852df933c75301bcd55528fa562b7e8f4c 100644 (file)
@@ -191,3 +191,38 @@ NTSTATUS auth_session_info_fill_unix(struct loadparm_context *lp_ctx,
 
        return NT_STATUS_OK;
 }
+
+/*
+ * Set the given auth_user_info_unix and auth_unix_token elements in a
+ * struct session_info, similar auth_session_info_fill_unix().
+ * Receives the uid and gid for the unix token as parameters and does
+ * not query the unix token from winbind (via security_token_to_unix_token()).
+ * This is useful to fill a user session info manually if winbind is not
+ * available.
+ */
+NTSTATUS auth_session_info_set_unix(struct loadparm_context *lp_ctx,
+                                   const char *original_user_name,
+                                   int uid,
+                                   int gid,
+                                   struct auth_session_info *session_info)
+{
+       NTSTATUS status;
+
+       session_info->unix_token = talloc_zero(session_info,
+                                              struct security_unix_token);
+       if (session_info->unix_token == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       session_info->unix_token->uid = uid;
+       session_info->unix_token->gid = gid;
+
+       status = fill_unix_info(lp_ctx,
+                               original_user_name,
+                               session_info);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
+       return NT_STATUS_OK;
+}