smbd: Remove unused [push_pull]_file_id_24
[samba.git] / source3 / utils / net_rpc_rights.c
index 02027f8d925f6f57ceb7da88af41d91fad651690..267ce6576e6f6c3804fc14045abe8adde57b6897 100644 (file)
 */
 #include "includes.h"
 #include "utils/net.h"
+#include "rpc_client/rpc_client.h"
 #include "../librpc/gen_ndr/ndr_lsa_c.h"
 #include "rpc_client/cli_lsarpc.h"
 #include "rpc_client/init_lsa.h"
 #include "../libcli/security/security.h"
+#include "lib/util/string_wrappers.h"
 
 /********************************************************************
 ********************************************************************/
@@ -71,7 +73,7 @@ static NTSTATUS name_to_sid(struct rpc_pipe_client *pipe_hnd,
        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
 
        /* maybe its a raw SID */
-       if ( strncmp(name, "S-", 2) == 0 && string_to_sid(sid, name) ) {
+       if (dom_sid_parse(name, sid)) {
                return NT_STATUS_OK;
        }
 
@@ -99,12 +101,12 @@ static NTSTATUS enum_privileges(struct rpc_pipe_client *pipe_hnd,
                                struct policy_handle *pol )
 {
        NTSTATUS status, result;
-       uint32 enum_context = 0;
-       uint32 pref_max_length=0x1000;
-       int i;
-       uint16 lang_id=0;
-       uint16 lang_id_sys=0;
-       uint16 lang_id_desc;
+       uint32_t enum_context = 0;
+       uint32_t pref_max_length=0x1000;
+       uint32_t i;
+       uint16_t lang_id=0;
+       uint16_t lang_id_sys=0;
+       uint16_t lang_id_desc;
        struct lsa_StringLarge *description = NULL;
        struct lsa_PrivArray priv_array;
        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
@@ -152,7 +154,7 @@ static NTSTATUS enum_privileges(struct rpc_pipe_client *pipe_hnd,
                        continue;
                }
 
-               d_printf("%s\n", description->string);
+               d_printf("%s\n", description ? description->string : "??????");
        }
 
        return NT_STATUS_OK;
@@ -169,7 +171,7 @@ static NTSTATUS check_privilege_for_user(struct rpc_pipe_client *pipe_hnd,
 {
        NTSTATUS status, result;
        struct lsa_RightSet rights;
-       int i;
+       uint32_t i;
        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
 
        status = dcerpc_lsa_EnumAccountRights(b, ctx,
@@ -189,7 +191,7 @@ static NTSTATUS check_privilege_for_user(struct rpc_pipe_client *pipe_hnd,
        }
 
        for (i = 0; i < rights.count; i++) {
-               if (StrCaseCmp(rights.names[i].string, right) == 0) {
+               if (strcasecmp_m(rights.names[i].string, right) == 0) {
                        return NT_STATUS_OK;
                }
        }
@@ -207,7 +209,7 @@ static NTSTATUS enum_privileges_for_user(struct rpc_pipe_client *pipe_hnd,
 {
        NTSTATUS status, result;
        struct lsa_RightSet rights;
-       int i;
+       uint32_t i;
        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
 
        status = dcerpc_lsa_EnumAccountRights(b, ctx,
@@ -240,10 +242,10 @@ static NTSTATUS enum_accounts_for_privilege(struct rpc_pipe_client *pipe_hnd,
                                                const char *privilege)
 {
        NTSTATUS status, result;
-       uint32 enum_context=0;
-       uint32 pref_max_length=0x1000;
+       uint32_t enum_context=0;
+       uint32_t pref_max_length=0x1000;
        struct lsa_SidArray sid_array;
-       int i;
+       uint32_t i;
        fstring name;
        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
 
@@ -293,10 +295,10 @@ static NTSTATUS enum_privileges_for_accounts(struct rpc_pipe_client *pipe_hnd,
                                                struct policy_handle *pol)
 {
        NTSTATUS status, result;
-       uint32 enum_context=0;
-       uint32 pref_max_length=0x1000;
+       uint32_t enum_context=0;
+       uint32_t pref_max_length=0x1000;
        struct lsa_SidArray sid_array;
-       int i;
+       uint32_t i;
        fstring name;
        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
 
@@ -351,9 +353,9 @@ static NTSTATUS rpc_rights_list_internal(struct net_context *c,
        fstring privname;
        struct lsa_String lsa_name;
        struct lsa_StringLarge *description = NULL;
-       uint16 lang_id = 0;
-       uint16 lang_id_sys = 0;
-       uint16 lang_id_desc;
+       uint16_t lang_id = 0;
+       uint16_t lang_id_sys = 0;
+       uint16_t lang_id_desc;
        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
 
        status = rpccli_lsa_open_policy(pipe_hnd, mem_ctx, true,
@@ -362,7 +364,7 @@ static NTSTATUS rpc_rights_list_internal(struct net_context *c,
        if ( !NT_STATUS_IS_OK(status) )
                return status;
 
-       /* backwards compatibility; just list available privileges if no arguement */
+       /* backwards compatibility; just list available privileges if no argument */
 
        if (argc == 0) {
                status = enum_privileges(pipe_hnd, mem_ctx, &pol );
@@ -442,7 +444,7 @@ static NTSTATUS rpc_rights_list_internal(struct net_context *c,
                goto done;
        }
 
-       /* backward comaptibility: if no keyword provided, treat the key
+       /* backward compatibility: if no keyword provided, treat the key
           as an account name */
        if (argc > 1) {
                d_printf("%s net rpc rights list [[accounts|privileges] "
@@ -475,11 +477,19 @@ static NTSTATUS rpc_rights_grant_internal(struct net_context *c,
                                        int argc,
                                        const char **argv )
 {
-       struct policy_handle dom_pol;
+       struct policy_handle dom_pol = {
+               .handle_type = 0,
+       };
        NTSTATUS status, result;
        struct lsa_RightSet rights;
        int i;
        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
+       union lsa_revision_info out_revision_info = {
+               .info1 = {
+                       .revision = 0,
+               },
+       };
+       uint32_t out_version = 0;
 
        struct dom_sid sid;
 
@@ -497,18 +507,27 @@ static NTSTATUS rpc_rights_grant_internal(struct net_context *c,
        if (!NT_STATUS_IS_OK(status))
                goto done;
 
-       status = rpccli_lsa_open_policy2(pipe_hnd, mem_ctx, true,
-                                    SEC_FLAG_MAXIMUM_ALLOWED,
-                                    &dom_pol);
-
-       if (!NT_STATUS_IS_OK(status))
-               return status;
+       status = dcerpc_lsa_open_policy_fallback(b,
+                                                mem_ctx,
+                                                pipe_hnd->srv_name_slash,
+                                                true,
+                                                SEC_FLAG_MAXIMUM_ALLOWED,
+                                                &out_version,
+                                                &out_revision_info,
+                                                &dom_pol,
+                                                &result);
+       if (any_nt_status_not_ok(status, result, &status)) {
+               DBG_DEBUG("Couldn't open policy handle: %s\n",
+                         nt_errstr(status));
+               goto done;
+       }
 
        rights.count = argc-1;
-       rights.names = TALLOC_ARRAY(mem_ctx, struct lsa_StringLarge,
+       rights.names = talloc_array(mem_ctx, struct lsa_StringLarge,
                                    rights.count);
-       if (!rights.names) {
-               return NT_STATUS_NO_MEMORY;
+       if (rights.names == NULL) {
+               status = NT_STATUS_NO_MEMORY;
+               goto done;
        }
 
        for (i=0; i<argc-1; i++) {
@@ -520,10 +539,7 @@ static NTSTATUS rpc_rights_grant_internal(struct net_context *c,
                                             &sid,
                                             &rights,
                                             &result);
-       if (!NT_STATUS_IS_OK(status))
-               goto done;
-       if (!NT_STATUS_IS_OK(result)) {
-               status = result;
+       if (any_nt_status_not_ok(status, result, &status)) {
                goto done;
        }
 
@@ -558,6 +574,13 @@ static NTSTATUS rpc_rights_revoke_internal(struct net_context *c,
        struct dom_sid sid;
        int i;
        struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;
+       union lsa_revision_info out_revision_info = {
+               .info1 =
+                       {
+                               .revision = 0,
+                       },
+       };
+       uint32_t out_version = 0;
 
        if (argc < 2 ) {
                d_printf("%s\n%s",
@@ -570,15 +593,23 @@ static NTSTATUS rpc_rights_revoke_internal(struct net_context *c,
        if (!NT_STATUS_IS_OK(status))
                return status;
 
-       status = rpccli_lsa_open_policy2(pipe_hnd, mem_ctx, true,
-                                    SEC_FLAG_MAXIMUM_ALLOWED,
-                                    &dom_pol);
-
-       if (!NT_STATUS_IS_OK(status))
+       status = dcerpc_lsa_open_policy_fallback(b,
+                                                mem_ctx,
+                                                pipe_hnd->srv_name_slash,
+                                                true,
+                                                SEC_FLAG_MAXIMUM_ALLOWED,
+                                                &out_version,
+                                                &out_revision_info,
+                                                &dom_pol,
+                                                &result);
+       if (any_nt_status_not_ok(status, result, &status)) {
+               DBG_DEBUG("Couldn't open policy handle: %s\n",
+                         nt_errstr(status));
                return status;
+       }
 
        rights.count = argc-1;
-       rights.names = TALLOC_ARRAY(mem_ctx, struct lsa_StringLarge,
+       rights.names = talloc_array(mem_ctx, struct lsa_StringLarge,
                                    rights.count);
        if (!rights.names) {
                return NT_STATUS_NO_MEMORY;
@@ -629,7 +660,7 @@ static int rpc_rights_list(struct net_context *c, int argc, const char **argv )
                return 0;
        }
 
-       return run_rpc_command(c, NULL, &ndr_table_lsarpc.syntax_id, 0,
+       return run_rpc_command(c, NULL, &ndr_table_lsarpc, 0,
                rpc_rights_list_internal, argc, argv );
 }
 
@@ -651,7 +682,7 @@ static int rpc_rights_grant(struct net_context *c, int argc, const char **argv )
                return 0;
        }
 
-       return run_rpc_command(c, NULL, &ndr_table_lsarpc.syntax_id, 0,
+       return run_rpc_command(c, NULL, &ndr_table_lsarpc, 0,
                rpc_rights_grant_internal, argc, argv );
 }
 
@@ -673,7 +704,7 @@ static int rpc_rights_revoke(struct net_context *c, int argc, const char **argv)
                return 0;
        }
 
-       return run_rpc_command(c, NULL, &ndr_table_lsarpc.syntax_id, 0,
+       return run_rpc_command(c, NULL, &ndr_table_lsarpc, 0,
                rpc_rights_revoke_internal, argc, argv );
 }
 
@@ -750,13 +781,13 @@ struct rpc_sh_cmd *net_rpc_rights_cmds(struct net_context *c, TALLOC_CTX *mem_ct
 {
        static struct rpc_sh_cmd cmds[] = {
 
-       { "list", NULL, &ndr_table_lsarpc.syntax_id, rpc_sh_rights_list,
+       { "list", NULL, &ndr_table_lsarpc, rpc_sh_rights_list,
          N_("View available or assigned privileges") },
 
-       { "grant", NULL, &ndr_table_lsarpc.syntax_id, rpc_sh_rights_grant,
+       { "grant", NULL, &ndr_table_lsarpc, rpc_sh_rights_grant,
          N_("Assign privilege[s]") },
 
-       { "revoke", NULL, &ndr_table_lsarpc.syntax_id, rpc_sh_rights_revoke,
+       { "revoke", NULL, &ndr_table_lsarpc, rpc_sh_rights_revoke,
          N_("Revoke privilege[s]") },
 
        { NULL, NULL, 0, NULL, NULL }