performance problems in getsamfilepwuid() with netlogond
Steve Langasek
vorlon at netexpress.net
Wed Aug 16 20:17:52 GMT 2000
Jerry,
> I've got to look at this for another site (it has been
> this way for probably 2 years now). Of course, if you
> want to patch it first, I'm all for that :-)
Well, fixing the code to be a little faster is probably easier in the
short-term than moving our 5000-line smbpasswd file to tdb, and we need this
yesterday, so here's a patch. :)
This adds brains to the getsamfilepwuid() function so that it can call
getsmbfilepwent() directly -- thereby avoiding the potentially costly calls to
pwdb_smb_to_sam() and pwdb_smb_map_names() made by getsamfile21pwent(). Since
getsamfilepwuid() appears to be the only function that calls
getsamfile21pwent() directly, I think this fixes the problem.
Cheers,
Steve Langasek
postmodern programmer
-------------- next part --------------
Index: source/passdb/sampass.c
===================================================================
RCS file: /cvsroot/samba/source/passdb/Attic/sampass.c,v
retrieving revision 1.5.2.10
diff -u -w -r1.5.2.10 sampass.c
--- source/passdb/sampass.c 2000/05/08 07:06:02 1.5.2.10
+++ source/passdb/sampass.c 2000/08/16 19:19:51
@@ -169,8 +169,22 @@
static struct sam_passwd *getsamfilepwuid(uid_t uid)
{
struct sam_passwd *pwd = NULL;
+ struct smb_passwd *smbpw = NULL;
void *fp = NULL;
+ user_struct bogus_user_struct;
+#if 0
+ user_struct *vuser;
+#endif
+ static pstring full_name;
+ static pstring home_dir;
+ static pstring home_drive;
+ static pstring logon_script;
+ static pstring profile_path;
+ static pstring acct_desc;
+ static pstring workstations;
+
+
DEBUG(10, ("search by uid: %x\n", (int)uid));
/* Open the smb password file - not for update. */
@@ -182,8 +196,67 @@
return NULL;
}
- while ((pwd = getsamfile21pwent(fp)) != NULL && pwd->unix_uid != uid)
- {
+ while ((smbpw = getsmbfilepwent(fp)) != NULL) {
+ if (smbpw->unix_uid != uid)
+ continue;
+
+ pwd = pwdb_smb_to_sam(pwdb_smb_map_names(smbpw));
+ if (pwd == NULL)
+ continue;
+
+ /* This is copied whole cloth from getsamfile21pwent() above,
+ but should be much more efficient with flatfiles. */
+#if 0
+ vuser = get_valid_user_struct(get_sec_ctx());
+#endif
+ /* HACK to make %U work in substitutions below */
+ fstrcpy(bogus_user_struct.requested_name, pwd->nt_name);
+ fstrcpy(bogus_user_struct.unix_name , pwd->unix_name);
+ DEBUG(7, ("getsamfilepwuid: nt_name=%s, unix_name=%s\n",
+ pwd->nt_name, pwd->unix_name));
+
+ pstrcpy(full_name , "");
+ pstrcpy(logon_script , lp_logon_script (&bogus_user_struct));
+ pstrcpy(profile_path , lp_logon_path (&bogus_user_struct));
+ pstrcpy(home_drive , lp_logon_drive (&bogus_user_struct));
+ pstrcpy(home_dir , lp_logon_home (&bogus_user_struct));
+ pstrcpy(acct_desc , "");
+ pstrcpy(workstations , "");
+
+#if 0
+ vuid_free_user_struct(vuser);
+#endif
+
+ /*
+ only overwrite values with defaults IIF specific backend
+ didn't filled the values
+ */
+
+ if (string_empty (pwd->full_name))
+ pwd->full_name = full_name;
+ if (string_empty (pwd->home_dir))
+ pwd->home_dir = home_dir;
+ if (string_empty (pwd->dir_drive))
+ pwd->dir_drive = home_drive;
+ if (string_empty (pwd->logon_script))
+ pwd->logon_script = logon_script;
+ if (string_empty (pwd->profile_path))
+ pwd->profile_path = profile_path;
+ if (string_empty (pwd->acct_desc))
+ pwd->acct_desc = acct_desc;
+ if (string_empty (pwd->workstations))
+ pwd->workstations = workstations;
+
+ pwd->unknown_str = NULL; /* don't know, yet! */
+ pwd->munged_dial = NULL; /* "munged" dial-back telephone number */
+
+ pwd->unknown_3 = 0xffffff; /* don't know */
+ pwd->logon_divs = 168; /* hours per week */
+ pwd->hours_len = 21; /* 21 times 8 bits = 168 */
+ memset(pwd->hours, 0xff, pwd->hours_len); /* available at all hours */
+ pwd->unknown_5 = 0x00020000; /* don't know */
+ pwd->unknown_6 = 0x000004ec; /* don't know */
+ break;
}
if (pwd != NULL)
More information about the samba-ntdom
mailing list