smbd: add [un]become_guest() helper functions
authorStefan Metzmacher <metze@samba.org>
Fri, 25 May 2018 14:22:33 +0000 (16:22 +0200)
committerStefan Metzmacher <metze@samba.org>
Thu, 12 Jul 2018 12:25:17 +0000 (14:25 +0200)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/smbd/proto.h
source3/smbd/uid.c

index ab4a8d68d3f1e7122f8a5959160d1ac4419c54c5..cbb43829fe083e278205b5b98831dd0cb7a74cfd 100644 (file)
@@ -1203,6 +1203,8 @@ void become_root(void);
 void unbecome_root(void);
 void smbd_become_root(void);
 void smbd_unbecome_root(void);
+bool become_guest(void);
+void unbecome_guest(void);
 bool become_user(connection_struct *conn, uint64_t vuid);
 bool become_user_by_fsp(struct files_struct *fsp);
 bool become_user_by_session(connection_struct *conn,
index 9d5321cf4ccc7772f81158a3356e6a8c0bd7c41d..c6c4573f9c9be0c04ef45beadc2404157e9380bf 100644 (file)
@@ -598,6 +598,34 @@ void smbd_unbecome_root(void)
        pop_conn_ctx();
 }
 
+bool become_guest(void)
+{
+       bool ok;
+
+       ok = push_sec_ctx();
+       if (!ok) {
+               return false;
+       }
+
+       push_conn_ctx();
+
+       ok = change_to_guest();
+       if (!ok) {
+               pop_sec_ctx();
+               pop_conn_ctx();
+               return false;
+       }
+
+       return true;
+}
+
+void unbecome_guest(void)
+{
+       pop_sec_ctx();
+       pop_conn_ctx();
+       return;
+}
+
 /****************************************************************************
  Push the current security context then force a change via change_to_user().
  Saves and restores the connection context.