2 * Unix SMB/Netbios implementation. Version 1.9. SMB parameters and setup
3 * Copyright (C) Andrew Tridgell 1992-1998 Modified by Jeremy Allison 1995.
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 675
17 * Mass Ave, Cambridge, MA 02139, USA.
24 static int pw_file_lock_depth = 0;
25 extern int DEBUGLEVEL;
26 extern pstring samlogon_user;
27 extern BOOL sam_logon_in_ssb;
29 static char s_readbuf[1024];
31 /***************************************************************
32 Start to enumerate the smbpasswd list. Returns a void pointer
33 to ensure no modification outside this module.
34 ****************************************************************/
36 void *startsmbfilepwent(BOOL update)
38 return startfilepwent(lp_smb_passwd_file(), s_readbuf, sizeof(s_readbuf),
39 &pw_file_lock_depth, update);
42 /***************************************************************
43 End enumeration of the smbpasswd list.
44 ****************************************************************/
46 void endsmbfilepwent(void *vp)
48 endfilepwent(vp, &pw_file_lock_depth);
51 /*************************************************************************
52 Return the current position in the smbpasswd list as an SMB_BIG_UINT.
53 This must be treated as an opaque token.
54 *************************************************************************/
56 SMB_BIG_UINT getsmbfilepwpos(void *vp)
58 return getfilepwpos(vp);
61 /*************************************************************************
62 Set the current position in the smbpasswd list from an SMB_BIG_UINT.
63 This must be treated as an opaque token.
64 *************************************************************************/
66 BOOL setsmbfilepwpos(void *vp, SMB_BIG_UINT tok)
68 return setfilepwpos(vp, tok);
71 /*************************************************************************
72 Routine to return the next entry in the smbpasswd list.
73 *************************************************************************/
74 struct smb_passwd *getsmbfilepwent(void *vp)
76 /* Static buffers we will return. */
77 static struct smb_passwd pw_buf;
78 static pstring user_name;
79 static unsigned char smbpwd[16];
80 static unsigned char smbntpwd[16];
81 struct passwd *pwfile;
89 DEBUG(0,("getsmbfilepwent: Bad password file pointer.\n"));
93 pwdb_init_smb(&pw_buf);
95 pw_buf.acct_ctrl = ACB_NORMAL;
98 * Scan the file, a line at a time.
100 while ((linebuf_len = getfileline(vp, linebuf, sizeof(linebuf))) > 0)
103 * The line we have should be of the form :-
105 * username:uid:32hex bytes:[Account type]:LCT-12345678....other flags presently
110 * username:uid:32hex bytes:32hex bytes:[Account type]:LCT-12345678....ignored....
112 * if Windows NT compatible passwords are also present.
113 * [Account type] is an ascii encoding of the type of account.
114 * LCT-(8 hex digits) is the time_t value of the last change time.
118 * As 256 is shorter than a pstring we don't need to check
119 * length here - if this ever changes....
121 p = strncpyn(user_name, linebuf, sizeof(user_name), ':');
128 p = Atoic( p, &uidval, ":");
130 pw_buf.smb_name = user_name;
131 pw_buf.smb_userid = uidval;
134 * Now get the password value - this should be 32 hex digits
135 * which are the ascii representations of a 16 byte string.
136 * Get two at a time and put them into the password.
142 if (*p == '*' || *p == 'X')
144 /* Password deliberately invalid - end here. */
145 DEBUG(10, ("getsmbfilepwent: entry invalidated for user %s\n", user_name));
146 pw_buf.smb_nt_passwd = NULL;
147 pw_buf.smb_passwd = NULL;
148 pw_buf.acct_ctrl |= ACB_DISABLED;
152 if (linebuf_len < (PTR_DIFF(p, linebuf) + 33))
154 DEBUG(0, ("getsmbfilepwent: malformed password entry (passwd too short)\n"));
160 DEBUG(0, ("getsmbfilepwent: malformed password entry (no terminating :)\n"));
164 if (!strncasecmp( p, "NO PASSWORD", 11))
166 pw_buf.smb_passwd = NULL;
167 pw_buf.acct_ctrl |= ACB_PWNOTREQ;
171 if (!pwdb_gethexpwd(p, (char *)smbpwd))
173 DEBUG(0, ("getsmbfilepwent: Malformed Lanman password entry (non hex chars)\n"));
176 pw_buf.smb_passwd = smbpwd;
180 * Now check if the NT compatible password is
183 pw_buf.smb_nt_passwd = NULL;
185 /* Move to the first character of the line after the lanman password. */
187 if ((linebuf_len >= (PTR_DIFF(p, linebuf) + 33)) && (p[32] == ':'))
189 if (*p != '*' && *p != 'X')
191 if(pwdb_gethexpwd(p,(char *)smbntpwd))
193 pw_buf.smb_nt_passwd = smbntpwd;
196 /* Move to the first character of the line after the NT password. */
200 DEBUG(5,("getsmbfilepwent: returning passwd entry for user %s, uid %d\n",
205 pw_buf.acct_ctrl = pwdb_decode_acct_ctrl((char*)p);
207 /* Must have some account type set. */
208 if (pw_buf.acct_ctrl == 0)
210 pw_buf.acct_ctrl = ACB_NORMAL;
213 /* Now try and get the last change time. */
221 pw_buf.pass_last_set_time = pwdb_get_last_set_time(p);
226 /* 'Old' style file. Fake up based on user name. */
228 * Currently trust accounts are kept in the same
229 * password file as 'normal accounts'. If this changes
230 * we will have to fix this code. JRA.
232 if (pw_buf.smb_name[strlen(pw_buf.smb_name) - 1] == '$')
234 pw_buf.acct_ctrl &= ~ACB_NORMAL;
235 pw_buf.acct_ctrl |= ACB_WSTRUST;
239 pwfile = Get_Pwnam(pw_buf.smb_name, False);
242 DEBUG(0,("getsmbfilepwent: smbpasswd database is corrupt!\n"));
243 DEBUG(0,("getsmbfilepwent: username %s not in unix passwd database!\n", pw_buf.smb_name));
250 DEBUG(5,("getsmbfilepwent: end of file reached.\n"));
254 /*************************************************************************
255 Routine to return the next entry in the smbpasswd list.
256 this function is a nice, messy combination of reading:
258 - the unix password database
259 - smb.conf options (not done at present).
260 *************************************************************************/
262 static struct sam_passwd *getsmbfile21pwent(void *vp)
264 struct smb_passwd *pw_buf = getsmbfilepwent(vp);
265 static struct sam_passwd user;
266 struct passwd *pwfile;
268 static pstring full_name;
269 static pstring home_dir;
270 static pstring home_drive;
271 static pstring logon_script;
272 static pstring profile_path;
273 static pstring acct_desc;
274 static pstring workstations;
276 DEBUG(5,("getsmbfile21pwent\n"));
278 if (pw_buf == NULL) return NULL;
280 pwdb_init_sam(&user);
282 pwfile = Get_Pwnam(pw_buf->smb_name, False);
285 DEBUG(0,("getsmbfile21pwent: smbpasswd database is corrupt!\n"));
286 DEBUG(0,("getsmbfile21pwent: username %s not in unix passwd database!\n", pw_buf->smb_name));
290 pstrcpy(samlogon_user, pw_buf->smb_name);
292 if (samlogon_user[strlen(samlogon_user)-1] != '$')
294 /* XXXX hack to get standard_sub_basic() to use sam logon username */
295 /* possibly a better way would be to do a become_user() call */
296 sam_logon_in_ssb = True;
298 user.smb_userid = pw_buf->smb_userid;
299 user.smb_grpid = pwfile->pw_gid;
301 user.user_rid = pwdb_uid_to_user_rid (user.smb_userid);
302 user.group_rid = pwdb_gid_to_group_rid(user.smb_grpid );
304 pstrcpy(full_name , pwfile->pw_gecos );
305 pstrcpy(logon_script , lp_logon_script ());
306 pstrcpy(profile_path , lp_logon_path ());
307 pstrcpy(home_drive , lp_logon_drive ());
308 pstrcpy(home_dir , lp_logon_home ());
309 pstrcpy(acct_desc , "");
310 pstrcpy(workstations , "");
312 sam_logon_in_ssb = False;
316 user.smb_userid = pw_buf->smb_userid;
317 user.smb_grpid = pwfile->pw_gid;
319 user.user_rid = pwdb_uid_to_user_rid (user.smb_userid);
320 user.group_rid = DOMAIN_GROUP_RID_USERS; /* lkclXXXX this is OBSERVED behaviour by NT PDCs, enforced here. */
322 pstrcpy(full_name , "");
323 pstrcpy(logon_script , "");
324 pstrcpy(profile_path , "");
325 pstrcpy(home_drive , "");
326 pstrcpy(home_dir , "");
327 pstrcpy(acct_desc , "");
328 pstrcpy(workstations , "");
331 user.smb_name = pw_buf->smb_name;
332 user.full_name = full_name;
333 user.home_dir = home_dir;
334 user.dir_drive = home_drive;
335 user.logon_script = logon_script;
336 user.profile_path = profile_path;
337 user.acct_desc = acct_desc;
338 user.workstations = workstations;
340 user.unknown_str = NULL; /* don't know, yet! */
341 user.munged_dial = NULL; /* "munged" dial-back telephone number */
343 user.smb_nt_passwd = pw_buf->smb_nt_passwd;
344 user.smb_passwd = pw_buf->smb_passwd;
346 user.acct_ctrl = pw_buf->acct_ctrl;
348 user.unknown_3 = 0xffffff; /* don't know */
349 user.logon_divs = 168; /* hours per week */
350 user.hours_len = 21; /* 21 times 8 bits = 168 */
351 memset(user.hours, 0xff, user.hours_len); /* available at all hours */
352 user.unknown_5 = 0x00020000; /* don't know */
353 user.unknown_5 = 0x000004ec; /* don't know */
358 /************************************************************************
359 Routine to add an entry to the smbpasswd file.
360 *************************************************************************/
362 static BOOL add_smbfilepwd_entry(struct smb_passwd *newpwd)
364 char *pfile = lp_smb_passwd_file();
365 struct smb_passwd *pwd = NULL;
372 int new_entry_length;
377 /* Open the smbpassword file - for update. */
378 fp = startsmbfilepwent(True);
381 DEBUG(0, ("add_smbfilepwd_entry: unable to open file.\n"));
386 * Scan the file, a line at a time and check if the name matches.
389 while ((pwd = getsmbfilepwent(fp)) != NULL) {
390 if (strequal(newpwd->smb_name, pwd->smb_name)) {
391 DEBUG(0, ("add_smbfilepwd_entry: entry with name %s already exists\n", pwd->smb_name));
397 /* Ok - entry doesn't exist. We can add it */
399 /* Create a new smb passwd entry and set it to the given password. */
401 * The add user write needs to be atomic - so get the fd from
402 * the fp and do a raw write() call.
406 if((offpos = sys_lseek(fd, 0, SEEK_END)) == -1) {
407 DEBUG(0, ("add_smbfilepwd_entry(sys_lseek): Failed to add entry for user %s to file %s. \
408 Error was %s\n", newpwd->smb_name, pfile, strerror(errno)));
413 new_entry_length = strlen(newpwd->smb_name) + 1 + 15 + 1 + 32 + 1 + 32 + 1 + NEW_PW_FORMAT_SPACE_PADDED_LEN + 1 + 13 + 2;
415 if((new_entry = (char *)malloc( new_entry_length )) == NULL) {
416 DEBUG(0, ("add_smbfilepwd_entry(malloc): Failed to add entry for user %s to file %s. \
417 Error was %s\n", newpwd->smb_name, pfile, strerror(errno)));
422 slprintf(new_entry, new_entry_length - 1, "%s:%u:", newpwd->smb_name, (unsigned)newpwd->smb_userid);
423 p = &new_entry[strlen(new_entry)];
425 if(newpwd->smb_passwd != NULL) {
426 for( i = 0; i < 16; i++) {
427 slprintf((char *)&p[i*2], new_entry_length - (p - new_entry) - 1, "%02X", newpwd->smb_passwd[i]);
431 if(newpwd->acct_ctrl & ACB_PWNOTREQ)
432 safe_strcpy((char *)p, "NO PASSWORDXXXXXXXXXXXXXXXXXXXXX", new_entry_length - 1 - (p - new_entry));
434 safe_strcpy((char *)p, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", new_entry_length - 1 - (p - new_entry));
441 if(newpwd->smb_nt_passwd != NULL) {
442 for( i = 0; i < 16; i++) {
443 slprintf((char *)&p[i*2], new_entry_length - 1 - (p - new_entry), "%02X", newpwd->smb_nt_passwd[i]);
446 if(newpwd->acct_ctrl & ACB_PWNOTREQ)
447 safe_strcpy((char *)p, "NO PASSWORDXXXXXXXXXXXXXXXXXXXXX", new_entry_length - 1 - (p - new_entry));
449 safe_strcpy((char *)p, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", new_entry_length - 1 - (p - new_entry));
456 /* Add the account encoding and the last change time. */
457 slprintf((char *)p, new_entry_length - 1 - (p - new_entry), "%s:LCT-%08X:\n",
458 pwdb_encode_acct_ctrl(newpwd->acct_ctrl, NEW_PW_FORMAT_SPACE_PADDED_LEN), (uint32)time(NULL));
460 #ifdef DEBUG_PASSWORD
461 DEBUG(100, ("add_smbfilepwd_entry(%d): new_entry_len %d entry_len %d made line |%s|",
462 fd, new_entry_length, strlen(new_entry), new_entry));
465 if ((wr_len = write(fd, new_entry, strlen(new_entry))) != strlen(new_entry)) {
466 DEBUG(0, ("add_smbfilepwd_entry(write): %d Failed to add entry for user %s to file %s. \
467 Error was %s\n", wr_len, newpwd->smb_name, pfile, strerror(errno)));
469 /* Remove the entry we just wrote. */
470 if(sys_ftruncate(fd, offpos) == -1) {
471 DEBUG(0, ("add_smbfilepwd_entry: ERROR failed to ftruncate file %s. \
472 Error was %s. Password file may be corrupt ! Please examine by hand !\n",
473 newpwd->smb_name, strerror(errno)));
486 /************************************************************************
487 Routine to search the smbpasswd file for an entry matching the username.
488 and then modify its password entry. We can't use the startsmbpwent()/
489 getsmbpwent()/endsmbpwent() interfaces here as we depend on looking
490 in the actual file to decide how much room we have to write data.
491 override = False, normal
492 override = True, override XXXXXXXX'd out password or NO PASS
493 ************************************************************************/
495 static BOOL mod_smbfilepwd_entry(struct smb_passwd* pwd, BOOL override)
497 /* Static buffers we will return. */
498 static pstring user_name;
505 unsigned char *p = NULL;
506 size_t linebuf_len = 0;
509 char *pfile = lp_smb_passwd_file();
510 BOOL found_entry = False;
511 BOOL got_pass_last_set_time = False;
513 SMB_OFF_T pwd_seekpos = 0;
520 DEBUG(0, ("No SMB password file set\n"));
523 DEBUG(10, ("mod_smbfilepwd_entry: opening file %s\n", pfile));
525 fp = sys_fopen(pfile, "r+");
528 DEBUG(0, ("mod_smbfilepwd_entry: unable to open file %s\n", pfile));
531 /* Set a buffer to do more efficient reads */
532 setvbuf(fp, readbuf, _IOFBF, sizeof(readbuf));
536 if (!file_lock(lockfd, F_WRLCK, 5, &pw_file_lock_depth)) {
537 DEBUG(0, ("mod_smbfilepwd_entry: unable to lock file %s\n", pfile));
542 /* Make sure it is only rw by the owner */
545 /* We have a write lock on the file. */
547 * Scan the file, a line at a time and check if the name matches.
550 pwd_seekpos = sys_ftell(fp);
554 fgets(linebuf, sizeof(linebuf), fp);
556 file_unlock(lockfd, &pw_file_lock_depth);
562 * Check if the string is terminated with a newline - if not
563 * then we must keep reading and discard until we get one.
565 linebuf_len = strlen(linebuf);
566 if (linebuf[linebuf_len - 1] != '\n') {
568 while (!ferror(fp) && !feof(fp)) {
575 linebuf[linebuf_len - 1] = '\0';
578 #ifdef DEBUG_PASSWORD
579 DEBUG(100, ("mod_smbfilepwd_entry: got line |%s|\n", linebuf));
582 if ((linebuf[0] == 0) && feof(fp)) {
583 DEBUG(4, ("mod_smbfilepwd_entry: end of file reached\n"));
588 * The line we have should be of the form :-
590 * username:uid:[32hex bytes]:....other flags presently
595 * username:uid:[32hex bytes]:[32hex bytes]:[attributes]:LCT-XXXXXXXX:...ignored.
597 * if Windows NT compatible passwords are also present.
600 if (linebuf[0] == '#' || linebuf[0] == '\0') {
601 DEBUG(6, ("mod_smbfilepwd_entry: skipping comment or blank line\n"));
605 p = (unsigned char *) strchr(linebuf, ':');
608 DEBUG(0, ("mod_smbfilepwd_entry: malformed password entry (no :)\n"));
613 * As 256 is shorter than a pstring we don't need to check
614 * length here - if this ever changes....
616 strncpy(user_name, linebuf, PTR_DIFF(p, linebuf));
617 user_name[PTR_DIFF(p, linebuf)] = '\0';
618 if (strequal(user_name, pwd->smb_name)) {
625 file_unlock(lockfd, &pw_file_lock_depth);
630 DEBUG(6, ("mod_smbfilepwd_entry: entry exists\n"));
632 /* User name matches - get uid and password */
633 p++; /* Go past ':' */
636 DEBUG(0, ("mod_smbfilepwd_entry: malformed password entry (uid not number)\n"));
637 file_unlock(lockfd, &pw_file_lock_depth);
642 while (*p && isdigit(*p))
645 DEBUG(0, ("mod_smbfilepwd_entry: malformed password entry (no : after uid)\n"));
646 file_unlock(lockfd, &pw_file_lock_depth);
652 * Now get the password value - this should be 32 hex digits
653 * which are the ascii representations of a 16 byte string.
654 * Get two at a time and put them into the password.
658 /* Record exact password position */
659 pwd_seekpos += PTR_DIFF(p, linebuf);
661 if (!override && (*p == '*' || *p == 'X')) {
662 /* Password deliberately invalid - end here. */
663 DEBUG(10, ("mod_smbfilepwd_entry: entry invalidated for user %s\n", user_name));
664 file_unlock(lockfd, &pw_file_lock_depth);
669 if (linebuf_len < (PTR_DIFF(p, linebuf) + 33)) {
670 DEBUG(0, ("mod_smbfilepwd_entry: malformed password entry (passwd too short)\n"));
671 file_unlock(lockfd,&pw_file_lock_depth);
677 DEBUG(0, ("mod_smbfilepwd_entry: malformed password entry (no terminating :)\n"));
678 file_unlock(lockfd,&pw_file_lock_depth);
683 if (!override && (*p == '*' || *p == 'X')) {
684 file_unlock(lockfd,&pw_file_lock_depth);
689 /* Now check if the NT compatible password is
691 p += 33; /* Move to the first character of the line after
692 the lanman password. */
693 if (linebuf_len < (PTR_DIFF(p, linebuf) + 33)) {
694 DEBUG(0, ("mod_smbfilepwd_entry: malformed password entry (passwd too short)\n"));
695 file_unlock(lockfd,&pw_file_lock_depth);
701 DEBUG(0, ("mod_smbfilepwd_entry: malformed password entry (no terminating :)\n"));
702 file_unlock(lockfd,&pw_file_lock_depth);
708 * Now check if the account info and the password last
709 * change time is available.
711 p += 33; /* Move to the first character of the line after
715 * If both NT and lanman passwords are provided - reset password
719 if(pwd->smb_passwd != NULL || pwd->smb_nt_passwd != NULL) {
720 /* Reqiure password in the future (should ACB_DISABLED also be reset?) */
721 pwd->acct_ctrl &= ~(ACB_PWNOTREQ);
727 encode_bits[i++] = *p++;
728 while((linebuf_len > PTR_DIFF(p, linebuf)) && (*p != ']'))
729 encode_bits[i++] = *p++;
731 encode_bits[i++] = ']';
732 encode_bits[i++] = '\0';
734 if(i == NEW_PW_FORMAT_SPACE_PADDED_LEN) {
736 * We are using a new format, space padded
737 * acct ctrl field. Encode the given acct ctrl
740 fstrcpy(encode_bits, pwdb_encode_acct_ctrl(pwd->acct_ctrl, NEW_PW_FORMAT_SPACE_PADDED_LEN));
743 * If using the old format and the ACB_DISABLED or
744 * ACB_PWNOTREQ are set then set the lanman and NT passwords to NULL
745 * here as we have no space to encode the change.
747 if(pwd->acct_ctrl & (ACB_DISABLED|ACB_PWNOTREQ)) {
748 pwd->smb_passwd = NULL;
749 pwd->smb_nt_passwd = NULL;
753 /* Go past the ']' */
754 if(linebuf_len > PTR_DIFF(p, linebuf))
757 if((linebuf_len > PTR_DIFF(p, linebuf)) && (*p == ':')) {
760 /* We should be pointing at the LCT entry. */
761 if((linebuf_len > (PTR_DIFF(p, linebuf) + 13)) && (StrnCaseCmp((char *)p, "LCT-", 4) == 0)) {
764 for(i = 0; i < 8; i++) {
765 if(p[i] == '\0' || !isxdigit(p[i]))
770 * p points at 8 characters of hex digits -
771 * read into a time_t as the seconds since
772 * 1970 that the password was last changed.
774 got_pass_last_set_time = True;
776 } /* *p && StrnCaseCmp() */
780 /* Entry is correctly formed. */
782 /* Create the 32 byte representation of the new p16 */
783 if(pwd->smb_passwd != NULL) {
784 for (i = 0; i < 16; i++) {
785 slprintf(&ascii_p16[i*2], sizeof(fstring) - 1, "%02X", (uchar) pwd->smb_passwd[i]);
788 if(pwd->acct_ctrl & ACB_PWNOTREQ)
789 fstrcpy(ascii_p16, "NO PASSWORDXXXXXXXXXXXXXXXXXXXXX");
791 fstrcpy(ascii_p16, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
794 /* Add on the NT md4 hash */
797 if (pwd->smb_nt_passwd != NULL) {
798 for (i = 0; i < 16; i++) {
799 slprintf(&ascii_p16[(i*2)+33], sizeof(fstring) - 1, "%02X", (uchar) pwd->smb_nt_passwd[i]);
802 if(pwd->acct_ctrl & ACB_PWNOTREQ)
803 fstrcpy(&ascii_p16[33], "NO PASSWORDXXXXXXXXXXXXXXXXXXXXX");
805 fstrcpy(&ascii_p16[33], "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
808 ascii_p16[66] = '\0'; /* null-terminate the string so that strlen works */
810 /* Add on the account info bits and the time of last
813 pwd->pass_last_set_time = time(NULL);
815 if(got_pass_last_set_time) {
816 slprintf(&ascii_p16[strlen(ascii_p16)],
817 sizeof(ascii_p16)-(strlen(ascii_p16)+1),
819 encode_bits, (uint32)pwd->pass_last_set_time );
820 wr_len = strlen(ascii_p16);
823 #ifdef DEBUG_PASSWORD
824 DEBUG(100,("mod_smbfilepwd_entry: "));
825 dump_data(100, ascii_p16, wr_len);
828 if(wr_len > sizeof(linebuf)) {
829 DEBUG(0, ("mod_smbfilepwd_entry: line to write (%d) is too long.\n", wr_len+1));
830 file_unlock(lockfd,&pw_file_lock_depth);
836 * Do an atomic write into the file at the position defined by
840 /* The mod user write needs to be atomic - so get the fd from
841 the fp and do a raw write() call.
846 if (sys_lseek(fd, pwd_seekpos - 1, SEEK_SET) != pwd_seekpos - 1) {
847 DEBUG(0, ("mod_smbfilepwd_entry: seek fail on file %s.\n", pfile));
848 file_unlock(lockfd,&pw_file_lock_depth);
853 /* Sanity check - ensure the areas we are writing are framed by ':' */
854 if (read(fd, linebuf, wr_len+1) != wr_len+1) {
855 DEBUG(0, ("mod_smbfilepwd_entry: read fail on file %s.\n", pfile));
856 file_unlock(lockfd,&pw_file_lock_depth);
861 if ((linebuf[0] != ':') || (linebuf[wr_len] != ':')) {
862 DEBUG(0, ("mod_smbfilepwd_entry: check on passwd file %s failed.\n", pfile));
863 file_unlock(lockfd,&pw_file_lock_depth);
868 if (sys_lseek(fd, pwd_seekpos, SEEK_SET) != pwd_seekpos) {
869 DEBUG(0, ("mod_smbfilepwd_entry: seek fail on file %s.\n", pfile));
870 file_unlock(lockfd,&pw_file_lock_depth);
875 if (write(fd, ascii_p16, wr_len) != wr_len) {
876 DEBUG(0, ("mod_smbfilepwd_entry: write failed in passwd file %s\n", pfile));
877 file_unlock(lockfd,&pw_file_lock_depth);
882 file_unlock(lockfd,&pw_file_lock_depth);
888 * Stub functions - implemented in terms of others.
891 static BOOL mod_smbfile21pwd_entry(struct sam_passwd* pwd, BOOL override)
893 return mod_smbfilepwd_entry(pwdb_sam_to_smb(pwd), override);
896 static BOOL add_smbfile21pwd_entry(struct sam_passwd *newpwd)
898 return add_smbfilepwd_entry(pwdb_sam_to_smb(newpwd));
901 static struct sam_disp_info *getsmbfiledispnam(const char *name)
903 return pwdb_sam_to_dispinfo(getsam21pwnam(name));
906 static struct sam_disp_info *getsmbfiledisprid(uint32 rid)
908 return pwdb_sam_to_dispinfo(getsam21pwrid(rid));
911 static struct sam_disp_info *getsmbfiledispent(void *vp)
913 return pwdb_sam_to_dispinfo(getsam21pwent(vp));
916 static struct passdb_ops file_ops = {
921 iterate_getsmbpwnam, /* In passdb.c */
922 iterate_getsmbpwuid, /* In passdb.c */
923 iterate_getsmbpwrid, /* In passdb.c */
925 add_smbfilepwd_entry,
926 mod_smbfilepwd_entry,
928 iterate_getsam21pwnam,
929 iterate_getsam21pwuid,
930 iterate_getsam21pwrid,
931 add_smbfile21pwd_entry,
932 mod_smbfile21pwd_entry,
938 struct passdb_ops *file_initialise_password_db(void)
944 /* Do *NOT* make this function static. It breaks the compile on gcc. JRA */
945 void smbpass_dummy_function(void) { } /* stop some compilers complaining */
946 #endif /* USE_SMBPASS_DB */