summaryrefslogtreecommitdiffstats
path: root/source/smbd/connection.c
diff options
context:
space:
mode:
authorGerald Carter <jerry@samba.org>2002-09-25 15:19:00 +0000
committerGerald Carter <jerry@samba.org>2002-09-25 15:19:00 +0000
commit65e7b5273bb58802bf0c389b77f7fcae0a1f6139 (patch)
tree672f59370f72efa2b3f4471bf311e0159e004a13 /source/smbd/connection.c
parentb5d03c7b55fb2f34fa4d0228abe4389020e5ed5f (diff)
downloadsamba-65e7b5273bb58802bf0c389b77f7fcae0a1f6139.tar.gz
samba-65e7b5273bb58802bf0c389b77f7fcae0a1f6139.tar.xz
samba-65e7b5273bb58802bf0c389b77f7fcae0a1f6139.zip
sync'ing up for 3.0alpha20 release
Diffstat (limited to 'source/smbd/connection.c')
-rw-r--r--source/smbd/connection.c84
1 files changed, 63 insertions, 21 deletions
diff --git a/source/smbd/connection.c b/source/smbd/connection.c
index 5609c2963d8..ad394a01ca0 100644
--- a/source/smbd/connection.c
+++ b/source/smbd/connection.c
@@ -28,14 +28,24 @@ static TDB_CONTEXT *tdb;
TDB_CONTEXT *conn_tdb_ctx(void)
{
- if (!tdb) {
+ if (!tdb)
tdb = tdb_open_log(lock_path("connections.tdb"), 0, TDB_CLEAR_IF_FIRST|TDB_DEFAULT,
O_RDWR | O_CREAT, 0644);
- }
return tdb;
}
+static void make_conn_key(connection_struct *conn,char *name, TDB_DATA *pkbuf, struct connections_key *pkey)
+{
+ ZERO_STRUCTP(pkey);
+ pkey->pid = sys_getpid();
+ pkey->cnum = conn?conn->cnum:-1;
+ fstrcpy(pkey->name, name);
+
+ pkbuf->dptr = (char *)pkey;
+ pkbuf->dsize = sizeof(*pkey);
+}
+
/****************************************************************************
Delete a connection record.
****************************************************************************/
@@ -45,17 +55,12 @@ BOOL yield_connection(connection_struct *conn,char *name)
struct connections_key key;
TDB_DATA kbuf;
- if (!tdb) return False;
+ if (!tdb)
+ return False;
DEBUG(3,("Yielding connection to %s\n",name));
- ZERO_STRUCT(key);
- key.pid = sys_getpid();
- key.cnum = conn?conn->cnum:-1;
- fstrcpy(key.name, name);
-
- kbuf.dptr = (char *)&key;
- kbuf.dsize = sizeof(key);
+ make_conn_key(conn, name, &kbuf, &key);
if (tdb_delete(tdb, kbuf) != 0) {
int dbg_lvl = (!conn && (tdb_error(tdb) == TDB_ERR_NOEXIST)) ? 3 : 0;
@@ -88,7 +93,7 @@ static int count_fn( TDB_CONTEXT *the_tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *u
memcpy(&crec, dbuf.dptr, sizeof(crec));
- if (crec.cnum == -1)
+ if (crec.cnum == -1)
return 0;
/* If the pid was not found delete the entry from connections.tdb */
@@ -111,16 +116,16 @@ static int count_fn( TDB_CONTEXT *the_tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *u
Claim an entry in the connections database.
****************************************************************************/
-BOOL claim_connection(connection_struct *conn,char *name,int max_connections,BOOL Clear)
+BOOL claim_connection(connection_struct *conn,char *name,int max_connections,BOOL Clear, uint32 msg_flags)
{
struct connections_key key;
struct connections_data crec;
TDB_DATA kbuf, dbuf;
- if (!tdb) {
+ if (!tdb)
tdb = tdb_open_log(lock_path("connections.tdb"), 0, TDB_CLEAR_IF_FIRST|TDB_DEFAULT,
O_RDWR | O_CREAT, 0644);
- }
+
if (!tdb)
return False;
@@ -156,13 +161,7 @@ BOOL claim_connection(connection_struct *conn,char *name,int max_connections,BOO
DEBUG(5,("claiming %s %d\n",name,max_connections));
- ZERO_STRUCT(key);
- key.pid = sys_getpid();
- key.cnum = conn?conn->cnum:-1;
- fstrcpy(key.name, name);
-
- kbuf.dptr = (char *)&key;
- kbuf.dsize = sizeof(key);
+ make_conn_key(conn, name, &kbuf, &key);
/* fill in the crec */
ZERO_STRUCT(crec);
@@ -176,6 +175,7 @@ BOOL claim_connection(connection_struct *conn,char *name,int max_connections,BOO
lp_servicename(SNUM(conn)),sizeof(crec.name)-1);
}
crec.start = time(NULL);
+ crec.bcast_msg_flags = msg_flags;
StrnCpy(crec.machine,get_remote_machine_name(),sizeof(crec.machine)-1);
StrnCpy(crec.addr,conn?conn->client_address:client_addr(),sizeof(crec.addr)-1);
@@ -191,3 +191,45 @@ BOOL claim_connection(connection_struct *conn,char *name,int max_connections,BOO
return True;
}
+
+BOOL register_message_flags(BOOL doreg, uint32 msg_flags)
+{
+ struct connections_key key;
+ struct connections_data *pcrec;
+ TDB_DATA kbuf, dbuf;
+
+ if (!tdb)
+ return False;
+
+ DEBUG(10,("register_message_flags: %s flags 0x%x\n",
+ doreg ? "adding" : "removing",
+ (unsigned int)msg_flags ));
+
+ make_conn_key(NULL, "", &kbuf, &key);
+
+ dbuf = tdb_fetch(tdb, kbuf);
+ if (!dbuf.dptr) {
+ DEBUG(0,("register_message_flags: tdb_fetch failed\n"));
+ return False;
+ }
+
+ pcrec = (struct connections_data *)dbuf.dptr;
+ pcrec->bcast_msg_flags = msg_flags;
+ if (doreg)
+ pcrec->bcast_msg_flags |= msg_flags;
+ else
+ pcrec->bcast_msg_flags &= ~msg_flags;
+
+ if (tdb_store(tdb, kbuf, dbuf, TDB_REPLACE) != 0) {
+ DEBUG(0,("register_message_flags: tdb_store failed with error %s.\n",
+ tdb_errorstr(tdb) ));
+ SAFE_FREE(dbuf.dptr);
+ return False;
+ }
+
+ DEBUG(10,("register_message_flags: new flags 0x%x\n",
+ (unsigned int)pcrec->bcast_msg_flags ));
+
+ SAFE_FREE(dbuf.dptr);
+ return True;
+}