trying to get HEAD building again. If you want the code
[abartlet/samba.git/.git] / source3 / nsswitch / winbindd_sid.c
index 5c225703bacdfcced20829cedaf2e020d1eaa534..676beae3aaf918f089891b10e1c5f43fec7cb5cd 100644 (file)
@@ -1,6 +1,5 @@
 /* 
-   Unix SMB/Netbios implementation.
-   Version 2.0
+   Unix SMB/CIFS implementation.
 
    Winbind daemon - sid related functions
 
@@ -22,7 +21,9 @@
 */
 
 #include "winbindd.h"
-#include "sids.h"
+
+#undef DBGC_CLASS
+#define DBGC_CLASS DBGC_WINBIND
 
 /* Convert a string  */
 
@@ -35,12 +36,18 @@ enum winbindd_result winbindd_lookupsid(struct winbindd_cli_state *state)
        fstring name;
        fstring dom_name;
 
+       /* Ensure null termination */
+       state->request.data.sid[sizeof(state->request.data.sid)-1]='\0';
+
        DEBUG(3, ("[%5d]: lookupsid %s\n", state->pid, 
                  state->request.data.sid));
 
        /* Lookup sid from PDC using lsa_lookup_sids() */
 
-       string_to_sid(&sid, state->request.data.sid);
+       if (!string_to_sid(&sid, state->request.data.sid)) {
+               DEBUG(5, ("%s not a SID\n", state->request.data.sid));
+               return WINBINDD_ERROR;
+       }
 
        /* Don't look up BUILTIN sids */
 
@@ -65,8 +72,10 @@ enum winbindd_result winbindd_lookupsid(struct winbindd_cli_state *state)
        return WINBINDD_OK;
 }
 
-/* Convert a sid to a string */
 
