r17554: Cleanup
[kai/samba.git] / source3 / passdb / pdb_interface.c
index 393b60516cc1c808b4f27007d19e74ca0e58d3f0..7f2a8f25b3d08b22120bd103ffdf8f5f0ce28d53 100644 (file)
@@ -37,7 +37,9 @@ static struct pdb_init_function_entry *backends = NULL;
 static void lazy_initialize_passdb(void)
 {
        static BOOL initialized = False;
-       if(initialized)return;
+       if(initialized) {
+               return;
+       }
        static_init_pdb;
        initialized = True;
 }
@@ -201,13 +203,19 @@ static struct pdb_methods *pdb_get_methods_reload( BOOL reload )
        if ( pdb && reload ) {
                pdb->free_private_data( &(pdb->private_data) );
                if ( !NT_STATUS_IS_OK( make_pdb_method_name( &pdb, lp_passdb_backend() ) ) ) {
-                       return NULL;
+                       pstring msg;
+                       slprintf(msg, sizeof(msg)-1, "pdb_get_methods_reload: failed to get pdb methods for backend %s\n",
+                               lp_passdb_backend() );
+                       smb_panic(msg);
                }
        }
 
        if ( !pdb ) {
                if ( !NT_STATUS_IS_OK( make_pdb_method_name( &pdb, lp_passdb_backend() ) ) ) {
-                       return NULL;
+                       pstring msg;
+                       slprintf(msg, sizeof(msg)-1, "pdb_get_methods_reload: failed to get pdb methods for backend %s\n",
+                               lp_passdb_backend() );
+                       smb_panic(msg);
                }
        }
 
@@ -226,22 +234,12 @@ static struct pdb_methods *pdb_get_methods(void)
 BOOL pdb_setsampwent(BOOL update, uint16 acb_mask) 
 {
        struct pdb_methods *pdb = pdb_get_methods();
-
-       if ( !pdb ) {
-               return False;
-       }
-
        return NT_STATUS_IS_OK(pdb->setsampwent(pdb, update, acb_mask));
 }
 
 void pdb_endsampwent(void) 
 {
        struct pdb_methods *pdb = pdb_get_methods();
-
-       if ( !pdb ) {
-               return;
-       }
-
        pdb->endsampwent(pdb);
 }
 
@@ -249,16 +247,10 @@ BOOL pdb_getsampwent(struct samu *user)
 {
        struct pdb_methods *pdb = pdb_get_methods();
 
-       if ( !pdb ) {
-               return False;
-       }
-
        if ( !NT_STATUS_IS_OK(pdb->getsampwent(pdb, user) ) ) {
                return False;
        }
-
        pdb_force_pw_initialization( user );
-
        return True;
 }
 
