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 extern int DEBUGLEVEL
;
25 extern pstring samlogon_user
;
26 extern BOOL sam_logon_in_ssb
;
28 static char s_readbuf
[1024];
29 static int pw_file_lock_depth
;
31 /***************************************************************
32 Start to enumerate the smbpasswd list. Returns a void pointer
33 to ensure no modification outside this module.
34 ****************************************************************/
36 static void *startsmbfilepwent(BOOL update
)
39 char *pfile
= lp_smb_passwd_file();
42 DEBUG(0, ("startsmbfilepwent: No SMB password file set\n"));
45 DEBUG(10, ("startsmbfilepwent: opening file %s\n", pfile
));
47 fp
= sys_fopen(pfile
, update
? "r+b" : "rb");
50 DEBUG(0, ("startsmbfilepwent: unable to open file %s\n", pfile
));
54 /* Set a buffer to do more efficient reads */
55 setvbuf(fp
, s_readbuf
, _IOFBF
, sizeof(s_readbuf
));
57 if (!pw_file_lock(fileno(fp
), (update
? F_WRLCK
: F_RDLCK
), 5, &pw_file_lock_depth
))
59 DEBUG(0, ("startsmbfilepwent: unable to lock file %s\n", pfile
));
64 /* Make sure it is only rw by the owner */
67 /* We have a lock on the file. */
71 /***************************************************************
72 End enumeration of the smbpasswd list.
73 ****************************************************************/
75 static void endsmbfilepwent(void *vp
)
77 FILE *fp
= (FILE *)vp
;
79 pw_file_unlock(fileno(fp
), &pw_file_lock_depth
);
81 DEBUG(7, ("endsmbfilepwent: closed password file.\n"));
84 /*************************************************************************
85 Routine to return the next entry in the smbpasswd list.
86 *************************************************************************/
87 static struct smb_passwd
*getsmbfilepwent(void *vp
)
89 /* Static buffers we will return. */
90 static struct smb_passwd pw_buf
;
91 static pstring user_name
;
92 static unsigned char smbpwd
[16];
93 static unsigned char smbntpwd
[16];
94 FILE *fp
= (FILE *)vp
;
102 DEBUG(0,("getsmbfilepwent: Bad password file pointer.\n"));
106 pdb_init_smb(&pw_buf
);
108 pw_buf
.acct_ctrl
= ACB_NORMAL
;
111 * Scan the file, a line at a time and check if the name matches.
116 fgets(linebuf
, 256, fp
);
122 * Check if the string is terminated with a newline - if not
123 * then we must keep reading and discard until we get one.
125 linebuf_len
= strlen(linebuf
);
126 if (linebuf
[linebuf_len
- 1] != '\n') {
128 while (!ferror(fp
) && !feof(fp
)) {
134 linebuf
[linebuf_len
- 1] = '\0';
136 #ifdef DEBUG_PASSWORD
137 DEBUG(100, ("getsmbfilepwent: got line |%s|\n", linebuf
));
139 if ((linebuf
[0] == 0) && feof(fp
)) {
140 DEBUG(4, ("getsmbfilepwent: end of file reached\n"));
144 * The line we have should be of the form :-
146 * username:uid:32hex bytes:[Account type]:LCT-12345678....other flags presently
151 * username:uid:32hex bytes:32hex bytes:[Account type]:LCT-12345678....ignored....
153 * if Windows NT compatible passwords are also present.
154 * [Account type] is an ascii encoding of the type of account.
155 * LCT-(8 hex digits) is the time_t value of the last change time.
158 if (linebuf
[0] == '#' || linebuf
[0] == '\0') {
159 DEBUG(6, ("getsmbfilepwent: skipping comment or blank line\n"));
162 p
= (unsigned char *) strchr(linebuf
, ':');
164 DEBUG(0, ("getsmbfilepwent: malformed password entry (no :)\n"));
168 * As 256 is shorter than a pstring we don't need to check
169 * length here - if this ever changes....
171 strncpy(user_name
, linebuf
, PTR_DIFF(p
, linebuf
));
172 user_name
[PTR_DIFF(p
, linebuf
)] = '\0';
176 p
++; /* Go past ':' */
179 DEBUG(0, ("getsmbfilepwent: uids in the smbpasswd file must not be negative.\n"));
184 DEBUG(0, ("getsmbfilepwent: malformed password entry (uid not number)\n"));
188 uidval
= atoi((char *) p
);
190 while (*p
&& isdigit(*p
))
194 DEBUG(0, ("getsmbfilepwent: malformed password entry (no : after uid)\n"));
198 pw_buf
.smb_name
= user_name
;
199 pw_buf
.smb_userid
= uidval
;
202 * Now get the password value - this should be 32 hex digits
203 * which are the ascii representations of a 16 byte string.
204 * Get two at a time and put them into the password.
210 if (*p
== '*' || *p
== 'X') {
211 /* Password deliberately invalid - end here. */
212 DEBUG(10, ("getsmbfilepwent: entry invalidated for user %s\n", user_name
));
213 pw_buf
.smb_nt_passwd
= NULL
;
214 pw_buf
.smb_passwd
= NULL
;
215 pw_buf
.acct_ctrl
|= ACB_DISABLED
;
219 if (linebuf_len
< (PTR_DIFF(p
, linebuf
) + 33)) {
220 DEBUG(0, ("getsmbfilepwent: malformed password entry (passwd too short)\n"));
225 DEBUG(0, ("getsmbfilepwent: malformed password entry (no terminating :)\n"));
229 if (!strncasecmp((char *) p
, "NO PASSWORD", 11)) {
230 pw_buf
.smb_passwd
= NULL
;
231 pw_buf
.acct_ctrl
|= ACB_PWNOTREQ
;
233 if (!pdb_gethexpwd((char *)p
, (char *)smbpwd
)) {
234 DEBUG(0, ("getsmbfilepwent: Malformed Lanman password entry (non hex chars)\n"));
237 pw_buf
.smb_passwd
= smbpwd
;
241 * Now check if the NT compatible password is
244 pw_buf
.smb_nt_passwd
= NULL
;
246 p
+= 33; /* Move to the first character of the line after
247 the lanman password. */
248 if ((linebuf_len
>= (PTR_DIFF(p
, linebuf
) + 33)) && (p
[32] == ':')) {
249 if (*p
!= '*' && *p
!= 'X') {
250 if(pdb_gethexpwd((char *)p
,(char *)smbntpwd
))
251 pw_buf
.smb_nt_passwd
= smbntpwd
;
253 p
+= 33; /* Move to the first character of the line after
257 DEBUG(5,("getsmbfilepwent: returning passwd entry for user %s, uid %ld\n",
262 pw_buf
.acct_ctrl
= pdb_decode_acct_ctrl((char*)p
);
264 /* Must have some account type set. */
265 if(pw_buf
.acct_ctrl
== 0)
266 pw_buf
.acct_ctrl
= ACB_NORMAL
;
268 /* Now try and get the last change time. */
273 if(*p
&& (StrnCaseCmp((char *)p
, "LCT-", 4)==0)) {
276 for(i
= 0; i
< 8; i
++) {
277 if(p
[i
] == '\0' || !isxdigit(p
[i
]))
282 * p points at 8 characters of hex digits -
283 * read into a time_t as the seconds since
284 * 1970 that the password was last changed.
286 pw_buf
.pass_last_set_time
= (time_t)strtol((char *)p
, NULL
, 16);
291 /* 'Old' style file. Fake up based on user name. */
293 * Currently trust accounts are kept in the same
294 * password file as 'normal accounts'. If this changes
295 * we will have to fix this code. JRA.
297 if(pw_buf
.smb_name
[strlen(pw_buf
.smb_name
) - 1] == '$') {
298 pw_buf
.acct_ctrl
&= ~ACB_NORMAL
;
299 pw_buf
.acct_ctrl
|= ACB_WSTRUST
;
306 DEBUG(5,("getsmbfilepwent: end of file reached.\n"));
310 /*************************************************************************
311 Routine to return the next entry in the smbpasswd list.
312 this function is a nice, messy combination of reading:
314 - the unix password database
315 - smb.conf options (not done at present).
316 *************************************************************************/
318 static struct sam_passwd
*getsmbfile21pwent(void *vp
)
320 struct smb_passwd
*pw_buf
= getsmbfilepwent(vp
);
321 static struct sam_passwd user
;
322 struct passwd
*pwfile
;
324 static pstring full_name
;
325 static pstring home_dir
;
326 static pstring home_drive
;
327 static pstring logon_script
;
328 static pstring profile_path
;
329 static pstring acct_desc
;
330 static pstring workstations
;
332 DEBUG(5,("getsmbfile21pwent\n"));
334 if (pw_buf
== NULL
) return NULL
;
336 pwfile
= sys_getpwnam(pw_buf
->smb_name
);
339 DEBUG(0,("getsmbfile21pwent: smbpasswd database is corrupt!\n"));
340 DEBUG(0,("getsmbfile21pwent: username %s not in unix passwd database!\n", pw_buf
->smb_name
));
346 pstrcpy(samlogon_user
, pw_buf
->smb_name
);
348 if (samlogon_user
[strlen(samlogon_user
)-1] != '$')
350 /* XXXX hack to get standard_sub_basic() to use sam logon username */
351 /* possibly a better way would be to do a become_user() call */
352 sam_logon_in_ssb
= True
;
354 user
.smb_userid
= pw_buf
->smb_userid
;
355 user
.smb_grpid
= pwfile
->pw_gid
;
357 user
.user_rid
= pdb_uid_to_user_rid (user
.smb_userid
);
358 user
.group_rid
= pdb_gid_to_group_rid(user
.smb_grpid
);
360 pstrcpy(full_name
, pwfile
->pw_gecos
);
361 pstrcpy(logon_script
, lp_logon_script ());
362 pstrcpy(profile_path
, lp_logon_path ());
363 pstrcpy(home_drive
, lp_logon_drive ());
364 pstrcpy(home_dir
, lp_logon_home ());
365 pstrcpy(acct_desc
, "");
366 pstrcpy(workstations
, "");
368 sam_logon_in_ssb
= False
;
372 user
.smb_userid
= pw_buf
->smb_userid
;
373 user
.smb_grpid
= pwfile
->pw_gid
;
375 user
.user_rid
= pdb_uid_to_user_rid (user
.smb_userid
);
376 user
.group_rid
= DOMAIN_GROUP_RID_USERS
; /* lkclXXXX this is OBSERVED behaviour by NT PDCs, enforced here. */
378 pstrcpy(full_name
, "");
379 pstrcpy(logon_script
, "");
380 pstrcpy(profile_path
, "");
381 pstrcpy(home_drive
, "");
382 pstrcpy(home_dir
, "");
383 pstrcpy(acct_desc
, "");
384 pstrcpy(workstations
, "");
387 user
.smb_name
= pw_buf
->smb_name
;
388 user
.full_name
= full_name
;
389 user
.home_dir
= home_dir
;
390 user
.dir_drive
= home_drive
;
391 user
.logon_script
= logon_script
;
392 user
.profile_path
= profile_path
;
393 user
.acct_desc
= acct_desc
;
394 user
.workstations
= workstations
;
396 user
.unknown_str
= NULL
; /* don't know, yet! */
397 user
.munged_dial
= NULL
; /* "munged" dial-back telephone number */
399 user
.smb_nt_passwd
= pw_buf
->smb_nt_passwd
;
400 user
.smb_passwd
= pw_buf
->smb_passwd
;
402 user
.acct_ctrl
= pw_buf
->acct_ctrl
;
404 user
.unknown_3
= 0xffffff; /* don't know */
405 user
.logon_divs
= 168; /* hours per week */
406 user
.hours_len
= 21; /* 21 times 8 bits = 168 */
407 memset(user
.hours
, 0xff, user
.hours_len
); /* available at all hours */
408 user
.unknown_5
= 0x00020000; /* don't know */
409 user
.unknown_5
= 0x000004ec; /* don't know */
414 /*************************************************************************
415 Return the current position in the smbpasswd list as an SMB_BIG_UINT.
416 This must be treated as an opaque token.
417 *************************************************************************/
419 static SMB_BIG_UINT
getsmbfilepwpos(void *vp
)
421 return (SMB_BIG_UINT
)sys_ftell((FILE *)vp
);
424 /*************************************************************************
425 Set the current position in the smbpasswd list from an SMB_BIG_UINT.
426 This must be treated as an opaque token.
427 *************************************************************************/
429 static BOOL
setsmbfilepwpos(void *vp
, SMB_BIG_UINT tok
)
431 return !sys_fseek((FILE *)vp
, (SMB_OFF_T
)tok
, SEEK_SET
);
434 /************************************************************************
435 Routine to add an entry to the smbpasswd file.
436 *************************************************************************/
438 static BOOL
add_smbfilepwd_entry(struct smb_passwd
*newpwd
)
440 char *pfile
= lp_smb_passwd_file();
441 struct smb_passwd
*pwd
= NULL
;
448 int new_entry_length
;
453 /* Open the smbpassword file - for update. */
454 fp
= startsmbfilepwent(True
);
457 DEBUG(0, ("add_smbfilepwd_entry: unable to open file.\n"));
462 * Scan the file, a line at a time and check if the name matches.
465 while ((pwd
= getsmbfilepwent(fp
)) != NULL
) {
466 if (strequal(newpwd
->smb_name
, pwd
->smb_name
)) {
467 DEBUG(0, ("add_smbfilepwd_entry: entry with name %s already exists\n", pwd
->smb_name
));
473 /* Ok - entry doesn't exist. We can add it */
475 /* Create a new smb passwd entry and set it to the given password. */
477 * The add user write needs to be atomic - so get the fd from
478 * the fp and do a raw write() call.
482 if((offpos
= sys_lseek(fd
, 0, SEEK_END
)) == -1) {
483 DEBUG(0, ("add_smbfilepwd_entry(sys_lseek): Failed to add entry for user %s to file %s. \
484 Error was %s\n", newpwd
->smb_name
, pfile
, strerror(errno
)));
489 new_entry_length
= strlen(newpwd
->smb_name
) + 1 + 15 + 1 + 32 + 1 + 32 + 1 + NEW_PW_FORMAT_SPACE_PADDED_LEN
+ 1 + 13 + 2;
491 if((new_entry
= (char *)malloc( new_entry_length
)) == NULL
) {
492 DEBUG(0, ("add_smbfilepwd_entry(malloc): Failed to add entry for user %s to file %s. \
493 Error was %s\n", newpwd
->smb_name
, pfile
, strerror(errno
)));
498 slprintf(new_entry
, new_entry_length
- 1, "%s:%u:", newpwd
->smb_name
, (unsigned)newpwd
->smb_userid
);
499 p
= &new_entry
[strlen(new_entry
)];
501 if(newpwd
->smb_passwd
!= NULL
) {
502 for( i
= 0; i
< 16; i
++) {
503 slprintf((char *)&p
[i
*2], new_entry_length
- (p
- new_entry
) - 1, "%02X", newpwd
->smb_passwd
[i
]);
507 if(newpwd
->acct_ctrl
& ACB_PWNOTREQ
)
508 safe_strcpy((char *)p
, "NO PASSWORDXXXXXXXXXXXXXXXXXXXXX", new_entry_length
- 1 - (p
- new_entry
));
510 safe_strcpy((char *)p
, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", new_entry_length
- 1 - (p
- new_entry
));
517 if(newpwd
->smb_nt_passwd
!= NULL
) {
518 for( i
= 0; i
< 16; i
++) {
519 slprintf((char *)&p
[i
*2], new_entry_length
- 1 - (p
- new_entry
), "%02X", newpwd
->smb_nt_passwd
[i
]);
522 if(newpwd
->acct_ctrl
& ACB_PWNOTREQ
)
523 safe_strcpy((char *)p
, "NO PASSWORDXXXXXXXXXXXXXXXXXXXXX", new_entry_length
- 1 - (p
- new_entry
));
525 safe_strcpy((char *)p
, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", new_entry_length
- 1 - (p
- new_entry
));
532 /* Add the account encoding and the last change time. */
533 slprintf((char *)p
, new_entry_length
- 1 - (p
- new_entry
), "%s:LCT-%08X:\n",
534 pdb_encode_acct_ctrl(newpwd
->acct_ctrl
, NEW_PW_FORMAT_SPACE_PADDED_LEN
), (uint32
)time(NULL
));
536 #ifdef DEBUG_PASSWORD
537 DEBUG(100, ("add_smbfilepwd_entry(%d): new_entry_len %d entry_len %d made line |%s|",
538 fd
, new_entry_length
, strlen(new_entry
), new_entry
));
541 if ((wr_len
= write(fd
, new_entry
, strlen(new_entry
))) != strlen(new_entry
)) {
542 DEBUG(0, ("add_smbfilepwd_entry(write): %d Failed to add entry for user %s to file %s. \
543 Error was %s\n", wr_len
, newpwd
->smb_name
, pfile
, strerror(errno
)));
545 /* Remove the entry we just wrote. */
546 if(sys_ftruncate(fd
, offpos
) == -1) {
547 DEBUG(0, ("add_smbfilepwd_entry: ERROR failed to ftruncate file %s. \
548 Error was %s. Password file may be corrupt ! Please examine by hand !\n",
549 newpwd
->smb_name
, strerror(errno
)));
562 /************************************************************************
563 Routine to search the smbpasswd file for an entry matching the username.
564 and then modify its password entry. We can't use the startsmbpwent()/
565 getsmbpwent()/endsmbpwent() interfaces here as we depend on looking
566 in the actual file to decide how much room we have to write data.
567 override = False, normal
568 override = True, override XXXXXXXX'd out password or NO PASS
569 ************************************************************************/
571 static BOOL
mod_smbfilepwd_entry(struct smb_passwd
* pwd
, BOOL override
)
573 /* Static buffers we will return. */
574 static pstring user_name
;
581 unsigned char *p
= NULL
;
582 size_t linebuf_len
= 0;
585 char *pfile
= lp_smb_passwd_file();
586 BOOL found_entry
= False
;
587 BOOL got_pass_last_set_time
= False
;
589 SMB_OFF_T pwd_seekpos
= 0;
596 DEBUG(0, ("No SMB password file set\n"));
599 DEBUG(10, ("mod_smbfilepwd_entry: opening file %s\n", pfile
));
601 fp
= sys_fopen(pfile
, "r+");
604 DEBUG(0, ("mod_smbfilepwd_entry: unable to open file %s\n", pfile
));
607 /* Set a buffer to do more efficient reads */
608 setvbuf(fp
, readbuf
, _IOFBF
, sizeof(readbuf
));
612 if (!pw_file_lock(lockfd
, F_WRLCK
, 5, &pw_file_lock_depth
)) {
613 DEBUG(0, ("mod_smbfilepwd_entry: unable to lock file %s\n", pfile
));
618 /* Make sure it is only rw by the owner */
621 /* We have a write lock on the file. */
623 * Scan the file, a line at a time and check if the name matches.
626 pwd_seekpos
= sys_ftell(fp
);
630 fgets(linebuf
, sizeof(linebuf
), fp
);
632 pw_file_unlock(lockfd
, &pw_file_lock_depth
);
638 * Check if the string is terminated with a newline - if not
639 * then we must keep reading and discard until we get one.
641 linebuf_len
= strlen(linebuf
);
642 if (linebuf
[linebuf_len
- 1] != '\n') {
644 while (!ferror(fp
) && !feof(fp
)) {
651 linebuf
[linebuf_len
- 1] = '\0';
654 #ifdef DEBUG_PASSWORD
655 DEBUG(100, ("mod_smbfilepwd_entry: got line |%s|\n", linebuf
));
658 if ((linebuf
[0] == 0) && feof(fp
)) {
659 DEBUG(4, ("mod_smbfilepwd_entry: end of file reached\n"));
664 * The line we have should be of the form :-
666 * username:uid:[32hex bytes]:....other flags presently
671 * username:uid:[32hex bytes]:[32hex bytes]:[attributes]:LCT-XXXXXXXX:...ignored.
673 * if Windows NT compatible passwords are also present.
676 if (linebuf
[0] == '#' || linebuf
[0] == '\0') {
677 DEBUG(6, ("mod_smbfilepwd_entry: skipping comment or blank line\n"));
681 p
= (unsigned char *) strchr(linebuf
, ':');
684 DEBUG(0, ("mod_smbfilepwd_entry: malformed password entry (no :)\n"));
689 * As 256 is shorter than a pstring we don't need to check
690 * length here - if this ever changes....
692 strncpy(user_name
, linebuf
, PTR_DIFF(p
, linebuf
));
693 user_name
[PTR_DIFF(p
, linebuf
)] = '\0';
694 if (strequal(user_name
, pwd
->smb_name
)) {
701 pw_file_unlock(lockfd
, &pw_file_lock_depth
);
706 DEBUG(6, ("mod_smbfilepwd_entry: entry exists\n"));
708 /* User name matches - get uid and password */
709 p
++; /* Go past ':' */
712 DEBUG(0, ("mod_smbfilepwd_entry: malformed password entry (uid not number)\n"));
713 pw_file_unlock(lockfd
, &pw_file_lock_depth
);
718 while (*p
&& isdigit(*p
))
721 DEBUG(0, ("mod_smbfilepwd_entry: malformed password entry (no : after uid)\n"));
722 pw_file_unlock(lockfd
, &pw_file_lock_depth
);
728 * Now get the password value - this should be 32 hex digits
729 * which are the ascii representations of a 16 byte string.
730 * Get two at a time and put them into the password.
734 /* Record exact password position */
735 pwd_seekpos
+= PTR_DIFF(p
, linebuf
);
737 if (!override
&& (*p
== '*' || *p
== 'X')) {
738 /* Password deliberately invalid - end here. */
739 DEBUG(10, ("mod_smbfilepwd_entry: entry invalidated for user %s\n", user_name
));
740 pw_file_unlock(lockfd
, &pw_file_lock_depth
);
745 if (linebuf_len
< (PTR_DIFF(p
, linebuf
) + 33)) {
746 DEBUG(0, ("mod_smbfilepwd_entry: malformed password entry (passwd too short)\n"));
747 pw_file_unlock(lockfd
,&pw_file_lock_depth
);
753 DEBUG(0, ("mod_smbfilepwd_entry: malformed password entry (no terminating :)\n"));
754 pw_file_unlock(lockfd
,&pw_file_lock_depth
);
759 if (!override
&& (*p
== '*' || *p
== 'X')) {
760 pw_file_unlock(lockfd
,&pw_file_lock_depth
);
765 /* Now check if the NT compatible password is
767 p
+= 33; /* Move to the first character of the line after
768 the lanman password. */
769 if (linebuf_len
< (PTR_DIFF(p
, linebuf
) + 33)) {
770 DEBUG(0, ("mod_smbfilepwd_entry: malformed password entry (passwd too short)\n"));
771 pw_file_unlock(lockfd
,&pw_file_lock_depth
);
777 DEBUG(0, ("mod_smbfilepwd_entry: malformed password entry (no terminating :)\n"));
778 pw_file_unlock(lockfd
,&pw_file_lock_depth
);
784 * Now check if the account info and the password last
785 * change time is available.
787 p
+= 33; /* Move to the first character of the line after
791 * If both NT and lanman passwords are provided - reset password
795 if(pwd
->smb_passwd
!= NULL
|| pwd
->smb_nt_passwd
!= NULL
) {
796 /* Reqiure password in the future (should ACB_DISABLED also be reset?) */
797 pwd
->acct_ctrl
&= ~(ACB_PWNOTREQ
);
803 encode_bits
[i
++] = *p
++;
804 while((linebuf_len
> PTR_DIFF(p
, linebuf
)) && (*p
!= ']'))
805 encode_bits
[i
++] = *p
++;
807 encode_bits
[i
++] = ']';
808 encode_bits
[i
++] = '\0';
810 if(i
== NEW_PW_FORMAT_SPACE_PADDED_LEN
) {
812 * We are using a new format, space padded
813 * acct ctrl field. Encode the given acct ctrl
816 fstrcpy(encode_bits
, pdb_encode_acct_ctrl(pwd
->acct_ctrl
, NEW_PW_FORMAT_SPACE_PADDED_LEN
));
819 * If using the old format and the ACB_DISABLED or
820 * ACB_PWNOTREQ are set then set the lanman and NT passwords to NULL
821 * here as we have no space to encode the change.
823 if(pwd
->acct_ctrl
& (ACB_DISABLED
|ACB_PWNOTREQ
)) {
824 pwd
->smb_passwd
= NULL
;
825 pwd
->smb_nt_passwd
= NULL
;
829 /* Go past the ']' */
830 if(linebuf_len
> PTR_DIFF(p
, linebuf
))
833 if((linebuf_len
> PTR_DIFF(p
, linebuf
)) && (*p
== ':')) {
836 /* We should be pointing at the LCT entry. */
837 if((linebuf_len
> (PTR_DIFF(p
, linebuf
) + 13)) && (StrnCaseCmp((char *)p
, "LCT-", 4) == 0)) {
840 for(i
= 0; i
< 8; i
++) {
841 if(p
[i
] == '\0' || !isxdigit(p
[i
]))
846 * p points at 8 characters of hex digits -
847 * read into a time_t as the seconds since
848 * 1970 that the password was last changed.
850 got_pass_last_set_time
= True
;
852 } /* *p && StrnCaseCmp() */
856 /* Entry is correctly formed. */
858 /* Create the 32 byte representation of the new p16 */
859 if(pwd
->smb_passwd
!= NULL
) {
860 for (i
= 0; i
< 16; i
++) {
861 slprintf(&ascii_p16
[i
*2], sizeof(fstring
) - 1, "%02X", (uchar
) pwd
->smb_passwd
[i
]);
864 if(pwd
->acct_ctrl
& ACB_PWNOTREQ
)
865 fstrcpy(ascii_p16
, "NO PASSWORDXXXXXXXXXXXXXXXXXXXXX");
867 fstrcpy(ascii_p16
, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
870 /* Add on the NT md4 hash */
873 if (pwd
->smb_nt_passwd
!= NULL
) {
874 for (i
= 0; i
< 16; i
++) {
875 slprintf(&ascii_p16
[(i
*2)+33], sizeof(fstring
) - 1, "%02X", (uchar
) pwd
->smb_nt_passwd
[i
]);
878 if(pwd
->acct_ctrl
& ACB_PWNOTREQ
)
879 fstrcpy(&ascii_p16
[33], "NO PASSWORDXXXXXXXXXXXXXXXXXXXXX");
881 fstrcpy(&ascii_p16
[33], "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
884 ascii_p16
[66] = '\0'; /* null-terminate the string so that strlen works */
886 /* Add on the account info bits and the time of last
889 pwd
->pass_last_set_time
= time(NULL
);
891 if(got_pass_last_set_time
) {
892 slprintf(&ascii_p16
[strlen(ascii_p16
)],
893 sizeof(ascii_p16
)-(strlen(ascii_p16
)+1),
895 encode_bits
, (uint32
)pwd
->pass_last_set_time
);
896 wr_len
= strlen(ascii_p16
);
899 #ifdef DEBUG_PASSWORD
900 DEBUG(100,("mod_smbfilepwd_entry: "));
901 dump_data(100, ascii_p16
, wr_len
);
904 if(wr_len
> sizeof(linebuf
)) {
905 DEBUG(0, ("mod_smbfilepwd_entry: line to write (%d) is too long.\n", wr_len
+1));
906 pw_file_unlock(lockfd
,&pw_file_lock_depth
);
912 * Do an atomic write into the file at the position defined by
916 /* The mod user write needs to be atomic - so get the fd from
917 the fp and do a raw write() call.
922 if (sys_lseek(fd
, pwd_seekpos
- 1, SEEK_SET
) != pwd_seekpos
- 1) {
923 DEBUG(0, ("mod_smbfilepwd_entry: seek fail on file %s.\n", pfile
));
924 pw_file_unlock(lockfd
,&pw_file_lock_depth
);
929 /* Sanity check - ensure the areas we are writing are framed by ':' */
930 if (read(fd
, linebuf
, wr_len
+1) != wr_len
+1) {
931 DEBUG(0, ("mod_smbfilepwd_entry: read fail on file %s.\n", pfile
));
932 pw_file_unlock(lockfd
,&pw_file_lock_depth
);
937 if ((linebuf
[0] != ':') || (linebuf
[wr_len
] != ':')) {
938 DEBUG(0, ("mod_smbfilepwd_entry: check on passwd file %s failed.\n", pfile
));
939 pw_file_unlock(lockfd
,&pw_file_lock_depth
);
944 if (sys_lseek(fd
, pwd_seekpos
, SEEK_SET
) != pwd_seekpos
) {
945 DEBUG(0, ("mod_smbfilepwd_entry: seek fail on file %s.\n", pfile
));
946 pw_file_unlock(lockfd
,&pw_file_lock_depth
);
951 if (write(fd
, ascii_p16
, wr_len
) != wr_len
) {
952 DEBUG(0, ("mod_smbfilepwd_entry: write failed in passwd file %s\n", pfile
));
953 pw_file_unlock(lockfd
,&pw_file_lock_depth
);
958 pw_file_unlock(lockfd
,&pw_file_lock_depth
);
964 * Stub functions - implemented in terms of others.
967 static BOOL
mod_smbfile21pwd_entry(struct sam_passwd
* pwd
, BOOL override
)
969 return mod_smbfilepwd_entry(pdb_sam_to_smb(pwd
), override
);
972 static BOOL
add_smbfile21pwd_entry(struct sam_passwd
*newpwd
)
974 return add_smbfilepwd_entry(pdb_sam_to_smb(newpwd
));
977 static struct sam_disp_info
*getsmbfiledispnam(char *name
)
979 return pdb_sam_to_dispinfo(getsam21pwnam(name
));
982 static struct sam_disp_info
*getsmbfiledisprid(uint32 rid
)
984 return pdb_sam_to_dispinfo(getsam21pwrid(rid
));
987 static struct sam_disp_info
*getsmbfiledispent(void *vp
)
989 return pdb_sam_to_dispinfo(getsam21pwent(vp
));
992 static struct passdb_ops file_ops
= {
997 iterate_getsmbpwnam
, /* In passdb.c */
998 iterate_getsmbpwuid
, /* In passdb.c */
999 iterate_getsmbpwrid
, /* In passdb.c */
1001 add_smbfilepwd_entry
,
1002 mod_smbfilepwd_entry
,
1004 iterate_getsam21pwnam
,
1005 iterate_getsam21pwuid
,
1006 iterate_getsam21pwrid
,
1007 add_smbfile21pwd_entry
,
1008 mod_smbfile21pwd_entry
,
1014 struct passdb_ops
*file_initialize_password_db(void)
1020 /* Do *NOT* make this function static. It breaks the compile on gcc. JRA */
1021 void smbpass_dummy_function(void) { } /* stop some compilers complaining */
1022 #endif /* USE_SMBPASS_DB */