And finally IDMAP in 3_0
[amitay/samba.git] / source3 / passdb / pdb_nisplus.c
index 484e8986e42f57fa64ddd01fd04df6b3e8332014..4e4aaed02b2f9c02187bf64fb8f12bdce3762575 100644 (file)
@@ -24,8 +24,6 @@
 
 #include "includes.h"
 
-#ifdef WITH_NISPLUS_SAM
-
 #ifdef BROKEN_NISPLUS_INCLUDE_FILES
 
 /*
@@ -130,7 +128,7 @@ static nis_result *nisp_get_nis_list (const char *nisname,
  Start enumeration of the passwd list.
 ****************************************************************/
 
-static BOOL nisplussam_setsampwent (struct pdb_methods *methods, BOOL update)
+static NTSTATUS nisplussam_setsampwent (struct pdb_methods *methods, BOOL update)
 {
        struct nisplus_private_info *private =
                (struct nisplus_private_info *) methods->private_data;
@@ -148,7 +146,10 @@ static BOOL nisplussam_setsampwent (struct pdb_methods *methods, BOOL update)
        pdb_endsampwent ();     /* just in case */
        global_nisp_ent->result = nisp_get_nis_list (pfiletmp, 0);
        global_nisp_ent->enum_entry = 0;
-       return global_nisp_ent->result != NULL ? True : False;
+       if (global_nisp_ent->result != NULL) 
+               return NT_STATUS_UNSUCCESSFUL;
+       else
+               return NT_STATUS_OK;
 }
 
 /***************************************************************
@@ -169,10 +170,10 @@ static void nisplussam_endsampwent (struct pdb_methods *methods)
  Get one SAM_ACCOUNT from the list (next in line)
 *****************************************************************/
 
