r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text
[bbaumbach/samba-autobuild/.git] / source3 / nsswitch / winbindd_user.c
index 5e1ce8d13700d62c8aebe4d70dfdd329319917ff..198c54c039dbe3a105579df6b1c38f4eb8739ef8 100644 (file)
@@ -9,7 +9,7 @@
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -18,8 +18,7 @@
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
@@ -400,7 +399,8 @@ void winbindd_getpwnam(struct winbindd_cli_state *state)
        /* Get rid and name type from name.  The following costs 1 packet */
 
        winbindd_lookupname_async(state->mem_ctx, domname, username,
-                                 getpwnam_name2sid_recv, state);
+                                 getpwnam_name2sid_recv, WINBINDD_GETPWNAM, 
+                                 state);
 }
 
 static void getpwnam_name2sid_recv(void *private_data, BOOL success,
@@ -662,7 +662,7 @@ void winbindd_getpwent(struct winbindd_cli_state *state)
 {
        struct getent_state *ent;
        struct winbindd_pw *user_list;
-       int num_users, user_list_ndx = 0, i;
+       int num_users, user_list_ndx;
 
        DEBUG(3, ("[%5lu]: getpwent\n", (unsigned long)state->pid));
 
@@ -676,6 +676,11 @@ void winbindd_getpwent(struct winbindd_cli_state *state)
        /* Allocate space for returning a chunk of users */
 
        num_users = MIN(MAX_GETPWENT_USERS, state->request.data.num_entries);
+
+       if (num_users == 0) {
+               request_error(state);
+               return;
+       }
        
        if ((state->response.extra_data.data = SMB_MALLOC_ARRAY(struct winbindd_pw, num_users)) == NULL) {
                request_error(state);
@@ -697,7 +702,7 @@ void winbindd_getpwent(struct winbindd_cli_state *state)
 
        /* Start sending back users */
 
-       for (i = 0; i < num_users; i++) {
+       for (user_list_ndx = 0; user_list_ndx < num_users; ) {
                struct getpwent_user *name_list = NULL;
                uint32 result;
 
@@ -740,8 +745,6 @@ void winbindd_getpwent(struct winbindd_cli_state *state)
                        name_list[ent->sam_entry_index].shell,
                        &user_list[user_list_ndx]);
                
-               ent->sam_entry_index++;
-               
                /* Add user to return list */
                
                if (result) {
@@ -754,6 +757,9 @@ void winbindd_getpwent(struct winbindd_cli_state *state)
                } else
                        DEBUG(1, ("could not lookup domain user %s\n",
                                  name_list[ent->sam_entry_index].name));
+
+               ent->sam_entry_index++;
+               
        }
 
        /* Out of domains */