+/**
+ * Look up the SID for a qualified name.  
+ **/
 enum winbindd_result winbindd_lookupname(struct winbindd_cli_state *state)
 {
        enum SID_NAME_USE type;
@@ -74,8 +83,17 @@ enum winbindd_result winbindd_lookupname(struct winbindd_cli_state *state)
        char *name_domain, *name_user;
        DOM_SID sid;
        struct winbindd_domain *domain;
-       DEBUG(3, ("[%5d]: lookupname [%s]\\[%s]\n", state->pid,
-                 state->request.data.name.dom_name, state->request.data.name.name));
+
+       /* Ensure null termination */
+       state->request.data.sid[sizeof(state->request.data.name.dom_name)-1]='\0';
+
+       /* Ensure null termination */
+       state->request.data.sid[sizeof(state->request.data.name.name)-1]='\0';
+
+       DEBUG(3, ("[%5d]: lookupname %s%s%s\n", state->pid,
+                 state->request.data.name.dom_name, 
+                 lp_winbind_separator(),
+                 state->request.data.name.name));
 
        name_domain = state->request.data.name.dom_name;
        name_user = state->request.data.name.name;
@@ -104,33 +122,26 @@ enum winbindd_result winbindd_lookupname(struct winbindd_cli_state *state)
 enum winbindd_result winbindd_sid_to_uid(struct winbindd_cli_state *state)
 {
        DOM_SID sid;
-       uint32 user_rid;
-       struct winbindd_domain *domain;
+       uint32 flags = 0x0;
+
+       /* Ensure null termination */
+       state->request.data.sid[sizeof(state->request.data.sid)-1]='\0';
 
        DEBUG(3, ("[%5d]: sid to uid %s\n", state->pid,
                  state->request.data.sid));
 
        /* Split sid into domain sid and user rid */
-
-       string_to_sid(&sid, state->request.data.sid);
-       sid_split_rid(&sid, &user_rid);
-
-       /* Find domain this sid belongs to */
-
-       if ((domain = find_domain_from_sid(&sid)) == NULL) {
-               fstring sid_str;
-
-               sid_to_string(sid_str, &sid);
-               DEBUG(1, ("Could not find domain for sid %s\n", sid_str));
+       if (!string_to_sid(&sid, state->request.data.sid)) {
+               DEBUG(1, ("Could not get convert sid %s from string\n", state->request.data.sid));
                return WINBINDD_ERROR;
        }
-
+       
+       if ( state->request.flags & WBFLAG_QUERY_ONLY ) 
+               flags = ID_QUERY_ONLY;
+       
        /* Find uid for this sid and return it */
-
-       if (!winbindd_idmap_get_uid_from_rid(domain->name, user_rid,
-                                            &state->response.data.uid)) {
-               DEBUG(1, ("Could not get uid for sid %s\n",
-                         state->request.data.sid));
+       if ( !NT_STATUS_IS_OK(idmap_sid_to_uid(&sid, &(state->response.data.uid), flags)) ) {
+               DEBUG(1, ("Could not get uid for sid %s\n", state->request.data.sid));
                return WINBINDD_ERROR;
        }
 
@@ -143,33 +154,25 @@ enum winbindd_result winbindd_sid_to_uid(struct winbindd_cli_state *state)
 enum winbindd_result winbindd_sid_to_gid(struct winbindd_cli_state *state)
 {
        DOM_SID sid;
-       uint32 group_rid;
-       struct winbindd_domain *domain;
+       uint32 flags = 0x0;
+
+       /* Ensure null termination */
+       state->request.data.sid[sizeof(state->request.data.sid)-1]='\0';
 
        DEBUG(3, ("[%5d]: sid to gid %s\n", state->pid, 
                  state->request.data.sid));
 
-       /* Split sid into domain sid and user rid */
-
-       string_to_sid(&sid, state->request.data.sid);
-       sid_split_rid(&sid, &group_rid);
-
-       /* Find domain this sid belongs to */
-
-       if ((domain = find_domain_from_sid(&sid)) == NULL) {
-               fstring sid_str;
-
-               sid_to_string(sid_str, &sid);
-               DEBUG(1, ("Could not find domain for sid %s\n", sid_str));
+       if (!string_to_sid(&sid, state->request.data.sid)) {
+               DEBUG(1, ("Could not cvt string to sid %s\n", state->request.data.sid));
                return WINBINDD_ERROR;
        }
 
-       /* Find uid for this sid and return it */
-
-       if (!winbindd_idmap_get_gid_from_rid(domain->name, group_rid,
-                                            &state->response.data.gid)) {
-               DEBUG(1, ("Could not get gid for sid %s\n",
-                         state->request.data.sid));
+       if ( state->request.flags & WBFLAG_QUERY_ONLY ) 
+               flags = ID_QUERY_ONLY;
+               
+       /* Find gid for this sid and return it */
+       if ( !NT_STATUS_IS_OK(idmap_sid_to_gid(&sid, &(state->response.data.gid), flags)) ) {
+               DEBUG(1, ("Could not get gid for sid %s\n", state->request.data.sid));
                return WINBINDD_ERROR;
        }
 
@@ -180,8 +183,6 @@ enum winbindd_result winbindd_sid_to_gid(struct winbindd_cli_state *state)
 
 enum winbindd_result winbindd_uid_to_sid(struct winbindd_cli_state *state)
 {
-       struct winbindd_domain *domain;
-       uint32 user_rid;
        DOM_SID sid;
 
        /* Bug out if the uid isn't in the winbind range */
@@ -195,18 +196,12 @@ enum winbindd_result winbindd_uid_to_sid(struct winbindd_cli_state *state)
                  state->request.data.uid));
 
        /* Lookup rid for this uid */
-
-       if (!winbindd_idmap_get_rid_from_uid(state->request.data.uid,
-                                            &user_rid, &domain)) {
+       if (!NT_STATUS_IS_OK(idmap_uid_to_sid(&sid, state->request.data.uid))) {
                DEBUG(1, ("Could not convert uid %d to rid\n",
                          state->request.data.uid));
                return WINBINDD_ERROR;
        }
 
-       /* Construct sid and return it */
-
-       sid_copy(&sid, &domain->sid);
-       sid_append_rid(&sid, user_rid);
        sid_to_string(state->response.data.sid.sid, &sid);
        state->response.data.sid.type = SID_NAME_USER;
 
@@ -217,8 +212,6 @@ enum winbindd_result winbindd_uid_to_sid(struct winbindd_cli_state *state)
 
 enum winbindd_result winbindd_gid_to_sid(struct winbindd_cli_state *state)
 {
-       struct winbindd_domain *domain;
-       uint32 group_rid;
        DOM_SID sid;
 
        /* Bug out if the gid isn't in the winbind range */
@@ -231,19 +224,14 @@ enum winbindd_result winbindd_gid_to_sid(struct winbindd_cli_state *state)
        DEBUG(3, ("[%5d]: gid to sid %d\n", state->pid,
                  state->request.data.gid));
 
-       /* Lookup rid for this uid */
-
-       if (!winbindd_idmap_get_rid_from_gid(state->request.data.gid,
-                                            &group_rid, &domain)) {
-               DEBUG(1, ("Could not convert gid %d to rid\n",
+       /* Lookup sid for this uid */
+       if (!NT_STATUS_IS_OK(idmap_gid_to_sid(&sid, state->request.data.gid))) {
+               DEBUG(1, ("Could not convert gid %d to sid\n",
                          state->request.data.gid));
                return WINBINDD_ERROR;
        }
 
        /* Construct sid and return it */
-
-       sid_copy(&sid, &domain->sid);
-       sid_append_rid(&sid, group_rid);
        sid_to_string(state->response.data.sid.sid, &sid);
        state->response.data.sid.type = SID_NAME_DOM_GRP;