smbcacls: Move StringToSid to common file
authorChristof Schmitt <cs@samba.org>
Fri, 24 Apr 2015 16:15:13 +0000 (09:15 -0700)
committerJeremy Allison <jra@samba.org>
Fri, 24 Apr 2015 22:04:24 +0000 (00:04 +0200)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=11237

Signed-off-by: Christof Schmitt <cs@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/include/util_sd.h
source3/lib/util_sd.c
source3/utils/smbcacls.c

index 55e2205d8c8ad10e9e9bc5cf5e3c27b6c915fbe9..7f21c643c2477c5c089222dd8096a68d09535e9e 100644 (file)
@@ -26,5 +26,6 @@
 
 void SidToString(struct cli_state *cli, fstring str, const struct dom_sid *sid,
                 bool numeric);
+bool StringToSid(struct cli_state *cli, struct dom_sid *sid, const char *str);
 
 #endif
index b653fe9745de1f48569744294dccbadb2f3e33dd..584d34aaf6f5f6e229214b1b93f65de52a147333 100644 (file)
@@ -111,3 +111,64 @@ void SidToString(struct cli_state *cli, fstring str, const struct dom_sid *sid,
                fstrcpy(str, name);
        }
 }
+
+static NTSTATUS cli_lsa_lookup_name(struct cli_state *cli,
+                                   const char *name,
+                                   enum lsa_SidType *type,
+                                   struct dom_sid *sid)
+{
+       uint16 orig_cnum = cli_state_get_tid(cli);
+       struct rpc_pipe_client *p;
+       struct policy_handle handle;
+       NTSTATUS status;
+       TALLOC_CTX *frame = talloc_stackframe();
+       struct dom_sid *sids;
+       enum lsa_SidType *types;
+
+       status = cli_tree_connect(cli, "IPC$", "?????", "", 0);
+       if (!NT_STATUS_IS_OK(status)) {
+               goto tcon_fail;
+       }
+
+       status = cli_rpc_pipe_open_noauth(cli, &ndr_table_lsarpc,
+                                         &p);
+       if (!NT_STATUS_IS_OK(status)) {
+               goto fail;
+       }
+
+       status = rpccli_lsa_open_policy(p, talloc_tos(), True,
+                                       GENERIC_EXECUTE_ACCESS, &handle);
+       if (!NT_STATUS_IS_OK(status)) {
+               goto fail;
+       }
+
+       status = rpccli_lsa_lookup_names(p, talloc_tos(), &handle, 1, &name,
+                                        NULL, 1, &sids, &types);
+       if (!NT_STATUS_IS_OK(status)) {
+               goto fail;
+       }
+
+       *type = types[0];
+       *sid = sids[0];
+
+       status = NT_STATUS_OK;
+ fail:
+       TALLOC_FREE(p);
+       cli_tdis(cli);
+ tcon_fail:
+       cli_state_set_tid(cli, orig_cnum);
+       TALLOC_FREE(frame);
+       return status;
+}
+
+/* convert a string to a SID, either numeric or username/group */
+bool StringToSid(struct cli_state *cli, struct dom_sid *sid, const char *str)
+{
+       enum lsa_SidType type;
+
+       if (string_to_sid(sid, str)) {
+               return true;
+       }
+
+       return NT_STATUS_IS_OK(cli_lsa_lookup_name(cli, str, &type, sid));
+}
index 5bbc8fa812cef1954ed38d6e8fbb6e40f1db738b..778d30d4548b5b9a2d18d1990f767348124494a0 100644 (file)
@@ -72,56 +72,6 @@ static const struct perm_value standard_values[] = {
        { NULL, 0 },
 };
 
-static NTSTATUS cli_lsa_lookup_name(struct cli_state *cli,
-                                   const char *name,
-                                   enum lsa_SidType *type,
-                                   struct dom_sid *sid)
-{
-       uint16 orig_cnum = cli_state_get_tid(cli);
-       struct rpc_pipe_client *p;
-       struct policy_handle handle;
-       NTSTATUS status;
-       TALLOC_CTX *frame = talloc_stackframe();
-       struct dom_sid *sids;
-       enum lsa_SidType *types;
-
-       status = cli_tree_connect(cli, "IPC$", "?????", "", 0);
-       if (!NT_STATUS_IS_OK(status)) {
-               goto tcon_fail;
-       }
-
-       status = cli_rpc_pipe_open_noauth(cli, &ndr_table_lsarpc,
-                                         &p);
-       if (!NT_STATUS_IS_OK(status)) {
-               goto fail;
-       }
-
-       status = rpccli_lsa_open_policy(p, talloc_tos(), True,
-                                       GENERIC_EXECUTE_ACCESS, &handle);
-       if (!NT_STATUS_IS_OK(status)) {
-               goto fail;
-       }
-
-       status = rpccli_lsa_lookup_names(p, talloc_tos(), &handle, 1, &name,
-                                        NULL, 1, &sids, &types);
-       if (!NT_STATUS_IS_OK(status)) {
-               goto fail;
-       }
-
-       *type = types[0];
-       *sid = sids[0];
-
-       status = NT_STATUS_OK;
- fail:
-       TALLOC_FREE(p);
-       cli_tdis(cli);
- tcon_fail:
-       cli_state_set_tid(cli, orig_cnum);
-       TALLOC_FREE(frame);
-       return status;
-}
-
-
 static NTSTATUS cli_lsa_lookup_domain_sid(struct cli_state *cli,
                                          struct dom_sid *sid)
 {
@@ -197,18 +147,6 @@ static struct dom_sid *get_domain_sid(struct cli_state *cli)
        return sid;
 }
 
-/* convert a string to a SID, either numeric or username/group */
-static bool StringToSid(struct cli_state *cli, struct dom_sid *sid, const char *str)
-{
-       enum lsa_SidType type;
-
-       if (string_to_sid(sid, str)) {
-               return true;
-       }
-
-       return NT_STATUS_IS_OK(cli_lsa_lookup_name(cli, str, &type, sid));
-}
-
 static void print_ace_flags(FILE *f, uint8_t flags)
 {
        char *str = talloc_strdup(NULL, "");