@@ -266,10 +258,6 @@ BOOL pdb_getsampwnam(struct samu *sam_acct, const char *username)
 {
        struct pdb_methods *pdb = pdb_get_methods();
 
-       if ( !pdb ) {
-               return False;
-       }
-
        if (!NT_STATUS_IS_OK(pdb->getsampwnam(pdb, sam_acct, username))) {
                return False;
        }
@@ -280,8 +268,14 @@ BOOL pdb_getsampwnam(struct samu *sam_acct, const char *username)
 
        pdb_force_pw_initialization( sam_acct );
        
-       if ( (csamuser = samu_new( NULL )) != NULL ) {
-               pdb_copy_sam_account(csamuser, sam_acct);
+       csamuser = samu_new( NULL );
+       if (!csamuser) {
+               return False;
+       }
+
+       if (!pdb_copy_sam_account(csamuser, sam_acct)) {
+               TALLOC_FREE(csamuser);
+               return False;
        }
 
        return True;
@@ -314,13 +308,9 @@ BOOL guest_user_info( struct samu *user )
 
 BOOL pdb_getsampwsid(struct samu *sam_acct, const DOM_SID *sid) 
 {
-       struct pdb_methods *pdb;
+       struct pdb_methods *pdb = pdb_get_methods();
        uint32 rid;
 
-       if ( !(pdb = pdb_get_methods()) ) {
-               return False;
-       }
-
        /* hard code the Guest RID of 501 */
 
        if ( !sid_peek_check_rid( get_global_sam_sid(), sid, &rid ) )
@@ -354,6 +344,7 @@ static NTSTATUS pdb_default_create_user(struct pdb_methods *methods,
        if ( !(pwd = Get_Pwnam_alloc(tmp_ctx, name)) ) {
                pstring add_script;
                int add_ret;
+               fstring name2;
 
                if ((acb_info & ACB_NORMAL) && name[strlen(name)-1] != '$') {
                        pstrcpy(add_script, lp_adduser_script());
@@ -367,10 +358,23 @@ static NTSTATUS pdb_default_create_user(struct pdb_methods *methods,
                        return NT_STATUS_NO_SUCH_USER;
                }
 
-               all_string_sub(add_script, "%u", name, sizeof(add_script));
+               /* lowercase the username before creating the Unix account for 
+                  compatibility with previous Samba releases */
+               fstrcpy( name2, name );
+               strlower_m( name2 );
+               all_string_sub(add_script, "%u", name2, sizeof(add_script));
                add_ret = smbrun(add_script,NULL);
                DEBUG(add_ret ? 0 : 3, ("_samr_create_user: Running the command `%s' gave %d\n",
                                        add_script, add_ret));
+
+#ifdef ENABLE_BUILD_FARM_HACKS
+               if (add_ret != 0) {
+                       DEBUG(1, ("Creating a faked user %s for build farm "
+                                 "purposes", name));
+                       faked_create_user(name);
+               }
+#endif
+
                flush_pwnam_cache();
 
                pwd = Get_Pwnam_alloc(tmp_ctx, name);
@@ -393,6 +397,10 @@ static NTSTATUS pdb_default_create_user(struct pdb_methods *methods,
                return NT_STATUS_INTERNAL_ERROR;
        }
 
+       /* Use the username case specified in the original request */
+
+       pdb_set_username( sam_pass, name, PDB_SET );
+
        /* Disable the account on creation, it does not have a reasonable password yet. */
 
        acb_info |= ACB_DISABLED;
@@ -410,11 +418,6 @@ NTSTATUS pdb_create_user(TALLOC_CTX *mem_ctx, const char *name, uint32 flags,
                         uint32 *rid)
 {
        struct pdb_methods *pdb = pdb_get_methods();
-
-       if ( !pdb ) {
-               return NT_STATUS_UNSUCCESSFUL;
-       }
-
        return pdb->create_user(pdb, mem_ctx, name, flags, rid);
 }
 
@@ -450,6 +453,7 @@ static NTSTATUS pdb_default_delete_user(struct pdb_methods *methods,
                                        struct samu *sam_acct)
 {
        NTSTATUS status;
+       fstring username;
 
        status = pdb_delete_sam_account(sam_acct);
        if (!NT_STATUS_IS_OK(status)) {
@@ -462,7 +466,14 @@ static NTSTATUS pdb_default_delete_user(struct pdb_methods *methods,
         * not necessary present and maybe the sysadmin doesn't want to delete
         * the unix side
         */
-       smb_delete_user( pdb_get_username(sam_acct) );
+
+       /* always lower case the username before handing it off to 
+          external scripts */
+
+       fstrcpy( username, pdb_get_username(sam_acct) );
+       strlower_m( username );
+
+       smb_delete_user( username );
        
        return status;
 }
@@ -472,10 +483,6 @@ NTSTATUS pdb_delete_user(TALLOC_CTX *mem_ctx, struct samu *sam_acct)
        struct pdb_methods *pdb = pdb_get_methods();
        uid_t uid = -1;
 
-       if ( !pdb ) {
-               return NT_STATUS_UNSUCCESSFUL;
-       }
-
        /* sanity check to make sure we don't delete root */
 
        if ( !sid_to_uid( pdb_get_user_sid(sam_acct), &uid ) ) {
@@ -492,11 +499,6 @@ NTSTATUS pdb_delete_user(TALLOC_CTX *mem_ctx, struct samu *sam_acct)
 NTSTATUS pdb_add_sam_account(struct samu *sam_acct) 
 {
        struct pdb_methods *pdb = pdb_get_methods();
-
-       if ( !pdb ) {
-               return NT_STATUS_UNSUCCESSFUL;
-       }
-       
        return pdb->add_sam_account(pdb, sam_acct);
 }
 
@@ -504,10 +506,6 @@ NTSTATUS pdb_update_sam_account(struct samu *sam_acct)
 {
        struct pdb_methods *pdb = pdb_get_methods();
 
-       if ( !pdb ) {
-               return NT_STATUS_UNSUCCESSFUL;
-       }
-
        if (csamuser != NULL) {
                TALLOC_FREE(csamuser);
                csamuser = NULL;
@@ -520,10 +518,6 @@ NTSTATUS pdb_delete_sam_account(struct samu *sam_acct)
 {
        struct pdb_methods *pdb = pdb_get_methods();
 
-       if ( !pdb ) {
-               return NT_STATUS_UNSUCCESSFUL;
-       }
-
        if (csamuser != NULL) {
                TALLOC_FREE(csamuser);
                csamuser = NULL;
@@ -536,10 +530,7 @@ NTSTATUS pdb_rename_sam_account(struct samu *oldname, const char *newname)
 {
        struct pdb_methods *pdb = pdb_get_methods();
        uid_t uid;
-
-       if ( !pdb ) {
-               return NT_STATUS_NOT_IMPLEMENTED;
-       }
+       NTSTATUS status;
 
        if (csamuser != NULL) {
                TALLOC_FREE(csamuser);
@@ -556,50 +547,35 @@ NTSTATUS pdb_rename_sam_account(struct samu *oldname, const char *newname)
                return NT_STATUS_ACCESS_DENIED;
        }
 
-       return pdb->rename_sam_account(pdb, oldname, newname);
+       status = pdb->rename_sam_account(pdb, oldname, newname);
+
+       /* always flush the cache here just to be safe */
+       flush_pwnam_cache();
+
+       return status;
 }
 
 NTSTATUS pdb_update_login_attempts(struct samu *sam_acct, BOOL success)
 {
        struct pdb_methods *pdb = pdb_get_methods();
-
-       if ( !pdb ) {
-               return NT_STATUS_NOT_IMPLEMENTED;
-       }
-
        return pdb->update_login_attempts(pdb, sam_acct, success);
 }
 
 BOOL pdb_getgrsid(GROUP_MAP *map, DOM_SID sid)
 {
        struct pdb_methods *pdb = pdb_get_methods();
-
-       if ( !pdb ) {
-               return False;
-       }
-
        return NT_STATUS_IS_OK(pdb->getgrsid(pdb, map, sid));
 }
 
 BOOL pdb_getgrgid(GROUP_MAP *map, gid_t gid)
 {
        struct pdb_methods *pdb = pdb_get_methods();
-
-       if ( !pdb ) {
-               return False;
-       }
-
        return NT_STATUS_IS_OK(pdb->getgrgid(pdb, map, gid));
 }
 
 BOOL pdb_getgrnam(GROUP_MAP *map, const char *name)
 {
        struct pdb_methods *pdb = pdb_get_methods();
-
-       if ( !pdb ) {
-               return False;
-       }
-
        return NT_STATUS_IS_OK(pdb->getgrnam(pdb, map, name));
 }
 
@@ -645,11 +621,6 @@ NTSTATUS pdb_create_dom_group(TALLOC_CTX *mem_ctx, const char *name,
                              uint32 *rid)
 {
        struct pdb_methods *pdb = pdb_get_methods();
-
-       if ( !pdb ) {
-               return NT_STATUS_UNSUCCESSFUL;
-       }
-
        return pdb->create_dom_group(pdb, mem_ctx, name, rid);
 }
 
@@ -704,44 +675,24 @@ static NTSTATUS pdb_default_delete_dom_group(struct pdb_methods *methods,
 NTSTATUS pdb_delete_dom_group(TALLOC_CTX *mem_ctx, uint32 rid)
 {
        struct pdb_methods *pdb = pdb_get_methods();
-
-       if ( !pdb ) {
-               return NT_STATUS_UNSUCCESSFUL;
-       }
-
        return pdb->delete_dom_group(pdb, mem_ctx, rid);
 }
 
 NTSTATUS pdb_add_group_mapping_entry(GROUP_MAP *map)
 {
        struct pdb_methods *pdb = pdb_get_methods();
-
-       if ( !pdb ) {
-               return NT_STATUS_UNSUCCESSFUL;
-       }
-
        return pdb->add_group_mapping_entry(pdb, map);
 }
 
 NTSTATUS pdb_update_group_mapping_entry(GROUP_MAP *map)
 {
        struct pdb_methods *pdb = pdb_get_methods();
-
-       if ( !pdb ) {
-               return NT_STATUS_UNSUCCESSFUL;
-       }
-
        return pdb->update_group_mapping_entry(pdb, map);
 }
 
 NTSTATUS pdb_delete_group_mapping_entry(DOM_SID sid)
 {
        struct pdb_methods *pdb = pdb_get_methods();
-
-       if ( !pdb ) {
-               return NT_STATUS_UNSUCCESSFUL;
-       }
-
        return pdb->delete_group_mapping_entry(pdb, sid);
 }
 
@@ -749,11 +700,6 @@ BOOL pdb_enum_group_mapping(const DOM_SID *sid, enum SID_NAME_USE sid_name_use,
                            size_t *p_num_entries, BOOL unix_only)
 {
        struct pdb_methods *pdb = pdb_get_methods();
-
-       if ( !pdb ) {
-               return False;
-       }
-
        return NT_STATUS_IS_OK(pdb-> enum_group_mapping(pdb, sid, sid_name_use,
                pp_rmap, p_num_entries, unix_only));
 }
@@ -766,10 +712,6 @@ NTSTATUS pdb_enum_group_members(TALLOC_CTX *mem_ctx,
        struct pdb_methods *pdb = pdb_get_methods();
        NTSTATUS result;
 
-       if ( !pdb ) {
-               return NT_STATUS_UNSUCCESSFUL;
-       }
-
        result = pdb->enum_group_members(pdb, mem_ctx, 
                        sid, pp_member_rids, p_num_members);
                
@@ -796,11 +738,6 @@ NTSTATUS pdb_enum_group_memberships(TALLOC_CTX *mem_ctx, struct samu *user,
                                    size_t *p_num_groups)
 {
        struct pdb_methods *pdb = pdb_get_methods();
-
-       if ( !pdb ) {
-               return NT_STATUS_UNSUCCESSFUL;
-       }
-
        return pdb->enum_group_memberships(
                pdb, mem_ctx, user,
                pp_sids, pp_gids, p_num_groups);
@@ -829,11 +766,6 @@ static NTSTATUS pdb_default_set_unix_primary_group(struct pdb_methods *methods,
 NTSTATUS pdb_set_unix_primary_group(TALLOC_CTX *mem_ctx, struct samu *user)
 {
        struct pdb_methods *pdb = pdb_get_methods();
-
-       if ( !pdb ) {
-               return NT_STATUS_UNSUCCESSFUL;
-       }
-
        return pdb->set_unix_primary_group(pdb, mem_ctx, user);
 }
 
@@ -923,11 +855,6 @@ NTSTATUS pdb_add_groupmem(TALLOC_CTX *mem_ctx, uint32 group_rid,
                          uint32 member_rid)
 {
        struct pdb_methods *pdb = pdb_get_methods();
-
-       if ( !pdb ) {
-               return NT_STATUS_UNSUCCESSFUL;
-       }
-
        return pdb->add_groupmem(pdb, mem_ctx, group_rid, member_rid);
 }
 
@@ -990,44 +917,24 @@ NTSTATUS pdb_del_groupmem(TALLOC_CTX *mem_ctx, uint32 group_rid,
                          uint32 member_rid)
 {
        struct pdb_methods *pdb = pdb_get_methods();
-
-       if ( !pdb ) {
-               return NT_STATUS_UNSUCCESSFUL;
-       }
-
        return pdb->del_groupmem(pdb, mem_ctx, group_rid, member_rid);
 }
 
 BOOL pdb_find_alias(const char *name, DOM_SID *sid)
 {
        struct pdb_methods *pdb = pdb_get_methods();
-
-       if ( !pdb ) {
-               return False;
-       }
-
        return NT_STATUS_IS_OK(pdb->find_alias(pdb, name, sid));
 }
 
 NTSTATUS pdb_create_alias(const char *name, uint32 *rid)
 {
        struct pdb_methods *pdb = pdb_get_methods();
-
-       if ( !pdb ) {
-               return NT_STATUS_NOT_IMPLEMENTED;
-       }
-
        return pdb->create_alias(pdb, name, rid);
 }
 
 BOOL pdb_delete_alias(const DOM_SID *sid)
 {
        struct pdb_methods *pdb = pdb_get_methods();
-
-       if ( !pdb ) {
-               return False;
-       }
-
        return NT_STATUS_IS_OK(pdb->delete_alias(pdb, sid));
                                                            
 }
@@ -1035,44 +942,24 @@ BOOL pdb_delete_alias(const DOM_SID *sid)
 BOOL pdb_get_aliasinfo(const DOM_SID *sid, struct acct_info *info)
 {
        struct pdb_methods *pdb = pdb_get_methods();
-
-       if ( !pdb ) {
-               return False;
-       }
-
        return NT_STATUS_IS_OK(pdb->get_aliasinfo(pdb, sid, info));
 }
 
 BOOL pdb_set_aliasinfo(const DOM_SID *sid, struct acct_info *info)
 {
        struct pdb_methods *pdb = pdb_get_methods();
-
-       if ( !pdb ) {
-               return False;
-       }
-
        return NT_STATUS_IS_OK(pdb->set_aliasinfo(pdb, sid, info));
 }
 
 NTSTATUS pdb_add_aliasmem(const DOM_SID *alias, const DOM_SID *member)
 {
        struct pdb_methods *pdb = pdb_get_methods();
-
-       if ( !pdb ) {
-               return NT_STATUS_UNSUCCESSFUL;
-       }
-
        return pdb->add_aliasmem(pdb, alias, member);
 }
 
 NTSTATUS pdb_del_aliasmem(const DOM_SID *alias, const DOM_SID *member)
 {
        struct pdb_methods *pdb = pdb_get_methods();
-
-       if ( !pdb ) {
-               return NT_STATUS_UNSUCCESSFUL;
-       }
-
        return pdb->del_aliasmem(pdb, alias, member);
 }
 
@@ -1080,13 +967,7 @@ NTSTATUS pdb_enum_aliasmem(const DOM_SID *alias,
                           DOM_SID **pp_members, size_t *p_num_members)
 {
        struct pdb_methods *pdb = pdb_get_methods();
-
-       if ( !pdb ) {
-               return NT_STATUS_UNSUCCESSFUL;
-       }
-
-       return pdb->enum_aliasmem(pdb, alias,
-                                             pp_members, p_num_members);
+       return pdb->enum_aliasmem(pdb, alias, pp_members, p_num_members);
 }
 
 NTSTATUS pdb_enum_alias_memberships(TALLOC_CTX *mem_ctx,
@@ -1096,11 +977,6 @@ NTSTATUS pdb_enum_alias_memberships(TALLOC_CTX *mem_ctx,
                                    size_t *p_num_alias_rids)
 {
        struct pdb_methods *pdb = pdb_get_methods();
-
-       if ( !pdb ) {
-               return NT_STATUS_NOT_IMPLEMENTED;
-       }
-
        return pdb->enum_alias_memberships(pdb, mem_ctx,
                                                       domain_sid,
                                                       members, num_members,
@@ -1112,86 +988,49 @@ NTSTATUS pdb_lookup_rids(const DOM_SID *domain_sid,
                         int num_rids,
                         uint32 *rids,
                         const char **names,
-                        uint32 *attrs)
+                        enum SID_NAME_USE *attrs)
 {
        struct pdb_methods *pdb = pdb_get_methods();
-
-       if ( !pdb ) {
-               return NT_STATUS_NOT_IMPLEMENTED;
-       }
-
-       return pdb->lookup_rids(pdb, domain_sid,
-                                           num_rids, rids, names, attrs);
+       return pdb->lookup_rids(pdb, domain_sid, num_rids, rids, names, attrs);
 }
 
 NTSTATUS pdb_lookup_names(const DOM_SID *domain_sid,
                          int num_names,
                          const char **names,
                          uint32 *rids,
-                         uint32 *attrs)
+                         enum SID_NAME_USE *attrs)
 {
        struct pdb_methods *pdb = pdb_get_methods();
-
-       if ( !pdb ) {
-               return NT_STATUS_NOT_IMPLEMENTED;
-       }
-
-       return pdb->lookup_names(pdb, domain_sid,
-                                            num_names, names, rids, attrs);
+       return pdb->lookup_names(pdb, domain_sid, num_names, names, rids, attrs);
 }
 
 BOOL pdb_get_account_policy(int policy_index, uint32 *value)
 {
        struct pdb_methods *pdb = pdb_get_methods();
-
-       if ( !pdb ) {
-               return False;
-       }
-
        return NT_STATUS_IS_OK(pdb->get_account_policy(pdb, policy_index, value));
 }
 
 BOOL pdb_set_account_policy(int policy_index, uint32 value)
 {
        struct pdb_methods *pdb = pdb_get_methods();
-
-       if ( !pdb ) {
-               return False;
-       }
-
        return NT_STATUS_IS_OK(pdb->set_account_policy(pdb, policy_index, value));
 }
 
 BOOL pdb_get_seq_num(time_t *seq_num)
 {
        struct pdb_methods *pdb = pdb_get_methods();
-
-       if ( !pdb ) {
-               return False;
-       }
-
        return NT_STATUS_IS_OK(pdb->get_seq_num(pdb, seq_num));
 }
 
 BOOL pdb_uid_to_rid(uid_t uid, uint32 *rid)
 {
        struct pdb_methods *pdb = pdb_get_methods();
-
-       if ( !pdb ) {
-               return False;
-       }
-
        return pdb->uid_to_rid(pdb, uid, rid);
 }
 
 BOOL pdb_gid_to_sid(gid_t gid, DOM_SID *sid)
 {
        struct pdb_methods *pdb = pdb_get_methods();
-
-       if ( !pdb ) {
-               return False;
-       }
-
        return pdb->gid_to_sid(pdb, gid, sid);
 }
 
@@ -1199,22 +1038,12 @@ BOOL pdb_sid_to_id(const DOM_SID *sid, union unid_t *id,
                   enum SID_NAME_USE *type)
 {
        struct pdb_methods *pdb = pdb_get_methods();
-
-       if ( !pdb ) {
-               return False;
-       }
-
        return pdb->sid_to_id(pdb, sid, id, type);
 }
 
 BOOL pdb_rid_algorithm(void)
 {
        struct pdb_methods *pdb = pdb_get_methods();
-
-       if ( !pdb ) {
-               return False;
-       }
-
        return pdb->rid_algorithm(pdb);
 }
 
@@ -1234,10 +1063,6 @@ BOOL pdb_new_rid(uint32 *rid)
        int i;
        TALLOC_CTX *ctx;
 
-       if ( !pdb ) {
-               return False;
-       }
-
        if (pdb_rid_algorithm()) {
                DEBUG(0, ("Trying to allocate a RID when algorithmic RIDs "
                          "are active\n"));
@@ -1675,6 +1500,11 @@ static BOOL lookup_global_sam_rid(TALLOC_CTX *mem_ctx, uint32 rid,
 
                unbecome_root();                /* -----> EXIT BECOME_ROOT() */
                *name = talloc_strdup(mem_ctx, pdb_get_username(sam_account));
+               if (!*name) {
+                       TALLOC_FREE(sam_account);
+                       return False;
+               }
+
                *psid_name_use = SID_NAME_USER;
 
                TALLOC_FREE(sam_account);
@@ -1733,7 +1563,7 @@ NTSTATUS pdb_default_lookup_rids(struct pdb_methods *methods,
                                 int num_rids,
                                 uint32 *rids,
                                 const char **names,
-                                uint32 *attrs)
+                                enum SID_NAME_USE *attrs)
 {
        int i;
        NTSTATUS result;
@@ -1796,7 +1626,7 @@ NTSTATUS pdb_default_lookup_names(struct pdb_methods *methods,
                                  int num_names,
                                  const char **names,
                                  uint32 *rids,
-                                 uint32 *attrs)
+                                 enum SID_NAME_USE *attrs)
 {
        int i;
        NTSTATUS result;
@@ -1913,7 +1743,7 @@ struct user_search {
 static BOOL next_entry_users(struct pdb_search *s,
                             struct samr_displayentry *entry)
 {
-       struct user_search *state = s->private_data;
+       struct user_search *state = (struct user_search *)s->private_data;
        struct samu *user = NULL;
 
  next:
@@ -1988,7 +1818,7 @@ struct group_search {
 static BOOL next_entry_groups(struct pdb_search *s,
                              struct samr_displayentry *entry)
 {
-       struct group_search *state = s->private_data;
+       struct group_search *state = (struct group_search *)s->private_data;
        uint32 rid;
        GROUP_MAP *map = &state->groups[state->current_group];
 
@@ -2006,7 +1836,8 @@ static BOOL next_entry_groups(struct pdb_search *s,
 
 static void search_end_groups(struct pdb_search *search)
 {
-       struct group_search *state = search->private_data;
+       struct group_search *state =
+               (struct group_search *)search->private_data;
        SAFE_FREE(state->groups);
 }
 
@@ -2079,10 +1910,10 @@ struct pdb_search *pdb_search_users(uint32 acct_flags)
        struct pdb_methods *pdb = pdb_get_methods();
        struct pdb_search *result;
 
-       if (pdb == NULL) return NULL;
-
        result = pdb_search_init(PDB_USER_SEARCH);
-       if (result == NULL) return NULL;
+       if (result == NULL) {
+               return NULL;
+       }
 
        if (!pdb->search_users(pdb, result, acct_flags)) {
                talloc_destroy(result->mem_ctx);
@@ -2096,10 +1927,10 @@ struct pdb_search *pdb_search_groups(void)
        struct pdb_methods *pdb = pdb_get_methods();
        struct pdb_search *result;
 
-       if (pdb == NULL) return NULL;
-
        result = pdb_search_init(PDB_GROUP_SEARCH);
-       if (result == NULL) return NULL;
+       if (result == NULL) {
+                return NULL;
+       }
 
        if (!pdb->search_groups(pdb, result)) {
                talloc_destroy(result->mem_ctx);