From: Stefan Metzmacher Date: Fri, 25 May 2018 14:22:33 +0000 (+0200) Subject: smbd: add [un]become_guest() helper functions X-Git-Tag: ldb-1.5.0~345 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7b5a47b84696e8e5c26207bd398742b883e598c2;p=thirdparty%2Fsamba.git smbd: add [un]become_guest() helper functions Signed-off-by: Stefan Metzmacher Reviewed-by: Ralph Boehme --- diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index ab4a8d68d3f..cbb43829fe0 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -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, diff --git a/source3/smbd/uid.c b/source3/smbd/uid.c index 9d5321cf4cc..c6c4573f9c9 100644 --- a/source3/smbd/uid.c +++ b/source3/smbd/uid.c @@ -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.