Add bcast_msg_flags to connection struct. Allows sender to filter when
authorJeremy Allison <jra@samba.org>
Wed, 4 Sep 2002 19:13:06 +0000 (19:13 +0000)
committerJeremy Allison <jra@samba.org>
Wed, 4 Sep 2002 19:13:06 +0000 (19:13 +0000)
sending broadcast messages. Also initial cut-down of printing notify
messages (not yet finished).
Jeremy.
(This used to be commit aca333719695b278843c59e1c6eb07d6655fd59c)

source3/include/local.h
source3/include/messages.h
source3/include/smb.h
source3/lib/messages.c
source3/printing/printing.c
source3/smbd/connection.c
source3/smbd/reply.c
source3/smbd/server.c
source3/smbd/service.c

index 15231e92ee209f8822f178a688831374490762f4..5096e13fc3931230f64dbf445440d159315cd0f4 100644 (file)
 #define MAX_OPEN_FILES 10000
 #endif
  
-/* the max number of simultanous connections to the server by all clients */
-/* zero means no limit. */
-#define MAXSTATUS 0
-
 #define WORDMAX 0xFFFF
 
 /* the maximum password length before we declare a likely attack */
index 58e606b40fa453c0242319082edc501610e4a69a..0e995039ff51ea97269c44eb5f694d16d421b12c 100644 (file)
 #define MSG_SMB_SAM_SYNC     3003
 #define MSG_SMB_SAM_REPL     3004
 
+/* Flags to classify messages - used in message_send_all() */
+/* Sender will filter by flag. */
+
+#define FLAG_MSG_GENERAL       0x0001
+#define FLAG_MSG_SMBD          0x0002
+#define FLAG_MSG_NMBD          0x0004
+#define FLAG_MSG_PRINTING      0x0008
+
 #endif
index f2eb37096cd72dde5c3138f81dc6f5b2952c00bf..909c1a57ecda87c9eee63171439b126242d83a93 100644 (file)
@@ -718,6 +718,7 @@ struct connections_data {
        char addr[24];
        char machine[FSTRING_LEN];
        time_t start;
+       uint32 bcast_msg_flags;
 };
 
 
index e6d2de4a58bb26f51da7d03fe4da95d813d3b28d..21470dff5c890393be6246712d93b1fb012fe30a 100644 (file)
@@ -382,10 +382,11 @@ void message_deregister(int msg_type)
 
 struct msg_all {
        int msg_type;
+       uint32 msg_flag;
        const void *buf;
        size_t len;
        BOOL duplicates;
-       int             n_sent;
+       int n_sent;
 };
 
 /****************************************************************************
@@ -405,13 +406,20 @@ static int traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA kbuf, TDB_DATA dbuf, void
        if (crec.cnum != -1)
                return 0;
 
-       /* if the msg send fails because the pid was not found (i.e. smbd died), 
+       /* Don't send if the receiver hasn't registered an interest. */
+
+       if(!(crec.bcast_msg_flags & msg_all->msg_flag))
+               return 0;
+
+       /* If the msg send fails because the pid was not found (i.e. smbd died), 
         * the msg has already been deleted from the messages.tdb.*/
