smbd: some write time fixes
[tprouty/samba.git] / source / smbd / connection.c
index 65b7c352c550368ed1fbeb13d9525f574706889d..d7063c99894bcfd948d5c48d3162feea5b0c35a5 100644 (file)
@@ -23,7 +23,7 @@
  Delete a connection record.
 ****************************************************************************/
 
-BOOL yield_connection(connection_struct *conn, const char *name)
+bool yield_connection(connection_struct *conn, const char *name)
 {
        struct db_record *rec;
        NTSTATUS status;
@@ -50,7 +50,7 @@ struct count_stat {
        pid_t mypid;
        int curr_connections;
        const char *name;
-       BOOL Clear;
+       bool Clear;
 };
 
 /****************************************************************************
@@ -94,7 +94,7 @@ static int count_fn(struct db_record *rec,
  Claim an entry in the connections database.
 ****************************************************************************/
 
-int count_current_connections( const char *sharename, BOOL clear  )
+int count_current_connections( const char *sharename, bool clear  )
 {
        struct count_stat cs;
 
@@ -117,21 +117,31 @@ int count_current_connections( const char *sharename, BOOL clear  )
        return cs.curr_connections;
 }
 
+/****************************************************************************
+ Count the number of connections open across all shares.
+****************************************************************************/
+
+int count_all_current_connections(void)
+{
+        return count_current_connections(NULL, True /* clear stale entries */);
+}
+
 /****************************************************************************
  Claim an entry in the connections database.
 ****************************************************************************/
 
-BOOL claim_connection(connection_struct *conn, const char *name,
+bool claim_connection(connection_struct *conn, const char *name,
                      uint32 msg_flags)
 {
        struct db_record *rec;
        struct connections_data crec;
        TDB_DATA dbuf;
        NTSTATUS status;
+       char addr[INET6_ADDRSTRLEN];
 
        DEBUG(5,("claiming [%s]\n", name));
 
-       if (!(rec = connections_fetch_entry(NULL, conn, name))) {
+       if (!(rec = connections_fetch_entry(talloc_tos(), conn, name))) {
                DEBUG(0, ("connections_fetch_entry failed\n"));
                return False;
        }
@@ -151,7 +161,8 @@ BOOL claim_connection(connection_struct *conn, const char *name,
        crec.bcast_msg_flags = msg_flags;
        
        strlcpy(crec.machine,get_remote_machine_name(),sizeof(crec.machine));
-       strlcpy(crec.addr,conn?conn->client_address:client_addr(),
+       strlcpy(crec.addr,conn?conn->client_address:
+                       client_addr(get_client_fd(),addr,sizeof(addr)),
                sizeof(crec.addr));
 
        dbuf.dptr = (uint8 *)&crec;
@@ -170,7 +181,7 @@ BOOL claim_connection(connection_struct *conn, const char *name,
        return True;
 }
 
-BOOL register_message_flags(BOOL doreg, uint32 msg_flags)
+bool register_message_flags(bool doreg, uint32 msg_flags)
 {
        struct db_record *rec;
        struct connections_data *pcrec;
@@ -255,13 +266,13 @@ static void fill_pipe_open_rec( struct pipe_open_rec *prec, smb_np_struct *p )
 /*********************************************************************
 *********************************************************************/
 
-BOOL store_pipe_opendb( smb_np_struct *p )
+bool store_pipe_opendb( smb_np_struct *p )
 {
        struct db_record *dbrec;
        struct pipe_open_rec *prec;
        TDB_DATA *key;
        TDB_DATA data;
-       BOOL ret = False;
+       bool ret = False;
        
        if ( (prec = TALLOC_P( NULL, struct pipe_open_rec)) == NULL ) {
                DEBUG(0,("store_pipe_opendb: talloc failed!\n"));
@@ -291,12 +302,12 @@ done:
 /*********************************************************************
 *********************************************************************/
 
-BOOL delete_pipe_opendb( smb_np_struct *p )
+bool delete_pipe_opendb( smb_np_struct *p )
 {
        struct db_record *dbrec;
        struct pipe_open_rec *prec;
        TDB_DATA *key;
-       BOOL ret = False;
+       bool ret = False;
        
        if ( (prec = TALLOC_P( NULL, struct pipe_open_rec)) == NULL ) {
                DEBUG(0,("store_pipe_opendb: talloc failed!\n"));