s3-privs Convert from user_has_privileges() -> security_token_has_privilege()
authorAndrew Bartlett <abartlet@samba.org>
Mon, 30 Aug 2010 03:04:27 +0000 (13:04 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 9 Sep 2010 04:46:00 +0000 (14:46 +1000)
This new call is available in the merged privileges code, and
takes an enum as the parameter, rather than a bitmask.

Andrew Bartlett

Signed-off-by: Andrew Tridgell <tridge@samba.org>
source3/lib/util_seaccess.c
source3/printing/nt_printing.c
source3/registry/reg_backend_smbconf.c
source3/rpc_server/srv_samr_nt.c
source3/rpc_server/srv_spoolss_nt.c
source3/rpc_server/srv_srvsvc_nt.c
source3/rpc_server/srv_winreg_nt.c
source3/rpc_server/srv_wkssvc_nt.c
source3/smbd/posix_acls.c

index 3bedec686550596a1ace9f9d8b06d002a4cd29cf..7e803fcfce681b7eee648d927fda0e2e63a9e799 100644 (file)
@@ -113,7 +113,7 @@ static uint32_t access_check_max_allowed(const struct security_descriptor *sd,
 
        if (is_sid_in_token(token, sd->owner_sid)) {
                granted |= SEC_STD_WRITE_DAC | SEC_STD_READ_CONTROL | SEC_STD_DELETE;
-       } else if (user_has_privileges(token, &se_restore)) {
+       } else if (security_token_has_privilege(token, SEC_PRIV_RESTORE)) {
                granted |= SEC_STD_DELETE;
        }
 
@@ -203,7 +203,7 @@ NTSTATUS se_access_check(const struct security_descriptor *sd,
                bits_remaining &= ~(SEC_STD_WRITE_DAC|SEC_STD_READ_CONTROL|SEC_STD_DELETE);
        }
        if ((bits_remaining & SEC_STD_DELETE) &&
-           user_has_privileges(token, &se_restore)) {
+           (security_token_has_privilege(token, SEC_PRIV_RESTORE))) {
                bits_remaining &= ~SEC_STD_DELETE;
        }
 
index bba85ba4f38cb2f9fe7658aab82c914ec88eaa69..52b663c2024b17d301aac8efc460a641112d16cc 100644 (file)
@@ -2075,14 +2075,13 @@ bool print_access_check(struct auth_serversupplied_info *server_info,
        WERROR result;
        const char *pname;
        TALLOC_CTX *mem_ctx = NULL;
-       uint64_t se_printop = SE_PRINT_OPERATOR;
 
        /* If user is NULL then use the current_user structure */
 
        /* Always allow root or SE_PRINT_OPERATROR to do anything */
 
        if (server_info->utok.uid == sec_initial_uid()
-           || user_has_privileges(server_info->ptok, &se_printop ) ) {
+           || security_token_has_privilege(server_info->ptok, SEC_PRIV_PRINT_OPERATOR)) {
                return True;
        }
 
index a2bf506e52ba0b47025e20fe9ca67ed03f820ec5..b96c73b47b96130599379938880a46468a813ce8 100644 (file)
@@ -60,7 +60,7 @@ static bool smbconf_reg_access_check(const char *keyname, uint32 requested,
                                     uint32 *granted,
                                     const struct security_token *token)
 {
-       if (!(user_has_privileges(token, &se_disk_operators))) {
+       if (!security_token_has_privilege(token, SEC_PRIV_DISK_OPERATOR)) {
                return False;
        }
 
index 7755b3b7c33a40d1aeedfadf34225abfc8623b62..8e8911005c4dfc8e4c5705359355c475db39a632 100644 (file)
@@ -574,7 +574,7 @@ NTSTATUS _samr_OpenDomain(struct pipes_struct *p,
         * Users with SeAddUser get the ability to manipulate groups
         * and aliases.
         */
-       if (user_has_any_privilege(p->server_info->ptok, &se_add_users)) {
+       if (security_token_has_privilege(p->server_info->ptok, SEC_PRIV_ADD_USERS)) {
                extra_access |= (SAMR_DOMAIN_ACCESS_CREATE_GROUP |
                                SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS |
                                SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT |
index b537e218e529ae8b4cf72b923b85c9523031dac6..40aa07d8abcd655a3e3da103bcaec16939f33806 100644 (file)
@@ -301,7 +301,6 @@ static WERROR delete_printer_hook(TALLOC_CTX *ctx, struct security_token *token,
        char *cmd = lp_deleteprinter_cmd();
        char *command = NULL;
        int ret;
-       uint64_t se_printop = SE_PRINT_OPERATOR;
        bool is_print_op = false;
 
        /* can't fail if we don't try */
@@ -316,7 +315,7 @@ static WERROR delete_printer_hook(TALLOC_CTX *ctx, struct security_token *token,
                return WERR_NOMEM;
        }
        if ( token )
-               is_print_op = user_has_privileges( token, &se_printop );
+               is_print_op = security_token_has_privilege(token, SEC_PRIV_PRINT_OPERATOR);
 
        DEBUG(10,("Running [%s]\n", command));
 
@@ -1628,8 +1627,6 @@ WERROR _spoolss_OpenPrinterEx(struct pipes_struct *p,
 
                if ( r->in.access_mask & SERVER_ACCESS_ADMINISTER )
                {
-                       uint64_t se_printop = SE_PRINT_OPERATOR;
-
                        if (!lp_ms_add_printer_wizard()) {
                                close_printer_handle(p, r->out.handle);
                                ZERO_STRUCTP(r->out.handle);
@@ -1640,8 +1637,7 @@ WERROR _spoolss_OpenPrinterEx(struct pipes_struct *p,
                           and not a printer admin, then fail */
 
                        if ((p->server_info->utok.uid != sec_initial_uid()) &&
-                           !user_has_privileges(p->server_info->ptok,
-                                                &se_printop ) &&
+                           !security_token_has_privilege(p->server_info->ptok, SEC_PRIV_PRINT_OPERATOR) &&
                            !token_contains_name_in_list(
                                    uidtoname(p->server_info->utok.uid),
                                    p->server_info->info3->base.domain.string,
@@ -1878,13 +1874,12 @@ WERROR _spoolss_DeletePrinterDriver(struct pipes_struct *p,
        struct spoolss_DriverInfo8 *info_win2k = NULL;
        int                             version;
        WERROR                          status;
-       uint64_t                         se_printop = SE_PRINT_OPERATOR;
 
        /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
           and not a printer admin, then fail */
 
        if ( (p->server_info->utok.uid != sec_initial_uid())
-               && !user_has_privileges(p->server_info->ptok, &se_printop )
+            && !security_token_has_privilege(p->server_info->ptok, SEC_PRIV_PRINT_OPERATOR)
                && !token_contains_name_in_list(
                        uidtoname(p->server_info->utok.uid),
                        p->server_info->info3->base.domain.string,
@@ -1976,13 +1971,12 @@ WERROR _spoolss_DeletePrinterDriverEx(struct pipes_struct *p,
        int                             version;
        bool                            delete_files;
        WERROR                          status;
-       uint64_t                         se_printop = SE_PRINT_OPERATOR;
 
        /* if the user is not root, doesn't have SE_PRINT_OPERATOR privilege,
           and not a printer admin, then fail */
 
        if ( (p->server_info->utok.uid != sec_initial_uid())
-               && !user_has_privileges(p->server_info->ptok, &se_printop )
+               && !security_token_has_privilege(p->server_info->ptok, SEC_PRIV_PRINT_OPERATOR)
                && !token_contains_name_in_list(
                        uidtoname(p->server_info->utok.uid),
                        p->server_info->info3->base.domain.string,
@@ -5680,7 +5674,6 @@ static WERROR add_port_hook(TALLOC_CTX *ctx, struct security_token *token, const
        char *cmd = lp_addport_cmd();
        char *command = NULL;
        int ret;
-       uint64_t se_printop = SE_PRINT_OPERATOR;
        bool is_print_op = false;
 
        if ( !*cmd ) {
@@ -5694,7 +5687,7 @@ static WERROR add_port_hook(TALLOC_CTX *ctx, struct security_token *token, const
        }
 
        if ( token )
-               is_print_op = user_has_privileges( token, &se_printop );
+               is_print_op = security_token_has_privilege(token, SEC_PRIV_PRINT_OPERATOR);
 
        DEBUG(10,("Running [%s]\n", command));
 
@@ -5735,7 +5728,6 @@ static bool add_printer_hook(TALLOC_CTX *ctx, struct security_token *token,
        int numlines;
        int ret;
        int fd;
-       uint64_t se_printop = SE_PRINT_OPERATOR;
        bool is_print_op = false;
 
        if (!remote_machine) {
@@ -5752,7 +5744,7 @@ static bool add_printer_hook(TALLOC_CTX *ctx, struct security_token *token,
        }
 
        if ( token )
-               is_print_op = user_has_privileges( token, &se_printop );
+               is_print_op = security_token_has_privilege(token, SEC_PRIV_PRINT_OPERATOR);
 
        DEBUG(10,("Running [%s]\n", command));
 
@@ -8048,7 +8040,6 @@ WERROR _spoolss_AddForm(struct pipes_struct *p,
        struct spoolss_AddFormInfo1 *form = r->in.info.info1;
        int snum = -1;
        WERROR status = WERR_OK;
-       uint64_t se_printop = SE_PRINT_OPERATOR;
 
        Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
 
@@ -8064,8 +8055,8 @@ WERROR _spoolss_AddForm(struct pipes_struct *p,
           and not a printer admin, then fail */
 
        if ((p->server_info->utok.uid != sec_initial_uid()) &&
-            !user_has_privileges(p->server_info->ptok, &se_printop) &&
-            !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
+           !security_token_has_privilege(p->server_info->ptok, SEC_PRIV_PRINT_OPERATOR) &&
+           !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
                                          p->server_info->info3->base.domain.string,
                                          NULL,
                                          p->server_info->ptok,
@@ -8120,7 +8111,6 @@ WERROR _spoolss_DeleteForm(struct pipes_struct *p,
        Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
        int snum = -1;
        WERROR status = WERR_OK;
-       uint64_t se_printop = SE_PRINT_OPERATOR;
 
        DEBUG(5,("_spoolss_DeleteForm\n"));
 
@@ -8131,8 +8121,8 @@ WERROR _spoolss_DeleteForm(struct pipes_struct *p,
        }
 
        if ((p->server_info->utok.uid != sec_initial_uid()) &&
-            !user_has_privileges(p->server_info->ptok, &se_printop) &&
-            !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
+           !security_token_has_privilege(p->server_info->ptok, SEC_PRIV_PRINT_OPERATOR) &&
+           !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
                                          p->server_info->info3->base.domain.string,
                                          NULL,
                                          p->server_info->ptok,
@@ -8180,7 +8170,6 @@ WERROR _spoolss_SetForm(struct pipes_struct *p,
        const char *form_name = r->in.form_name;
        int snum = -1;
        WERROR status = WERR_OK;
-       uint64_t se_printop = SE_PRINT_OPERATOR;
 
        Printer_entry *Printer = find_printer_index_by_hnd(p, r->in.handle);
 
@@ -8196,7 +8185,7 @@ WERROR _spoolss_SetForm(struct pipes_struct *p,
           and not a printer admin, then fail */
 
        if ((p->server_info->utok.uid != sec_initial_uid()) &&
-            !user_has_privileges(p->server_info->ptok, &se_printop) &&
+            !security_token_has_privilege(p->server_info->ptok, SEC_PRIV_PRINT_OPERATOR) &&
             !token_contains_name_in_list(uidtoname(p->server_info->utok.uid),
                                          p->server_info->info3->base.domain.string,
                                          NULL,
index ee879e89f70de1cdc0de2809b22c8043179a34a7..a4d7726d28d9a20a42d7ba45dd9243f3c0a3a868 100644 (file)
@@ -1535,7 +1535,6 @@ WERROR _srvsvc_NetShareSetInfo(struct pipes_struct *p,
        int ret;
        char *path = NULL;
        struct security_descriptor *psd = NULL;
-       uint64_t se_diskop = SE_DISK_OPERATOR;
        bool is_disk_op = False;
        int max_connections = 0;
        TALLOC_CTX *ctx = p->mem_ctx;
@@ -1572,7 +1571,7 @@ WERROR _srvsvc_NetShareSetInfo(struct pipes_struct *p,
        if (lp_print_ok(snum))
                return WERR_ACCESS_DENIED;
 
-       is_disk_op = user_has_privileges( p->server_info->ptok, &se_diskop );
+       is_disk_op = security_token_has_privilege(p->server_info->ptok, SEC_PRIV_DISK_OPERATOR);
 
        /* fail out now if you are not root and not a disk op */
 
@@ -1764,7 +1763,6 @@ WERROR _srvsvc_NetShareAdd(struct pipes_struct *p,
        int ret;
        char *path;
        struct security_descriptor *psd = NULL;
-       uint64_t se_diskop = SE_DISK_OPERATOR;
        bool is_disk_op;
        int max_connections = 0;
        TALLOC_CTX *ctx = p->mem_ctx;
@@ -1775,7 +1773,7 @@ WERROR _srvsvc_NetShareAdd(struct pipes_struct *p,
                *r->out.parm_error = 0;
        }
 
-       is_disk_op = user_has_privileges( p->server_info->ptok, &se_diskop );
+       is_disk_op = security_token_has_privilege(p->server_info->ptok, SEC_PRIV_DISK_OPERATOR);
 
        if (p->server_info->utok.uid != sec_initial_uid()  && !is_disk_op )
                return WERR_ACCESS_DENIED;
@@ -1941,7 +1939,6 @@ WERROR _srvsvc_NetShareDel(struct pipes_struct *p,
        char *share_name = NULL;
        int ret;
        int snum;
-       uint64_t se_diskop = SE_DISK_OPERATOR;
        bool is_disk_op;
        struct share_params *params;
        TALLOC_CTX *ctx = p->mem_ctx;
@@ -1969,7 +1966,7 @@ WERROR _srvsvc_NetShareDel(struct pipes_struct *p,
        if (lp_print_ok(snum))
                return WERR_ACCESS_DENIED;
 
-       is_disk_op = user_has_privileges( p->server_info->ptok, &se_diskop );
+       is_disk_op = security_token_has_privilege(p->server_info->ptok, SEC_PRIV_DISK_OPERATOR);
 
        if (p->server_info->utok.uid != sec_initial_uid()  && !is_disk_op )
                return WERR_ACCESS_DENIED;
@@ -2517,12 +2514,11 @@ WERROR _srvsvc_NetFileClose(struct pipes_struct *p,
                            struct srvsvc_NetFileClose *r)
 {
        struct enum_file_close_state state;
-       uint64_t se_diskop = SE_DISK_OPERATOR;
        bool is_disk_op;
 
        DEBUG(5,("_srvsvc_NetFileClose: %d\n", __LINE__));
 
-       is_disk_op = user_has_privileges( p->server_info->ptok, &se_diskop );
+       is_disk_op = security_token_has_privilege(p->server_info->ptok, SEC_PRIV_DISK_OPERATOR);
 
        if (p->server_info->utok.uid != sec_initial_uid() && !is_disk_op) {
                return WERR_ACCESS_DENIED;
index de15f9f82f0728bbe78eae6d67c65b94c54aea05..ab43f6580a1fd80c1c32711e097ee0f089343e6b 100644 (file)
@@ -575,8 +575,7 @@ WERROR _winreg_InitiateSystemShutdownEx(struct pipes_struct *p,
                return WERR_NOMEM;
        }
 
-       can_shutdown = user_has_privileges( p->server_info->ptok,
-                                           &se_remote_shutdown );
+       can_shutdown = security_token_has_privilege(p->server_info->ptok, SEC_PRIV_REMOTE_SHUTDOWN);
 
        /* IF someone has privs, run the shutdown script as root. OTHERWISE run it as not root
           Take the error return from the script and provide it as the Windows return code. */
@@ -613,8 +612,7 @@ WERROR _winreg_AbortSystemShutdown(struct pipes_struct *p,
        if (!*abort_shutdown_script)
                return WERR_ACCESS_DENIED;
 
-       can_shutdown = user_has_privileges( p->server_info->ptok,
-                                           &se_remote_shutdown );
+       can_shutdown = security_token_has_privilege(p->server_info->ptok, SEC_PRIV_REMOTE_SHUTDOWN);
 
        /********** BEGIN SeRemoteShutdownPrivilege BLOCK **********/
 
@@ -704,8 +702,9 @@ WERROR _winreg_RestoreKey(struct pipes_struct *p,
 
        /* user must posses SeRestorePrivilege for this this proceed */
 
-       if ( !user_has_privileges( p->server_info->ptok, &se_restore ) )
+       if ( !security_token_has_privilege(p->server_info->ptok, SEC_PRIV_RESTORE)) {
                return WERR_ACCESS_DENIED;
+       }
 
        DEBUG(2,("_winreg_RestoreKey: Restoring [%s] from %s in share %s\n",
                 regkey->key->name, fname, lp_servicename(snum) ));
index 31513ed113e26b11121bdcad62a85f2ded09b37e..8c00254291f94795ef121c865d8593803b467c81 100644 (file)
@@ -822,7 +822,7 @@ WERROR _wkssvc_NetrJoinDomain2(struct pipes_struct *p,
                return WERR_INVALID_PARAM;
        }
 
-       if (!user_has_privileges(token, &se_machine_account) &&
+       if (!security_token_has_privilege(token, SEC_PRIV_MACHINE_ACCOUNT) &&
            !nt_token_check_domain_rid(token, DOMAIN_RID_ADMINS) &&
            !nt_token_check_sid(&global_sid_Builtin_Administrators, token)) {
                DEBUG(5,("_wkssvc_NetrJoinDomain2: account doesn't have "
@@ -893,7 +893,7 @@ WERROR _wkssvc_NetrUnjoinDomain2(struct pipes_struct *p,
                return WERR_INVALID_PARAM;
        }
 
-       if (!user_has_privileges(token, &se_machine_account) &&
+       if (!security_token_has_privilege(token, SEC_PRIV_MACHINE_ACCOUNT) &&
            !nt_token_check_domain_rid(token, DOMAIN_RID_ADMINS) &&
            !nt_token_check_sid(&global_sid_Builtin_Administrators, token)) {
                DEBUG(5,("_wkssvc_NetrUnjoinDomain2: account doesn't have "
index db8b2529f254705bc3dcf6c193360f435d2c7255..9470447f539b6b0bd1611c650a7441faaf61217f 100644 (file)
@@ -3547,10 +3547,8 @@ int try_chown(connection_struct *conn, struct smb_filename *smb_fname,
        /* Case (2) / (3) */
        if (lp_enable_privileges()) {
 
-               bool has_take_ownership_priv = user_has_privileges(get_current_nttok(conn),
-                                                             &se_take_ownership);
-               bool has_restore_priv = user_has_privileges(get_current_nttok(conn),
-                                                      &se_restore);
+               bool has_take_ownership_priv = security_token_has_privilege(get_current_nttok(conn), SEC_PRIV_TAKE_OWNERSHIP);
+               bool has_restore_priv = security_token_has_privilege(get_current_nttok(conn), SEC_PRIV_RESTORE);
 
                /* Case (2) */
                if ( ( has_take_ownership_priv && ( uid == get_current_uid(conn) ) ) ||