wbinfo: use wbcListUsers() and wbcListGroups()
authorStefan Metzmacher <metze@samba.org>
Mon, 24 Mar 2008 19:32:14 +0000 (20:32 +0100)
committerStefan Metzmacher <metze@samba.org>
Fri, 28 Mar 2008 14:11:42 +0000 (15:11 +0100)
metze
(This used to be commit 5a0ae1ad0c36e5ef97008a2c6bc2a921ca6538bd)

source3/nsswitch/wbinfo.c

index ababab367cf678bf97ae7b498899049f25905005..f8d77cec60e30a46ed48e95113f8180fd7f8fb45 100644 (file)
@@ -1074,42 +1074,28 @@ static bool wbinfo_klog(char *username)
 
 static bool print_domain_users(const char *domain)
 {
-       struct winbindd_request request;
-       struct winbindd_response response;
-       const char *extra_data;
-       char *name;
-       TALLOC_CTX *frame = NULL;
+       wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
+       uint32_t i;
+       uint32_t num_users = 0;
+       const char **users = NULL;
 
        /* Send request to winbind daemon */
 
-       ZERO_STRUCT(request);
-       ZERO_STRUCT(response);
-
-       if (domain) {
-               /* '.' is the special sign for our own domain */
-               if ( strequal(domain, ".") )
-                       fstrcpy( request.domain_name, get_winbind_domain() );
-               else
-                       fstrcpy( request.domain_name, domain );
+       /* '.' is the special sign for our own domain */
+       if (domain && strcmp(domain, ".") == 0) {
+               domain = get_winbind_domain();
        }
 
-       if (winbindd_request_response(WINBINDD_LIST_USERS, &request, &response) !=
-           NSS_STATUS_SUCCESS)
-               return false;
-
-       /* Look through extra data */
-
-       if (!response.extra_data.data)
+       wbc_status = wbcListUsers(domain, &num_users, &users);
+       if (!WBC_ERROR_IS_OK(wbc_status)) {
                return false;
+       }
 
-       extra_data = (const char *)response.extra_data.data;
-
-       frame = talloc_stackframe();
-       while(next_token_talloc(frame,&extra_data,&name, ","))
-               d_printf("%s\n", name);
-       TALLOC_FREE(frame);
+       for (i=0; i < num_users; i++) {
+               d_printf("%s\n", users[i]);
+       }
 
-       SAFE_FREE(response.extra_data.data);
+       wbcFreeMemory(users);
 
        return true;
 }
@@ -1118,39 +1104,28 @@ static bool print_domain_users(const char *domain)
 
 static bool print_domain_groups(const char *domain)
 {
-       struct winbindd_request  request;
-       struct winbindd_response response;
-       const char *extra_data;
-       TALLOC_CTX *frame = NULL;
-       char *name;
+       wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
+       uint32_t i;
+       uint32_t num_groups = 0;
+       const char **groups = NULL;
 
-       ZERO_STRUCT(request);
-       ZERO_STRUCT(response);
+       /* Send request to winbind daemon */
 
-       if (domain) {
-               if ( strequal(domain, ".") )
-                       fstrcpy( request.domain_name, get_winbind_domain() );
-               else
-                       fstrcpy( request.domain_name, domain );
+       /* '.' is the special sign for our own domain */
+       if (domain && strcmp(domain, ".") == 0) {
+               domain = get_winbind_domain();
        }
 
-       if (winbindd_request_response(WINBINDD_LIST_GROUPS, &request, &response) !=
-           NSS_STATUS_SUCCESS)
-               return false;
-
-       /* Look through extra data */
-
-       if (!response.extra_data.data)
+       wbc_status = wbcListGroups(domain, &num_groups, &groups);
+       if (!WBC_ERROR_IS_OK(wbc_status)) {
                return false;
+       }
 
-       extra_data = (const char *)response.extra_data.data;
-
-       frame = talloc_stackframe();
-       while(next_token_talloc(frame,&extra_data,&name, ","))
-               d_printf("%s\n", name);
-       TALLOC_FREE(frame);
+       for (i=0; i < num_groups; i++) {
+               d_printf("%s\n", groups[i]);
+       }
 
-       SAFE_FREE(response.extra_data.data);
+       wbcFreeMemory(groups);
 
        return true;
 }