+
        if (!message_send_pid(crec.pid, msg_all->msg_type,
                              msg_all->buf, msg_all->len,
                              msg_all->duplicates)) {
                
-               /* if the pid was not found delete the entry from connections.tdb */
+               /* If the pid was not found delete the entry from connections.tdb */
+
                if (errno == ESRCH) {
                        DEBUG(2,("pid %u doesn't exist - deleting connections %d [%s]\n",
                                        (unsigned int)crec.pid, crec.cnum, crec.name));
@@ -442,6 +450,17 @@ BOOL message_send_all(TDB_CONTEXT *conn_tdb, int msg_type,
        struct msg_all msg_all;
 
        msg_all.msg_type = msg_type;
+       if (msg_type < 1000)
+               msg_all.msg_flag = FLAG_MSG_GENERAL;
+       else if (msg_type > 1000 && msg_type < 2000)
+               msg_all.msg_flag = FLAG_MSG_NMBD;
+       else if (msg_type > 2000 && msg_type < 3000)
+               msg_all.msg_flag = FLAG_MSG_PRINTING;
+       else if (msg_type > 3000 && msg_type < 4000)
+               msg_all.msg_flag = FLAG_MSG_SMBD;
+       else
+               return False;
+
        msg_all.buf = buf;
        msg_all.len = len;
        msg_all.duplicates = duplicates_allowed;
index f3ee1a0d63fdb7a9342b2d1f87d487b8c1d10de9..0dacfe820cf55594d406fdb6d0b8278cae4a5675 100644 (file)
@@ -460,7 +460,7 @@ static void pjob_store_notify(int snum, uint32 jobid, struct printjob *old_data,
  Store a job structure back to the database.
 ****************************************************************************/
 
-static BOOL pjob_store(int snum, uint32 jobid, struct printjob *pjob)
+static BOOL pjob_store(int snum, uint32 jobid, struct printjob *pjob, BOOL donotify)
 {
        TDB_DATA old_data, new_data;
        BOOL ret;
@@ -483,7 +483,7 @@ static BOOL pjob_store(int snum, uint32 jobid, struct printjob *pjob)
 
        /* Send notify updates for what has changed */
 
-       if (ret && (old_data.dsize == 0 || old_data.dsize == sizeof(*pjob))) {
+       if (donotify && ret && (old_data.dsize == 0 || old_data.dsize == sizeof(*pjob))) {
                pjob_store_notify(
                        snum, jobid, (struct printjob *)old_data.dptr,
                        (struct printjob *)new_data.dptr);
@@ -581,7 +581,7 @@ static void print_unix_job(int snum, print_queue_struct *q)
        fstrcpy(pj.user, q->fs_user);
        fstrcpy(pj.queuename, lp_const_servicename(snum));
 
-       pjob_store(snum, jobid, &pj);
+       pjob_store(snum, jobid, &pj, True);
 }
 
 
@@ -868,7 +868,7 @@ static void print_queue_update(int snum)
                pjob->sysjob = queue[i].job;
                pjob->status = queue[i].status;
 
-               pjob_store(snum, jobid, pjob);
+               pjob_store(snum, jobid, pjob, True);
        }
 
        /* now delete any queued entries that don't appear in the
@@ -977,7 +977,7 @@ BOOL print_job_set_name(int snum, uint32 jobid, char *name)
                return False;
 
        fstrcpy(pjob->jobname, name);
-       return pjob_store(snum, jobid, pjob);
+       return pjob_store(snum, jobid, pjob, True);
 }
 
 /****************************************************************************
@@ -1009,7 +1009,7 @@ static BOOL print_job_delete1(int snum, uint32 jobid)
        /* Set the tdb entry to be deleting. */
 
        pjob->status = LPQ_DELETING;
-       pjob_store(snum, jobid, pjob);
+       pjob_store(snum, jobid, pjob, True);
 
        if (pjob->spooled && pjob->sysjob != -1)
                result = (*(current_printif->job_delete))(snum, pjob);
@@ -1172,7 +1172,7 @@ int print_job_write(int snum, uint32 jobid, const char *buf, int size)
        return_code = write(pjob->fd, buf, size);
        if (return_code>0) {
                pjob->size += size;
-               pjob_store(snum, jobid, pjob);
+               pjob_store(snum, jobid, pjob, True);
        }
        return return_code;
 }
@@ -1265,6 +1265,7 @@ int print_queue_length(int snum, print_status_struct *pstatus)
        return len;
 }
 
+#if 0 /* JRATEST */
 /****************************************************************************
  Determine the number of jobs in all queues. This is very expensive. Don't
  call ! JRA.
@@ -1298,6 +1299,7 @@ static int get_total_jobs(void)
        }
        return total_jobs;
 }
+#endif /* JRATEST */
 
 /***************************************************************************
  Start spooling a job - return the jobid.
@@ -1362,6 +1364,7 @@ uint32 print_job_start(struct current_user *user, int snum, char *jobname)
                return (uint32)-1;
        }
 
+#if 0 /* JRATEST */
        /* Insure the maximum print jobs in the system is not violated */
        if (lp_totalprintjobs() && get_total_jobs() > lp_totalprintjobs()) {
                DEBUG(3, ("print_job_start: number of jobs (%d) larger than max printjobs per system (%d).\n",
@@ -1370,6 +1373,7 @@ uint32 print_job_start(struct current_user *user, int snum, char *jobname)
                errno = ENOSPC;
                return (uint32)-1;
        }
+#endif /* JRATEST */
 
        /* create the database entry */
        ZERO_STRUCT(pjob);
@@ -1407,7 +1411,7 @@ uint32 print_job_start(struct current_user *user, int snum, char *jobname)
                if (!print_job_exists(snum, jobid))
                        break;
        }
-       if (jobid == next_jobid || !pjob_store(snum, jobid, &pjob)) {
+       if (jobid == next_jobid || !pjob_store(snum, jobid, &pjob, False)) {
                DEBUG(3, ("print_job_start: either jobid (%d)==next_jobid(%d) or pjob_store failed.\n",
                                jobid, next_jobid ));
                jobid = -1;
@@ -1420,6 +1424,9 @@ uint32 print_job_start(struct current_user *user, int snum, char *jobname)
                goto fail;
        }
 
+       /* We've finished with the INFO/nextjob lock. */
+       tdb_unlock_bystring(pdb->tdb, "INFO/nextjob");
+
        /* we have a job entry - now create the spool file */
        slprintf(pjob.filename, sizeof(pjob.filename)-1, "%s/%s%.8u.XXXXXX", 
                 path, PRINT_SPOOL_PREFIX, (unsigned int)jobid);
@@ -1438,9 +1445,8 @@ to open spool file %s.\n", pjob.filename));
                goto fail;
        }
 
-       pjob_store(snum, jobid, &pjob);
+       pjob_store(snum, jobid, &pjob, False);
 
-       tdb_unlock_bystring(pdb->tdb, "INFO/nextjob");
        release_print_db(pdb);
 
        /*
@@ -1481,7 +1487,7 @@ void print_job_endpage(int snum, uint32 jobid)
                return;
 
        pjob->page_count++;
-       pjob_store(snum, jobid, pjob);
+       pjob_store(snum, jobid, pjob, True);
 }
 
 /****************************************************************************
@@ -1539,7 +1545,7 @@ BOOL print_job_end(int snum, uint32 jobid, BOOL normal_close)
        
        pjob->spooled = True;
        pjob->status = LPQ_QUEUED;
-       pjob_store(snum, jobid, pjob);
+       pjob_store(snum, jobid, pjob, True);
        
        /* make sure the database is up to date */
        if (print_cache_expired(snum))
index 5609c2963d80ce6976f0e378bef9b8cb38f77862..bc897a95cb318d3d324b24471962c43afd97d248 100644 (file)
@@ -28,10 +28,9 @@ 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;
 }
@@ -45,7 +44,8 @@ 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));
 
@@ -111,16 +111,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;
 
@@ -176,6 +176,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);
index 010f0e47d3173de3347e03c520f522b5bed41d82..263626dcc1622f169d27ce77f2602d95d31773d8 100644 (file)
@@ -113,7 +113,7 @@ int reply_special(char *inbuf,char *outbuf)
                reload_services(True);
                reopen_logs();
 
