merge of the netsamlogon caching code from APPLIANCE_HEAD
[ira/wip.git] / source3 / nsswitch / wb_client.c
index 941d54a4c8af88d2f8a64db3ff0cfb10978f9669..b1765a8bd7d2852c410056aab947af94fa35646a 100644 (file)
 */
 
 #include "includes.h"
-#include "nsswitch/nss.h"
+#include "nsswitch/winbind_nss.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_WINBIND
+
 extern DOM_SID global_sid_NULL;                        /* NULL sid */
 
 NSS_STATUS winbindd_request(int req_type,
@@ -55,7 +56,8 @@ BOOL winbind_lookup_name(const char *dom_name, const char *name, DOM_SID *sid,
 
        if ((result = winbindd_request(WINBINDD_LOOKUPNAME, &request, 
                                       &response)) == NSS_STATUS_SUCCESS) {
-               string_to_sid(sid, response.data.sid.sid);
+               if (!string_to_sid(sid, response.data.sid.sid))
+                       return False;
                *name_type = (enum SID_NAME_USE)response.data.sid.type;
        }
 
@@ -64,7 +66,7 @@ BOOL winbind_lookup_name(const char *dom_name, const char *name, DOM_SID *sid,
 
 /* Call winbindd to convert sid to name */
 
-BOOL winbind_lookup_sid(DOM_SID *sid, 
+BOOL winbind_lookup_sid(const DOM_SID *sid, 
                        fstring dom_name, fstring name, 
                         enum SID_NAME_USE *name_type)
 {
@@ -101,7 +103,7 @@ BOOL winbind_lookup_sid(DOM_SID *sid,
 
 /* Call winbindd to convert SID to uid */
 
-BOOL winbind_sid_to_uid(uid_t *puid, DOM_SID *sid)
+BOOL winbind_sid_to_uid(uid_t *puid, const DOM_SID *sid)
 {
        struct winbindd_request request;
        struct winbindd_response response;
@@ -157,7 +159,8 @@ BOOL winbind_uid_to_sid(DOM_SID *sid, uid_t uid)
        /* Copy out result */
 
        if (result == NSS_STATUS_SUCCESS) {
-               string_to_sid(sid, response.data.sid.sid);
+               if (!string_to_sid(sid, response.data.sid.sid))
+                       return False;
        } else {
                sid_copy(sid, &global_sid_NULL);
        }
@@ -167,7 +170,7 @@ BOOL winbind_uid_to_sid(DOM_SID *sid, uid_t uid)
 
 /* Call winbindd to convert SID to gid */
 
-BOOL winbind_sid_to_gid(gid_t *pgid, DOM_SID *sid)
+BOOL winbind_sid_to_gid(gid_t *pgid, const DOM_SID *sid)
 {
        struct winbindd_request request;
        struct winbindd_response response;
@@ -223,7 +226,8 @@ BOOL winbind_gid_to_sid(DOM_SID *sid, gid_t gid)
        /* Copy out result */
 
        if (result == NSS_STATUS_SUCCESS) {
-               string_to_sid(sid, response.data.sid.sid);
+               if (!string_to_sid(sid, response.data.sid.sid))
+                       return False;
        } else {
                sid_copy(sid, &global_sid_NULL);
        }
@@ -265,11 +269,8 @@ static int wb_getgroups(const char *user, gid_t **groups)
    time consuming.  If size is zero, list is not modified and the total
    number of groups for the user is returned. */
 
-int winbind_getgroups(const char *user, int size, gid_t *list)
+int winbind_getgroups(const char *user, gid_t **list)
 {
-       gid_t *groups = NULL;
-       int result, i;
-
        /*
         * Don't do the lookup if the name has no separator _and_ we are not in
         * 'winbind use default domain' mode.
@@ -280,24 +281,5 @@ int winbind_getgroups(const char *user, int size, gid_t *list)
 
        /* Fetch list of groups */
 
-       result = wb_getgroups(user, &groups);
-
-       if (size == 0)
-               goto done;
-
-       if (result > size) {
-               result = -1;
-               errno = EINVAL; /* This is what getgroups() does */
-               goto done;
-       }
-
-       /* Copy list of groups across */
-
-       for (i = 0; i < result; i++) {
-               list[i] = groups[i];
-       }
-
- done:
-       SAFE_FREE(groups);
-       return result;
+       return wb_getgroups(user, list);
 }