summaryrefslogtreecommitdiff
path: root/source3/passdb/smbpass.c
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>1998-04-29 22:27:26 +0000
committerJeremy Allison <jra@samba.org>1998-04-29 22:27:26 +0000
commit90177708aaf5bf17d689979701b5f0156b8a2fa4 (patch)
treedcca0199c3d534976a204b8cd936109fbe5e69d8 /source3/passdb/smbpass.c
parente305c2c9e2e657974d34d1d58a8f9372921fdae2 (diff)
downloadsamba-90177708aaf5bf17d689979701b5f0156b8a2fa4.tar.gz
samba-90177708aaf5bf17d689979701b5f0156b8a2fa4.tar.bz2
samba-90177708aaf5bf17d689979701b5f0156b8a2fa4.zip
Makefile: Added files to smbpasswd.c.
loadparm.c: Patch from tim@quiknet.com for static string problems. server.c: Setup global_myname. smbpass.c: Fix up locking. Add machine_password_delete() call. smbpasswd.c: Added provisional code to add to a domain. lib/rpc/client/cli_login.c: Fixed incorrect cred_hash3 call when setting machine password. lib/rpc/server/srv_netlog.c: Fixed incorrect cred_hash3 call when setting machine password. Jeremy. (This used to be commit 6a7164233e3bf9d6bb57c44a53204068e454ae5c)
Diffstat (limited to 'source3/passdb/smbpass.c')
-rw-r--r--source3/passdb/smbpass.c81
1 files changed, 54 insertions, 27 deletions
diff --git a/source3/passdb/smbpass.c b/source3/passdb/smbpass.c
index aa3a694567..2ab21f78ef 100644
--- a/source3/passdb/smbpass.c
+++ b/source3/passdb/smbpass.c
@@ -80,7 +80,7 @@ static BOOL pw_file_lock(int fd, int type, int secs, int *plock_depth)
(*plock_depth)++;
if(pw_file_lock_depth == 0) {
- if (do_pw_lock(fd, secs, type)) {
+ if (!do_pw_lock(fd, secs, type)) {
DEBUG(10,("pw_file_lock: locking file failed, error = %s.\n",
strerror(errno)));
return False;
@@ -135,7 +135,7 @@ void *startsmbpwent(BOOL update)
/* Set a 16k buffer to do more efficient reads */
setvbuf(fp, s_readbuf, _IOFBF, sizeof(s_readbuf));
- if (!pw_file_lock(fileno(fp), F_RDLCK | (update ? F_WRLCK : 0), 5, &pw_file_lock_depth))
+ if (!pw_file_lock(fileno(fp), (update ? F_WRLCK : F_RDLCK), 5, &pw_file_lock_depth))
{
DEBUG(0, ("startsmbpwent: unable to lock file %s\n", pfile));
fclose(fp);
@@ -774,7 +774,7 @@ BOOL mod_smbpwd_entry(struct smb_passwd* pwd)
lockfd = fileno(fp);
- if (!pw_file_lock(lockfd, F_RDLCK | F_WRLCK, 5, &pw_file_lock_depth)) {
+ if (!pw_file_lock(lockfd, F_WRLCK, 5, &pw_file_lock_depth)) {
DEBUG(0, ("mod_smbpwd_entry: unable to lock file %s\n", pfile));
fclose(fp);
return False;
@@ -1076,48 +1076,63 @@ BOOL mod_smbpwd_entry(struct smb_passwd* pwd)
static int mach_passwd_lock_depth;
/************************************************************************
- Routine to lock the machine account password file for a domain.
+ Routine to get the name for a machine account file.
************************************************************************/
-void *machine_password_lock( char *domain, char *name, BOOL update)
+static void get_machine_account_file_name( char *domain, char *name, char *mac_file)
{
- FILE *fp;
- pstring mac_file;
unsigned int mac_file_len;
char *p;
- if(mach_passwd_lock_depth == 0) {
+ pstrcpy(mac_file, lp_smb_passwd_file());
+ p = strrchr(mac_file, '/');
+ if(p != NULL)
+ *++p = '\0';
- pstrcpy(mac_file, lp_smb_passwd_file());
- p = strrchr(mac_file, '/');
+ mac_file_len = strlen(mac_file);
- if(p != NULL)
- *++p = '\0';
+ if (sizeof(pstring) - mac_file_len - strlen(domain) - strlen(name) - 6 < 0)
+ {
+ DEBUG(0,("machine_password_lock: path %s too long to add machine details.\n",
+ mac_file));
+ return;
+ }
- mac_file_len = strlen(mac_file);
+ strcat(mac_file, domain);
+ strcat(mac_file, ".");
+ strcat(mac_file, name);
+ strcat(mac_file, ".mac");
+}
+
+/************************************************************************
+ Routine to lock the machine account password file for a domain.
+************************************************************************/
- if (sizeof(pstring) - mac_file_len - strlen(domain) - strlen(name) - 6 < 0)
- {
- DEBUG(0,("machine_password_lock: path %s too long to add machine details.\n",
- mac_file));
- return NULL;
- }
+void *machine_password_lock( char *domain, char *name, BOOL update)
+{
+ FILE *fp;
+ pstring mac_file;
+
+ if(mach_passwd_lock_depth == 0) {
- strcat(mac_file, domain);
- strcat(mac_file, ".");
- strcat(mac_file, name);
- strcat(mac_file, ".mac");
+ get_machine_account_file_name( domain, name, mac_file);
if((fp = fopen(mac_file, "r+b")) == NULL) {
- DEBUG(0,("machine_password_lock: cannot open file %s - Error was %s.\n",
- mac_file, strerror(errno) ));
- return NULL;
+ if(errno == ENOENT && update) {
+ fp = fopen(mac_file, "w+b");
+ }
+
+ if(fp == NULL) {
+ DEBUG(0,("machine_password_lock: cannot open file %s - Error was %s.\n",
+ mac_file, strerror(errno) ));
+ return NULL;
+ }
}
chmod(mac_file, 0600);
}
- if(!pw_file_lock(fileno(fp), F_RDLCK | (update ? F_WRLCK : 0),
+ if(!pw_file_lock(fileno(fp), (update ? F_WRLCK : F_RDLCK),
60, &mach_passwd_lock_depth))
{
DEBUG(0,("machine_password_lock: cannot lock file %s\n", mac_file));
@@ -1142,6 +1157,18 @@ BOOL machine_password_unlock( void *token )
}
/************************************************************************
+ Routine to delete the machine account password file for a domain.
+************************************************************************/
+
+BOOL machine_password_delete( char *domain, char *name )
+{
+ pstring mac_file;
+
+ get_machine_account_file_name( domain, name, mac_file);
+ return (unlink( mac_file ) == 0);
+}
+
+/************************************************************************
Routine to get the machine account password for a domain.
The user of this function must have locked the machine password file.
************************************************************************/