summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2001-05-22 19:24:53 +0000
committerJeremy Allison <jra@samba.org>2001-05-22 19:24:53 +0000
commitc32840f3d9d65505cc539da40e0d625d3aa91ef0 (patch)
tree8faf48178956d2584951de7c3a5719678385521b
parentcb0189dd02241b776899e599db9ca0331fea96e0 (diff)
downloadsamba-c32840f3d9d65505cc539da40e0d625d3aa91ef0.tar.gz
samba-c32840f3d9d65505cc539da40e0d625d3aa91ef0.tar.xz
samba-c32840f3d9d65505cc539da40e0d625d3aa91ef0.zip
Clean up the brlock database on exit as well as init.
Jeremy.
-rw-r--r--source/include/proto.h1
-rw-r--r--source/locking/brlock.c49
-rw-r--r--source/locking/locking.c12
-rw-r--r--source/smbd/reply.c69
4 files changed, 89 insertions, 42 deletions
diff --git a/source/include/proto.h b/source/include/proto.h
index daafb00d957..4b35d62b0ae 100644
--- a/source/include/proto.h
+++ b/source/include/proto.h
@@ -1199,6 +1199,7 @@ struct packet_struct *receive_unexpected(enum packet_type packet_type, int id,
/*The following definitions come from locking/brlock.c */
void brl_init(int read_only);
+void brl_shutdown(int read_only);
BOOL brl_lock(SMB_DEV_T dev, SMB_INO_T ino, int fnum,
uint16 smbpid, pid_t pid, uint16 tid,
br_off start, br_off size,
diff --git a/source/locking/brlock.c b/source/locking/brlock.c
index 175ab5c9b0a..1c68401aabc 100644
--- a/source/locking/brlock.c
+++ b/source/locking/brlock.c
@@ -113,12 +113,16 @@ static BOOL brl_conflict(struct lock_struct *lck1,
/****************************************************************************
-delete a record if it is for a dead process
+ Delete a record if it is for a dead process, if check_self is true, then
+ delete any records belonging to this pid also (there shouldn't be any).
****************************************************************************/
+
static int delete_fn(TDB_CONTEXT *ttdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state)
{
struct lock_struct *locks;
int count, i;
+ BOOL check_self = *(BOOL *)state;
+ pid_t mypid = sys_getpid();
tdb_chainlock(tdb, kbuf);
@@ -128,7 +132,20 @@ static int delete_fn(TDB_CONTEXT *ttdb, TDB_DATA kbuf, TDB_DATA dbuf, void *stat
for (i=0; i<count; i++) {
struct lock_struct *lock = &locks[i];
- if (process_exists(lock->context.pid)) continue;
+ /* If check_self is true we want to remove our own records. */
+ if (check_self && (mypid == lock->context.pid)) {
+
+ DEBUG(0,("locking : delete_fn. LOGIC ERROR ! Shutting down and a record for my pid (%u) exists !\n",
+ (unsigned int)lock->context.pid ));
+
+ } else if (process_exists(lock->context.pid)) {
+
+ DEBUG(10,("locking : delete_fn. pid %u exists.\n", (unsigned int)lock->context.pid ));
+ continue;
+ }
+
+ DEBUG(10,("locking : delete_fn. Deleting record for process %u\n",
+ (unsigned int)lock->context.pid ));
if (count > 1 && i < count-1) {
memmove(&locks[i], &locks[i+1],
@@ -152,9 +169,13 @@ static int delete_fn(TDB_CONTEXT *ttdb, TDB_DATA kbuf, TDB_DATA dbuf, void *stat
/****************************************************************************
Open up the brlock.tdb database.
****************************************************************************/
+
void brl_init(int read_only)
{
- if (tdb) return;
+ BOOL check_self = False;
+
+ if (tdb)
+ return;
tdb = tdb_open(lock_path("brlock.tdb"), 0, TDB_CLEAR_IF_FIRST,
read_only?O_RDONLY:(O_RDWR|O_CREAT), 0644);
if (!tdb) {
@@ -163,11 +184,27 @@ void brl_init(int read_only)
}
/* delete any dead locks */
- if (!read_only) {
- tdb_traverse(tdb, delete_fn, NULL);
- }
+ if (!read_only)
+ tdb_traverse(tdb, delete_fn, &check_self);
}
+/****************************************************************************
+ Close down the brlock.tdb database.
+****************************************************************************/
+
+void brl_shutdown(int read_only)
+{
+ BOOL check_self = True;
+
+ if (tdb)
+ return;
+
+ /* delete any dead locks */
+ if (!read_only)
+ tdb_traverse(tdb, delete_fn, &check_self);
+
+ tdb_close(tdb);
+}
/****************************************************************************
Lock a range of bytes.
diff --git a/source/locking/locking.c b/source/locking/locking.c
index 5824287e913..fa642a14887 100644
--- a/source/locking/locking.c
+++ b/source/locking/locking.c
@@ -217,11 +217,15 @@ void locking_close_file(files_struct *fsp)
/****************************************************************************
Initialise the locking functions.
****************************************************************************/
+
+static int open_read_only;
+
BOOL locking_init(int read_only)
{
brl_init(read_only);
- if (tdb) return True;
+ if (tdb)
+ return True;
tdb = tdb_open(lock_path("locking.tdb"),
0, TDB_CLEAR_IF_FIRST,
@@ -236,6 +240,8 @@ BOOL locking_init(int read_only)
if (!posix_locking_init(read_only))
return False;
+ open_read_only = read_only;
+
return True;
}
@@ -244,7 +250,9 @@ BOOL locking_init(int read_only)
******************************************************************/
BOOL locking_end(void)
{
- if (tdb && tdb_close(tdb) != 0) return False;
+ brl_shutdown(open_read_only);
+ if (tdb && tdb_close(tdb) != 0)
+ return False;
return True;
}
diff --git a/source/smbd/reply.c b/source/smbd/reply.c
index fc77a5424f4..800d762c9bb 100644
--- a/source/smbd/reply.c
+++ b/source/smbd/reply.c
@@ -558,47 +558,48 @@ static BOOL check_server_security(char *orig_user, char *domain, char *unix_user
char *smb_apasswd, int smb_apasslen,
char *smb_ntpasswd, int smb_ntpasslen)
{
- BOOL ret = False;
+ BOOL ret = False;
- if(lp_security() != SEC_SERVER)
- return False;
+ if(lp_security() != SEC_SERVER)
+ return False;
- if (!check_domain_match(orig_user, domain))
- return False;
+ if (!check_domain_match(orig_user, domain))
+ return False;
- ret = server_validate(orig_user, domain,
- smb_apasswd, smb_apasslen,
- smb_ntpasswd, smb_ntpasslen);
- if(ret) {
- struct passwd *pwd = NULL;
+ ret = server_validate(orig_user, domain,
+ smb_apasswd, smb_apasslen,
+ smb_ntpasswd, smb_ntpasslen);
- /*
- * User validated ok against Domain controller.
- * If the admin wants us to try and create a UNIX
- * user on the fly, do so.
- * Note that we can never delete users when in server
- * level security as we never know if it was a failure
- * due to a bad password, or the user really doesn't exist.
- */
- if(lp_adduser_script() && !(pwd = smb_getpwnam(unix_user,True))) {
- smb_create_user(unix_user, NULL);
- }
+ if(ret) {
+ struct passwd *pwd = NULL;
- if(lp_adduser_script() && pwd) {
- SMB_STRUCT_STAT st;
+ /*
+ * User validated ok against Domain controller.
+ * If the admin wants us to try and create a UNIX
+ * user on the fly, do so.
+ * Note that we can never delete users when in server
+ * level security as we never know if it was a failure
+ * due to a bad password, or the user really doesn't exist.
+ */
- /*
- * Also call smb_create_user if the users home directory
- * doesn't exist. Used with winbindd to allow the script to
- * create the home directory for a user mapped with winbindd.
- */
+ if(lp_adduser_script() && !(pwd = smb_getpwnam(unix_user,True)))
+ smb_create_user(unix_user, NULL);
- if (pwd->pw_shell && (sys_stat(pwd->pw_dir, &st) == -1) && (errno == ENOENT))
- smb_create_user(unix_user, pwd->pw_dir);
- }
- }
+ if(lp_adduser_script() && pwd) {
+ SMB_STRUCT_STAT st;
- return ret;
+ /*
+ * Also call smb_create_user if the users home directory
+ * doesn't exist. Used with winbindd to allow the script to
+ * create the home directory for a user mapped with winbindd.
+ */
+
+ if (pwd->pw_dir && (sys_stat(pwd->pw_dir, &st) == -1) && (errno == ENOENT))
+ smb_create_user(unix_user, pwd->pw_dir);
+ }
+ }
+
+ return ret;
}
/****************************************************************************
@@ -643,7 +644,7 @@ static BOOL check_domain_security(char *orig_user, char *domain, char *unix_user
* create the home directory for a user mapped with winbindd.
*/
- if (pwd->pw_shell && (sys_stat(pwd->pw_dir, &st) == -1) && (errno == ENOENT))
+ if (pwd->pw_dir && (sys_stat(pwd->pw_dir, &st) == -1) && (errno == ENOENT))
smb_create_user(unix_user, pwd->pw_dir);
}