summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Leighton <lkcl@samba.org>1997-11-08 14:23:49 +0000
committerLuke Leighton <lkcl@samba.org>1997-11-08 14:23:49 +0000
commita81dd62af0321e0c78f81ea79605dade3e563f7a (patch)
tree2207bf4cae161897ec8f92d971b2399a1879e95d
parentfbb57e5923a0da03033d3d2084547c12ca351d66 (diff)
downloadsamba-a81dd62af0321e0c78f81ea79605dade3e563f7a.tar.gz
samba-a81dd62af0321e0c78f81ea79605dade3e563f7a.tar.bz2
samba-a81dd62af0321e0c78f81ea79605dade3e563f7a.zip
mod_smbpasswd() was junking the smbpasswd file...
uninitialised variable warnings. (This used to be commit 1b0bd98bb3bfd3d8cd02e8983e825199e839ec05)
-rw-r--r--source3/passdb/smbpass.c196
1 files changed, 99 insertions, 97 deletions
diff --git a/source3/passdb/smbpass.c b/source3/passdb/smbpass.c
index 2c533f16f9..cc0e1fd26d 100644
--- a/source3/passdb/smbpass.c
+++ b/source3/passdb/smbpass.c
@@ -567,13 +567,13 @@ BOOL mod_smbpwd_entry(struct smb_passwd* pwd)
char readbuf[16 * 1024];
unsigned char c;
char ascii_p16[66];
- unsigned char *p;
- long linebuf_len;
+ unsigned char *p = NULL;
+ long linebuf_len = 0;
FILE *fp;
int lockfd;
char *pfile = lp_smb_passwd_file();
+ BOOL found_entry = False;
- BOOL found_entry = True;
long pwd_seekpos = 0;
int i;
@@ -585,13 +585,13 @@ BOOL mod_smbpwd_entry(struct smb_passwd* pwd)
DEBUG(0, ("No SMB password file set\n"));
return False;
}
- DEBUG(10, ("add_smbpwd_entry: opening file %s\n", pfile));
+ DEBUG(10, ("mod_smbpwd_entry: opening file %s\n", pfile));
fp = fopen(pfile, "r+");
if (fp == NULL)
{
- DEBUG(0, ("add_smbpwd_entry: unable to open file %s\n", pfile));
+ DEBUG(0, ("mod_smbpwd_entry: unable to open file %s\n", pfile));
return False;
}
/* Set a 16k buffer to do more efficient reads */
@@ -599,7 +599,7 @@ BOOL mod_smbpwd_entry(struct smb_passwd* pwd)
if ((lockfd = pw_file_lock(pfile, F_RDLCK | F_WRLCK, 5)) < 0)
{
- DEBUG(0, ("add_smbpwd_entry: unable to lock file %s\n", pfile));
+ DEBUG(0, ("mod_smbpwd_entry: unable to lock file %s\n", pfile));
fclose(fp);
return False;
}
@@ -647,12 +647,12 @@ BOOL mod_smbpwd_entry(struct smb_passwd* pwd)
}
#ifdef DEBUG_PASSWORD
- DEBUG(100, ("add_smbpwd_entry: got line |%s|\n", linebuf));
+ DEBUG(100, ("mod_smbpwd_entry: got line |%s|\n", linebuf));
#endif
if ((linebuf[0] == 0) && feof(fp))
{
- DEBUG(4, ("add_smbpwd_entry: end of file reached\n"));
+ DEBUG(4, ("mod_smbpwd_entry: end of file reached\n"));
break;
}
@@ -671,7 +671,7 @@ BOOL mod_smbpwd_entry(struct smb_passwd* pwd)
if (linebuf[0] == '#' || linebuf[0] == '\0')
{
- DEBUG(6, ("add_smbpwd_entry: skipping comment or blank line\n"));
+ DEBUG(6, ("mod_smbpwd_entry: skipping comment or blank line\n"));
continue;
}
@@ -679,7 +679,7 @@ BOOL mod_smbpwd_entry(struct smb_passwd* pwd)
if (p == NULL)
{
- DEBUG(0, ("add_smbpwd_entry: malformed password entry (no :)\n"));
+ DEBUG(0, ("mod_smbpwd_entry: malformed password entry (no :)\n"));
continue;
}
@@ -691,110 +691,112 @@ BOOL mod_smbpwd_entry(struct smb_passwd* pwd)
user_name[PTR_DIFF(p, linebuf)] = '\0';
if (strequal(user_name, pwd->smb_name))
{
- DEBUG(6, ("add_smbpwd_entry: entry already exists\n"));
found_entry = True;
break;
}
+ }
- /* User name matches - get uid and password */
- p++; /* Go past ':' */
+ if (!found_entry) return False;
- if (!isdigit(*p))
- {
- DEBUG(0, ("mod_smbpwd_entry: malformed password entry (uid not number)\n"));
- fclose(fp);
- pw_file_unlock(lockfd);
- return False;
- }
+ DEBUG(6, ("mod_smbpwd_entry: entry exists\n"));
- while (*p && isdigit(*p))
- p++;
- if (*p != ':')
- {
- DEBUG(0, ("mod_smbpwd_entry: malformed password entry (no : after uid)\n"));
- fclose(fp);
- pw_file_unlock(lockfd);
- return False;
- }
- /*
- * Now get the password value - this should be 32 hex digits
- * which are the ascii representations of a 16 byte string.
- * Get two at a time and put them into the password.
- */
- p++;
+ /* User name matches - get uid and password */
+ p++; /* Go past ':' */
- /* record exact password position */
- pwd_seekpos += PTR_DIFF(p, linebuf);
+ if (!isdigit(*p))
+ {
+ DEBUG(0, ("mod_smbpwd_entry: malformed password entry (uid not number)\n"));
+ fclose(fp);
+ pw_file_unlock(lockfd);
+ return False;
+ }
- if (*p == '*' || *p == 'X')
- {
- /* Password deliberately invalid - end here. */
- DEBUG(10, ("get_smbpwd_entry: entry invalidated for user %s\n", user_name));
- fclose(fp);
- pw_file_unlock(lockfd);
- return False;
- }
+ while (*p && isdigit(*p))
+ p++;
+ if (*p != ':')
+ {
+ DEBUG(0, ("mod_smbpwd_entry: malformed password entry (no : after uid)\n"));
+ fclose(fp);
+ pw_file_unlock(lockfd);
+ return False;
+ }
+ /*
+ * Now get the password value - this should be 32 hex digits
+ * which are the ascii representations of a 16 byte string.
+ * Get two at a time and put them into the password.
+ */
+ p++;
- if (linebuf_len < (PTR_DIFF(p, linebuf) + 33))
- {
- DEBUG(0, ("mod_smbpwd_entry: malformed password entry (passwd too short)\n"));
- fclose(fp);
- pw_file_unlock(lockfd);
- return (False);
- }
+ /* record exact password position */
+ pwd_seekpos += PTR_DIFF(p, linebuf);
- if (p[32] != ':')
- {
- DEBUG(0, ("mod_smbpwd_entry: malformed password entry (no terminating :)\n"));
- fclose(fp);
- pw_file_unlock(lockfd);
- return False;
- }
+ if (*p == '*' || *p == 'X')
+ {
+ /* Password deliberately invalid - end here. */
+ DEBUG(10, ("get_smbpwd_entry: entry invalidated for user %s\n", user_name));
+ fclose(fp);
+ pw_file_unlock(lockfd);
+ return False;
+ }
- if (*p == '*' || *p == 'X')
- {
- fclose(fp);
- pw_file_unlock(lockfd);
- return False;
- }
- if (!strncasecmp((char *) p, "NO PASSWORD", 11))
- {
- fclose(fp);
- pw_file_unlock(lockfd);
- return False;
- }
+ if (linebuf_len < (PTR_DIFF(p, linebuf) + 33))
+ {
+ DEBUG(0, ("mod_smbpwd_entry: malformed password entry (passwd too short)\n"));
+ fclose(fp);
+ pw_file_unlock(lockfd);
+ return (False);
+ }
- /* Now check if the NT compatible password is
- available. */
- p += 33; /* Move to the first character of the line after
- the lanman password. */
- if (linebuf_len < (PTR_DIFF(p, linebuf) + 33))
- {
- DEBUG(0, ("mod_smbpwd_entry: malformed password entry (passwd too short)\n"));
- fclose(fp);
- pw_file_unlock(lockfd);
- return (False);
- }
+ if (p[32] != ':')
+ {
+ DEBUG(0, ("mod_smbpwd_entry: malformed password entry (no terminating :)\n"));
+ fclose(fp);
+ pw_file_unlock(lockfd);
+ return False;
+ }
- if (p[32] != ':')
- {
- DEBUG(0, ("mod_smbpwd_entry: malformed password entry (no terminating :)\n"));
- fclose(fp);
- pw_file_unlock(lockfd);
- return False;
- }
+ if (*p == '*' || *p == 'X')
+ {
+ fclose(fp);
+ pw_file_unlock(lockfd);
+ return False;
+ }
+ if (!strncasecmp((char *) p, "NO PASSWORD", 11))
+ {
+ fclose(fp);
+ pw_file_unlock(lockfd);
+ return False;
+ }
- if (*p == '*' || *p == 'X')
- {
- fclose(fp);
- pw_file_unlock(lockfd);
- return False;
- }
+ /* Now check if the NT compatible password is
+ available. */
+ p += 33; /* Move to the first character of the line after
+ the lanman password. */
+ if (linebuf_len < (PTR_DIFF(p, linebuf) + 33))
+ {
+ DEBUG(0, ("mod_smbpwd_entry: malformed password entry (passwd too short)\n"));
+ fclose(fp);
+ pw_file_unlock(lockfd);
+ return (False);
+ }
- /* whew. entry is correctly formed. */
- break;
+ if (p[32] != ':')
+ {
+ DEBUG(0, ("mod_smbpwd_entry: malformed password entry (no terminating :)\n"));
+ fclose(fp);
+ pw_file_unlock(lockfd);
+ return False;
+ }
+
+ if (*p == '*' || *p == 'X')
+ {
+ fclose(fp);
+ pw_file_unlock(lockfd);
+ return False;
}
+ /* whew. entry is correctly formed. */
+
/*
* Do an atomic write into the file at the position defined by
* seekpos.