-               claim_connection(NULL,"",MAXSTATUS,True);
+               claim_connection(NULL,"",0,True,FLAG_MSG_GENERAL|FLAG_MSG_SMBD|FLAG_MSG_PRINTING);
 
                already_got_session = True;
                break;
index c748a87da296c80b752be5abb2eaa33b0b23ab12..8082c22cff8e765dd81ce3878b789436350e7a4a 100644 (file)
@@ -858,7 +858,7 @@ static void usage(char *pname)
        register_dmalloc_msgs();
 
        /* Setup the main smbd so that we can get messages. */
-       claim_connection(NULL,"",0,True);
+       claim_connection(NULL,"",0,True,FLAG_MSG_GENERAL|FLAG_MSG_SMBD);
 
        /* 
           DO NOT ENABLE THIS TILL YOU COPE WITH KILLING THESE TASKS AND INETD
index d475451e6bedbdfd6faf4615840e27f2d72dbc02..a8a590da804404f597d65b5eefd042b6d35b8e1e 100644 (file)
@@ -578,7 +578,7 @@ static connection_struct *make_connection_snum(int snum, user_struct *vuser,
        if (!claim_connection(conn,
                              lp_servicename(SNUM(conn)),
                              lp_max_connections(SNUM(conn)),
-                             False)) {
+                             False,0)) {
                DEBUG(1,("too many connections - rejected\n"));
                conn_free(conn);
                *status = NT_STATUS_INSUFFICIENT_RESOURCES;