-static BOOL nisplussam_getsampwent (struct pdb_methods *methods,
+static NTSTATUS nisplussam_getsampwent (struct pdb_methods *methods,
                                    SAM_ACCOUNT * user)
 {
-
+       NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
        struct nisplus_private_info *global_nisp_ent =
                (struct nisplus_private_info *) methods->private_data;
        int enum_entry = (int) (global_nisp_ent->enum_entry);
@@ -180,33 +181,31 @@ static BOOL nisplussam_getsampwent (struct pdb_methods *methods,
 
        if (user == NULL) {
                DEBUG (0, ("SAM_ACCOUNT is NULL.\n"));
-               return False;
+               return nt_status;
        }
 
-       if (result == NULL ||
-           enum_entry < 0 || enum_entry >= (NIS_RES_NUMOBJ (result) - 1)) {
-               return False;
+       if (result == NULL || enum_entry < 0 || enum_entry >= (NIS_RES_NUMOBJ (result) - 1)) {
+               return nt_status;
        }
 
-       if (!make_sam_from_nisp_object
-           (user, &NIS_RES_OBJECT (result)[enum_entry])) {
+       if (!make_sam_from_nisp_object(user, &NIS_RES_OBJECT (result)[enum_entry])) {
                DEBUG (0, ("Bad SAM_ACCOUNT entry returned from NIS+!\n"));
-               return False;
+               return nt_status;
        }
        (int) (global_nisp_ent->enum_entry)++;
-       return True;
-       DEBUG (10, ("nisplussam_getsampwent called\n"));
-       return False;
+
+       return nt_status;
 }
 
 /******************************************************************
  Lookup a name in the SAM database
 ******************************************************************/
 
-static BOOL nisplussam_getsampwnam (struct pdb_methods *methods,
+static NTSTATUS nisplussam_getsampwnam (struct pdb_methods *methods,
                                    SAM_ACCOUNT * user, const char *sname)
 {
        /* Static buffers we will return. */
+       NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
        nis_result *result = NULL;
        pstring nisname;
        BOOL ret;
@@ -215,7 +214,7 @@ static BOOL nisplussam_getsampwnam (struct pdb_methods *methods,
 
        if (!private->location || !(*private->location)) {
                DEBUG (0, ("No SMB password file set\n"));
-               return False;
+               return nt_status;
        }
        if (strrchr (private->location, '/'))
                private->location = strrchr (private->location, '/') + 1;
@@ -227,25 +226,25 @@ static BOOL nisplussam_getsampwnam (struct pdb_methods *methods,
        /* Search the table. */
 
        if (!(result = nisp_get_nis_list (nisname, 0))) {
-               return False;
+               return nt_status;
        }
 
        ret = make_sam_from_nisresult (user, result);
        nis_freeresult (result);
 
-       return ret;
+       if (ret) nt_status = NT_STATUS_OK;
 
-       DEBUG (10, ("nisplussam_getsampwnam called\n"));
-       return False;
+       return nt_status;
 }
 
 /***************************************************************************
  Search by sid
  **************************************************************************/
 
-static BOOL nisplussam_getsampwrid (struct pdb_methods *methods,
+static NTSTATUS nisplussam_getsampwrid (struct pdb_methods *methods,
                                    SAM_ACCOUNT * user, uint32 rid)
 {
+       NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
        nis_result *result;
        char *nisname;
        BOOL ret;
@@ -256,7 +255,7 @@ static BOOL nisplussam_getsampwrid (struct pdb_methods *methods,
 
        if (!private->location || !(*private->location)) {
                DEBUG (0, ("no SMB password file set\n"));
-               return False;
+               return nt_status;
        }
 
        if ((sp = strrchr (private->location, '/')))
@@ -273,22 +272,24 @@ static BOOL nisplussam_getsampwrid (struct pdb_methods *methods,
        /* Search the table. */
 
        if (!(result = nisp_get_nis_list (nisname, 0))) {
-               return False;
+               return nt_status;
        }
 
        ret = make_sam_from_nisresult (user, result);
        nis_freeresult (result);
 
-       return ret;
+       if (ret) nt_status = NT_STATUS_OK;
+
+       return nt_status;
 }
 
-static BOOL nisplussam_getsampwsid (struct pdb_methods *methods,
+static NTSTATUS nisplussam_getsampwsid (struct pdb_methods *methods,
                                    SAM_ACCOUNT * user, const DOM_SID * sid)
 {
        uint32 rid;
 
        if (!sid_peek_check_rid (get_global_sam_sid (), sid, &rid))
-               return False;
+               return NT_STATUS_UNSUCCESSFUL;
        return nisplussam_getsampwrid (methods, user, rid);
 }
 
@@ -298,9 +299,10 @@ static BOOL nisplussam_getsampwsid (struct pdb_methods *methods,
  Delete a SAM_ACCOUNT
 ****************************************************************************/
 
-static BOOL nisplussam_delete_sam_account (struct pdb_methods *methods,
-                                          SAM_ACCOUNT * user)
+static NTSTATUS nisplussam_delete_sam_account (struct pdb_methods *methods,
+                                               SAM_ACCOUNT * user)
 {
+       NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
        const char *sname;
        pstring nisname;
        nis_result *result, *delresult;
@@ -310,14 +312,14 @@ static BOOL nisplussam_delete_sam_account (struct pdb_methods *methods,
 
        if (!user) {
                DEBUG (0, ("no SAM_ACCOUNT specified!\n"));
-               return False;
+               return nt_status;
        }
 
        sname = pdb_get_username (user);
 
        if (!private->location || !(*private->location)) {
                DEBUG (0, ("no SMB password file set\n"));
-               return False;
+               return nt_status;
        }
 
        if (strrchr (private->location, '/'))
@@ -332,14 +334,14 @@ static BOOL nisplussam_delete_sam_account (struct pdb_methods *methods,
                                          MASTER_ONLY | FOLLOW_LINKS |
                                          FOLLOW_PATH | EXPAND_NAME |
                                          HARD_LOOKUP))) {
-               return False;
+               return nt_status;
        }
 
        if (result->status != NIS_SUCCESS || NIS_RES_NUMOBJ (result) <= 0) {
                /* User not found. */
                DEBUG (0, ("user not found in NIS+\n"));
                nis_freeresult (result);
-               return False;
+               return nt_status;
        }
 
        obj = NIS_RES_OBJECT (result);
@@ -358,21 +360,21 @@ static BOOL nisplussam_delete_sam_account (struct pdb_methods *methods,
                DEBUG (0, ("NIS+ table update failed: %s %s\n",
                           nisname, nis_sperrno (delresult->status)));
                nis_freeresult (delresult);
-               return False;
+               return nt_status;
        }
        nis_freeresult (delresult);
-       return True;
-       DEBUG (10, ("nisplussam_delete_sam_account called\n"));
-       return False;
+
+       return NT_STATUS_OK;
 }
 
 /***************************************************************************
  Modifies an existing SAM_ACCOUNT
 ****************************************************************************/
 
-static BOOL nisplussam_update_sam_account (struct pdb_methods *methods,
+static NTSTATUS nisplussam_update_sam_account (struct pdb_methods *methods,
                                           SAM_ACCOUNT * newpwd)
 {
+       NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
        nis_result *result, *addresult;
        nis_object *obj;
        nis_object new_obj;
@@ -384,7 +386,7 @@ static BOOL nisplussam_update_sam_account (struct pdb_methods *methods,
 
        if (!private->location || !(*private->location)) {
                DEBUG (0, ("no SMB password file set\n"));
-               return False;
+               return nt_status;
        }
        if (strrchr (private->location, '/'))
                private->location = strrchr (private->location, '/') + 1;
@@ -401,14 +403,14 @@ static BOOL nisplussam_update_sam_account (struct pdb_methods *methods,
             nisp_get_nis_list (nisname,
                                MASTER_ONLY | FOLLOW_LINKS | FOLLOW_PATH |
                                EXPAND_NAME | HARD_LOOKUP))) {
-               return False;
+               return ne_status;
        }
 
        if (result->status != NIS_SUCCESS || NIS_RES_NUMOBJ (result) <= 0) {
                /* User not found. */
                DEBUG (0, ("user not found in NIS+\n"));
                nis_freeresult (result);
-               return False;
+               return nt_status;
        }
 
        obj = NIS_RES_OBJECT (result);
@@ -425,7 +427,7 @@ static BOOL nisplussam_update_sam_account (struct pdb_methods *methods,
        if (!(ecol = (entry_col *) malloc (ta_maxcol * sizeof (entry_col)))) {
                DEBUG (0, ("memory allocation failure\n"));
                nis_freeresult (result);
-               return False;
+               return nt_status;
        }
 
        memmove ((char *) ecol, obj->EN_data.en_cols.en_cols_val,
@@ -449,7 +451,7 @@ static BOOL nisplussam_update_sam_account (struct pdb_methods *methods,
                        nis_freeresult (addresult);
                        nis_freeresult (result);
                        free (ecol);
-                       return False;
+                       return nt_status;
                }
 
                DEBUG (6, ("password changed\n"));
@@ -461,16 +463,17 @@ static BOOL nisplussam_update_sam_account (struct pdb_methods *methods,
        free (ecol);
        nis_freeresult (result);
 
-       return True;
+       return NT_STATUS_OK;
 }
 
 /***************************************************************************
  Adds an existing SAM_ACCOUNT
 ****************************************************************************/
 
-static BOOL nisplussam_add_sam_account (struct pdb_methods *methods,
+static NTSTATUS nisplussam_add_sam_account (struct pdb_methods *methods,
                                        SAM_ACCOUNT * newpwd)
 {
+       NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
        int local_user = 0;
        char *pfile;
        pstring pfiletmp;
@@ -518,7 +521,7 @@ static BOOL nisplussam_add_sam_account (struct pdb_methods *methods,
                nisname = make_nisname_from_name (pdb_get_username (newpwd),
                                                  pfiletmp);
        } else {
-               return False;
+               return nt_status;
        }
 
        if (!
@@ -526,20 +529,20 @@ static BOOL nisplussam_add_sam_account (struct pdb_methods *methods,
             nisp_get_nis_list (nisname,
                                MASTER_ONLY | FOLLOW_LINKS | FOLLOW_PATH |
                                EXPAND_NAME | HARD_LOOKUP))) {
-               return False;
+               return nt_status;
        }
        if (result->status != NIS_SUCCESS && result->status != NIS_NOTFOUND) {
                DEBUG (3, ("nis_list failure: %s: %s\n",
                           nisname, nis_sperrno (result->status)));
                nis_freeresult (result);
-               return False;
+               return nt_status;
        }
 
        if (result->status == NIS_SUCCESS && NIS_RES_NUMOBJ (result) > 0) {
                DEBUG (3, ("User already exists in NIS+ password db: %s\n",
                           pfile));
                nis_freeresult (result);
-               return False;
+               return nt_status;
        }
 
        nis_freeresult (result);        /* no such user, free results */
@@ -565,7 +568,7 @@ static BOOL nisplussam_add_sam_account (struct pdb_methods *methods,
 
                if (!(passwd = getpwnam_alloc (pdb_get_username (newpwd)))) {
                        /* no such user in system! */
-                       return False;
+                       return nt_status;
                }
                passwd_free (&passwd);
 
@@ -607,7 +610,7 @@ static BOOL nisplussam_add_sam_account (struct pdb_methods *methods,
                        nis_freeresult (tblresult);
                        DEBUG (3, ("nis_lookup failure: %s\n",
                                   nis_sperrno (tblresult->status)));
-                       return False;
+                       return nt_status;
                }
                /* we need full name for nis_add_entry() */
                safe_strcpy (pfiletmp, pfile, sizeof (pfiletmp) - 1);
@@ -636,7 +639,7 @@ static BOOL nisplussam_add_sam_account (struct pdb_methods *methods,
        if (!(ecol = (entry_col *) malloc (ta_maxcol * sizeof (entry_col)))) {
                DEBUG (0, ("memory allocation failure\n"));
                nis_freeresult (tblresult);
-               return False;
+               return nt_status;
        }
 
        memset ((char *) ecol, 0, ta_maxcol * sizeof (entry_col));
@@ -655,13 +658,13 @@ static BOOL nisplussam_add_sam_account (struct pdb_methods *methods,
                           nisname, nis_sperrno (result->status)));
                nis_freeresult (tblresult);
                nis_freeresult (result);
-               return False;
+               return nt_status;
        }
 
        nis_freeresult (tblresult);
        nis_freeresult (result);
 
-       return True;
+       return NT_STATUS_OK;
 }
 
 /***************************************************************
@@ -740,7 +743,7 @@ static BOOL make_sam_from_nisp_object (SAM_ACCOUNT * pw_buf,
        /* Don't change these timestamp settings without a good reason.  They are
           important for NT member server compatibility. */
 
-       pdb_set_logon_time (pw_buf, (time_t) 0, True);
+       pdb_set_logon_time (pw_buf, (time_t) 0, PDB_DEFAULT);
        ptr = (uchar *) ENTRY_VAL (obj, NPF_LOGON_T);
        if (ptr && *ptr && (StrnCaseCmp (ptr, "LNT-", 4) == 0)) {
                int i;
@@ -753,11 +756,11 @@ static BOOL make_sam_from_nisp_object (SAM_ACCOUNT * pw_buf,
                if (i == 8) {
                        pdb_set_logon_time (pw_buf,
                                            (time_t) strtol (ptr, NULL, 16),
-                                           True);
+                                           PDB_SET);
                }
        }
 
-       pdb_set_logoff_time (pw_buf, get_time_t_max (), True);
+       pdb_set_logoff_time (pw_buf, get_time_t_max (), PDB_DEFAULT);
        ptr = (uchar *) ENTRY_VAL (obj, NPF_LOGOFF_T);
        if (ptr && *ptr && (StrnCaseCmp (ptr, "LOT-", 4) == 0)) {
                int i;
@@ -770,11 +773,11 @@ static BOOL make_sam_from_nisp_object (SAM_ACCOUNT * pw_buf,
                if (i == 8) {
                        pdb_set_logoff_time (pw_buf,
                                             (time_t) strtol (ptr, NULL, 16),
-                                            True);
+                                            PDB_SET);
                }
        }
 
-       pdb_set_kickoff_time (pw_buf, get_time_t_max (), True);
+       pdb_set_kickoff_time (pw_buf, get_time_t_max (), PDB_DEFAULT);
        ptr = (uchar *) ENTRY_VAL (obj, NPF_KICK_T);
        if (ptr && *ptr && (StrnCaseCmp (ptr, "KOT-", 4) == 0)) {
                int i;
@@ -787,11 +790,11 @@ static BOOL make_sam_from_nisp_object (SAM_ACCOUNT * pw_buf,
                if (i == 8) {
                        pdb_set_kickoff_time (pw_buf,
                                              (time_t) strtol (ptr, NULL, 16),
-                                             True);
+                                             PDB_SET);
                }
        }
 
-       pdb_set_pass_last_set_time (pw_buf, (time_t) 0);
+       pdb_set_pass_last_set_time (pw_buf, (time_t) 0, PDB_DEFAULT);
        ptr = (uchar *) ENTRY_VAL (obj, NPF_PWDLSET_T);
        if (ptr && *ptr && (StrnCaseCmp (ptr, "LCT-", 4) == 0)) {
                int i;
@@ -805,11 +808,12 @@ static BOOL make_sam_from_nisp_object (SAM_ACCOUNT * pw_buf,
                        pdb_set_pass_last_set_time (pw_buf,
                                                    (time_t) strtol (ptr,
                                                                     NULL,
-                                                                    16));
+                                                                    16),
+                                                    PDB_SET);
                }
        }
 
-       pdb_set_pass_can_change_time (pw_buf, (time_t) 0, True);
+       pdb_set_pass_can_change_time (pw_buf, (time_t) 0, PDB_DEFAULT);
        ptr = (uchar *) ENTRY_VAL (obj, NPF_PWDCCHG_T);
        if (ptr && *ptr && (StrnCaseCmp (ptr, "CCT-", 4) == 0)) {
                int i;
@@ -824,11 +828,11 @@ static BOOL make_sam_from_nisp_object (SAM_ACCOUNT * pw_buf,
                                                      (time_t) strtol (ptr,
                                                                       NULL,
                                                                       16),
-                                                     True);
+                                                     PDB_SET);
                }
        }
 
-       pdb_set_pass_must_change_time (pw_buf, get_time_t_max (), True);        /* Password never expires. */
+       pdb_set_pass_must_change_time (pw_buf, get_time_t_max (), PDB_DEFAULT); /* Password never expires. */
        ptr = (uchar *) ENTRY_VAL (obj, NPF_PWDMCHG_T);
        if (ptr && *ptr && (StrnCaseCmp (ptr, "MCT-", 4) == 0)) {
                int i;
@@ -843,13 +847,13 @@ static BOOL make_sam_from_nisp_object (SAM_ACCOUNT * pw_buf,
                                                       (time_t) strtol (ptr,
                                                                        NULL,
                                                                        16),
-                                                      True);
+                                                      PDB_SET);
                }
        }
 
        /* string values */
-       pdb_set_username (pw_buf, ENTRY_VAL (obj, NPF_NAME));
-       pdb_set_domain (pw_buf, lp_workgroup ());
+       pdb_set_username (pw_buf, ENTRY_VAL (obj, NPF_NAME), PDB_SET);
+       pdb_set_domain (pw_buf, lp_workgroup (), PDB_DEFAULT);
        /* pdb_set_nt_username() -- cant set it here... */
 
        get_single_attribute (obj, NPF_FULL_NAME, full_name,
@@ -857,27 +861,25 @@ static BOOL make_sam_from_nisp_object (SAM_ACCOUNT * pw_buf,
 #if 0
        unix_to_dos (full_name, True);
 #endif
-       pdb_set_fullname (pw_buf, full_name);
+       pdb_set_fullname (pw_buf, full_name, PDB_SET);
 
        pdb_set_acct_ctrl (pw_buf, pdb_decode_acct_ctrl (ENTRY_VAL (obj,
-                                                                   NPF_ACB)));
+                                                                   NPF_ACB), PDB_SET));
 
        get_single_attribute (obj, NPF_ACCT_DESC, acct_desc,
                              sizeof (pstring));
 #if 0
        unix_to_dos (acct_desc, True);
 #endif
-       pdb_set_acct_desc (pw_buf, acct_desc);
+       pdb_set_acct_desc (pw_buf, acct_desc, PDB_SET);
 
-       pdb_set_workstations (pw_buf, ENTRY_VAL (obj, NPF_WORKSTATIONS));
-       pdb_set_munged_dial (pw_buf, NULL);
+       pdb_set_workstations (pw_buf, ENTRY_VAL (obj, NPF_WORKSTATIONS), PDB_SET);
+       pdb_set_munged_dial (pw_buf, NULL, PDB_DEFAULT);
 
-       pdb_set_uid (pw_buf, atoi (ENTRY_VAL (obj, NPF_UID)));
-       pdb_set_gid (pw_buf, atoi (ENTRY_VAL (obj, NPF_SMB_GRPID)));
        pdb_set_user_sid_from_rid (pw_buf,
-                                  atoi (ENTRY_VAL (obj, NPF_USER_RID)));
+                                  atoi (ENTRY_VAL (obj, NPF_USER_RID)), PDB_SET);
        pdb_set_group_sid_from_rid (pw_buf,
-                                   atoi (ENTRY_VAL (obj, NPF_GROUP_RID)));
+                                   atoi (ENTRY_VAL (obj, NPF_GROUP_RID)), PDB_SET);
 
        /* values, must exist for user */
        if (!(pdb_get_acct_ctrl (pw_buf) & ACB_WSTRUST)) {
@@ -886,74 +888,75 @@ static BOOL make_sam_from_nisp_object (SAM_ACCOUNT * pw_buf,
                                      sizeof (pstring));
                if (!(home_dir && *home_dir)) {
                        pstrcpy (home_dir, lp_logon_home ());
-                       pdb_set_homedir (pw_buf, home_dir, False);
+                       pdb_set_homedir (pw_buf, home_dir, PDB_DEFAULT);
                } else
-                       pdb_set_homedir (pw_buf, home_dir, True);
+                       pdb_set_homedir (pw_buf, home_dir, PDB_SET);
 
                get_single_attribute (obj, NPF_DIR_DRIVE, home_drive,
                                      sizeof (pstring));
                if (!(home_drive && *home_drive)) {
                        pstrcpy (home_drive, lp_logon_drive ());
-                       pdb_set_dir_drive (pw_buf, home_drive, False);
+                       pdb_set_dir_drive (pw_buf, home_drive, PDB_DEFAULT);
                } else
-                       pdb_set_dir_drive (pw_buf, home_drive, True);
+                       pdb_set_dir_drive (pw_buf, home_drive, PDB_SET);
 
                get_single_attribute (obj, NPF_LOGON_SCRIPT, logon_script,
                                      sizeof (pstring));
                if (!(logon_script && *logon_script)) {
                        pstrcpy (logon_script, lp_logon_script ());
+                       pdb_set_logon_script (pw_buf, logon_script, PDB_DEFAULT);
                } else
-                       pdb_set_logon_script (pw_buf, logon_script, True);
+                       pdb_set_logon_script (pw_buf, logon_script, PDB_SET);
 
                get_single_attribute (obj, NPF_PROFILE_PATH, profile_path,
                                      sizeof (pstring));
                if (!(profile_path && *profile_path)) {
                        pstrcpy (profile_path, lp_logon_path ());
-                       pdb_set_profile_path (pw_buf, profile_path, False);
+                       pdb_set_profile_path (pw_buf, profile_path, PDB_DEFAULT);
                } else
-                       pdb_set_profile_path (pw_buf, profile_path, True);
+                       pdb_set_profile_path (pw_buf, profile_path, PDB_SET);
 
        } else {
                /* lkclXXXX this is OBSERVED behaviour by NT PDCs, enforced here. */
-               pdb_set_group_sid_from_rid (pw_buf, DOMAIN_GROUP_RID_USERS);
+               pdb_set_group_sid_from_rid (pw_buf, DOMAIN_GROUP_RID_USERS, PDB_DEFAULT);
        }
 
        /* Check the lanman password column. */
        ptr = (char *) ENTRY_VAL (obj, NPF_LMPWD);
-       if (!pdb_set_lanman_passwd (pw_buf, NULL))
+       if (!pdb_set_lanman_passwd (pw_buf, NULL, PDB_DEFAULT))
                return False;
 
        if (!strncasecmp (ptr, "NO PASSWORD", 11)) {
                pdb_set_acct_ctrl (pw_buf,
-                                  pdb_get_acct_ctrl (pw_buf) | ACB_PWNOTREQ);
+                                  pdb_get_acct_ctrl (pw_buf) | ACB_PWNOTREQ, PDB_SET);
        } else {
                if (strlen (ptr) != 32 || !pdb_gethexpwd (ptr, smbpwd)) {
                        DEBUG (0, ("malformed LM pwd entry: %s.\n",
                                   pdb_get_username (pw_buf)));
                        return False;
                }
-               if (!pdb_set_lanman_passwd (pw_buf, smbpwd))
+               if (!pdb_set_lanman_passwd (pw_buf, smbpwd, PDB_SET))
                        return False;
        }
 
        /* Check the NT password column. */
        ptr = ENTRY_VAL (obj, NPF_NTPWD);
-       if (!pdb_set_nt_passwd (pw_buf, NULL))
+       if (!pdb_set_nt_passwd (pw_buf, NULL, PDB_DEFAULT))
                return False;
 
        if (!(pdb_get_acct_ctrl (pw_buf) & ACB_PWNOTREQ) &&
            strncasecmp (ptr, "NO PASSWORD", 11)) {
                if (strlen (ptr) != 32 || !pdb_gethexpwd (ptr, smbntpwd)) {
-                       DEBUG (0, ("malformed NT pwd entry:\
uid = %d.\n", pdb_get_uid (pw_buf)));
+                       DEBUG (0, ("malformed NT pwd entry:\ %s.\n",
                                 pdb_get_username (pw_buf)));
                        return False;
                }
-               if (!pdb_set_nt_passwd (pw_buf, smbntpwd))
+               if (!pdb_set_nt_passwd (pw_buf, smbntpwd, PDB_SET))
                        return False;
        }
 
-       pdb_set_unknown_3 (pw_buf, 0xffffff);   /* don't know */
-       pdb_set_logon_divs (pw_buf, 168);       /* hours per week */
+       pdb_set_unknown_3 (pw_buf, 0xffffff, PDB_DEFAULT);      /* don't know */
+       pdb_set_logon_divs (pw_buf, 168, PDB_DEFAULT);  /* hours per week */
 
        if ((hours_len = ENTRY_LEN (obj, NPF_HOURS)) == 21) {
                memcpy (hours, ENTRY_VAL (obj, NPF_HOURS), hours_len);
@@ -962,11 +965,11 @@ static BOOL make_sam_from_nisp_object (SAM_ACCOUNT * pw_buf,
                /* available at all hours */
                memset (hours, 0xff, hours_len);
        }
-       pdb_set_hours_len (pw_buf, hours_len);
-       pdb_set_hours (pw_buf, hours);
+       pdb_set_hours_len (pw_buf, hours_len, PDB_SET);
+       pdb_set_hours (pw_buf, hours, PDB_SET);
 
-       pdb_set_unknown_5 (pw_buf, 0x00020000); /* don't know */
-       pdb_set_unknown_6 (pw_buf, 0x000004ec); /* don't know */
+       pdb_set_unknown_5 (pw_buf, 0x00020000, PDB_DEFAULT);    /* don't know */
+       pdb_set_unknown_6 (pw_buf, 0x000004ec, PDB_DEFAULT);    /* don't know */
 
        return True;
 }
@@ -1042,6 +1045,8 @@ static BOOL init_nisp_from_sam (nis_object * obj, const SAM_ACCOUNT * sampass,
        BOOL need_to_modify = False;
        const char *name = pdb_get_username (sampass);  /* from SAM */
 
+       uint32 u_rid;
+       uint32 g_rid; 
        /* these must be static or allocate and free entry columns! */
        static fstring uid;     /* from SAM */
        static fstring user_rid;        /* from SAM */
@@ -1060,32 +1065,15 @@ static BOOL init_nisp_from_sam (nis_object * obj, const SAM_ACCOUNT * sampass,
        static fstring acct_desc;       /* from SAM */
        static char empty[1];   /* just an empty string */
 
-       slprintf (uid, sizeof (uid) - 1, "%u", pdb_get_uid (sampass));
-       slprintf (user_rid, sizeof (user_rid) - 1, "%u",
-                 pdb_get_user_rid (sampass) ? pdb_get_user_rid (sampass) :
-                 fallback_pdb_uid_to_user_rid (pdb_get_uid (sampass)));
-       slprintf (gid, sizeof (gid) - 1, "%u", pdb_get_gid (sampass));
-
-       {
-               uint32 rid;
-               GROUP_MAP map;
-
-               rid = pdb_get_group_rid (sampass);
-
-               if (rid == 0) {
-                       if (get_group_map_from_gid
-                           (pdb_get_gid (sampass), &map,
-                            MAPPING_WITHOUT_PRIV)) {
-                               if (!sid_peek_check_rid
-                                   (get_global_sam_sid (), &map.sid, &rid))
-                                       return False;
-                       } else
-                               rid = pdb_gid_to_group_rid (pdb_get_gid
-                                                           (sampass));
-               }
+       if (!(u_rid = pdb_get_user_rid (sampass)))
+               return False;
+       if (!(g_rid = pdb_get_group_rid (sampass)))
+               return False;
 
-               slprintf (group_rid, sizeof (group_rid) - 1, "%u", rid);
-       }
+       slprintf (uid, sizeof (uid) - 1, "%u", fallback_pdb_user_rid_to_uid (u_rid));
+       slprintf (user_rid, sizeof (user_rid) - 1, "%u", u_rid);
+       slprintf (gid, sizeof (gid) - 1, "%u", fallback_pdb_group_rid_to_uid (g_rid));
+       slprintf (group_rid, sizeof (group_rid) - 1, "%u", g_rid);
 
        acb = pdb_encode_acct_ctrl (pdb_get_acct_ctrl (sampass),
                                    NEW_PW_FORMAT_SPACE_PADDED_LEN);
@@ -1129,51 +1117,27 @@ static BOOL init_nisp_from_sam (nis_object * obj, const SAM_ACCOUNT * sampass,
 
 
                /* uid */
-               if (pdb_get_uid (sampass) != -1) {
-                       if (!ENTRY_VAL (old, NPF_UID)
-                           || strcmp (ENTRY_VAL (old, NPF_UID), uid)) {
+               if (!ENTRY_VAL (old, NPF_UID) || strcmp (ENTRY_VAL (old, NPF_UID), uid)) {
                                need_to_modify = True;
-                               set_single_attribute (obj, NPF_UID, uid,
-                                                     strlen (uid),
-                                                     EN_MODIFIED);
-                       }
+                               set_single_attribute (obj, NPF_UID, uid, strlen (uid), EN_MODIFIED);
                }
 
                /* user_rid */
-               if (pdb_get_user_rid (sampass)) {
-                       if (!ENTRY_VAL (old, NPF_USER_RID) ||
-                           strcmp (ENTRY_VAL (old, NPF_USER_RID),
-                                   user_rid)) {
+               if (!ENTRY_VAL (old, NPF_USER_RID) || strcmp (ENTRY_VAL (old, NPF_USER_RID), user_rid)) {
                                need_to_modify = True;
-                               set_single_attribute (obj, NPF_USER_RID,
-                                                     user_rid,
-                                                     strlen (user_rid),
-                                                     EN_MODIFIED);
-                       }
+                               set_single_attribute (obj, NPF_USER_RID, user_rid, strlen (user_rid), EN_MODIFIED);
                }
 
                /* smb_grpid */
-               if (pdb_get_gid (sampass) != -1) {
-                       if (!ENTRY_VAL (old, NPF_SMB_GRPID) ||
-                           strcmp (ENTRY_VAL (old, NPF_SMB_GRPID), gid)) {
+               if (!ENTRY_VAL (old, NPF_SMB_GRPID) || strcmp (ENTRY_VAL (old, NPF_SMB_GRPID), gid)) {
                                need_to_modify = True;
-                               set_single_attribute (obj, NPF_SMB_GRPID, gid,
-                                                     strlen (gid),
-                                                     EN_MODIFIED);
-                       }
+                               set_single_attribute (obj, NPF_SMB_GRPID, gid, strlen (gid), EN_MODIFIED);
                }
 
                /* group_rid */
-               if (pdb_get_group_rid (sampass)) {
-                       if (!ENTRY_VAL (old, NPF_GROUP_RID) ||
-                           strcmp (ENTRY_VAL (old, NPF_GROUP_RID),
-                                   group_rid)) {
+               if (!ENTRY_VAL (old, NPF_GROUP_RID) || strcmp (ENTRY_VAL (old, NPF_GROUP_RID), group_rid)) {
                                need_to_modify = True;
-                               set_single_attribute (obj, NPF_GROUP_RID,
-                                                     group_rid,
-                                                     strlen (group_rid),
-                                                     EN_MODIFIED);
-                       }
+                               set_single_attribute (obj, NPF_GROUP_RID, group_rid, strlen (group_rid), EN_MODIFIED);
                }
 
                /* acb */
@@ -1502,6 +1466,19 @@ static nis_result *nisp_get_nis_list (const char *nisname, unsigned int flags)
        return result;
 }
 
+static void free_private_data(void **vp)
+{
+       struct nisplus_private_info **private = (struct nisplus_private_info **)vp;
+
+       if ((*private)->result) {
+               nis_freeresult ((*private)->result);
+       }
+
+       free(*private);
+
+        /* No need to free any further, as it is talloc()ed */
+}
+
 NTSTATUS pdb_init_nisplussam (PDB_CONTEXT * pdb_context,
                              PDB_METHODS ** pdb_method, const char *location)
 {
@@ -1530,16 +1507,13 @@ NTSTATUS pdb_init_nisplussam (PDB_CONTEXT * pdb_context,
        (*pdb_method)->add_sam_account = nisplussam_add_sam_account;
        (*pdb_method)->update_sam_account = nisplussam_update_sam_account;
        (*pdb_method)->delete_sam_account = nisplussam_delete_sam_account;
+       (*pdb_method)->free_private_data = free_private_data;
        (*pdb_method)->private_data = private;
 
        return NT_STATUS_OK;
 }
 
-#else
-NTSTATUS pdb_init_nisplussam (PDB_CONTEXT * c, PDB_METHODS ** m,
-                             const char *l)
+NTSTATUS pdb_nisplus_init(void)
 {
-       DEBUG (0, ("nisplus sam not compiled in!\n"));
-       return NT_STATUS_UNSUCCESSFUL;
+       return smb_register_passdb(PASSDB_INTERFACE_VERSION, "nisplussam", pdb_init_nisplussam);
 }
-#endif /* WITH_NISPLUS_SAM */