mirror of
https://github.com/samba-team/samba.git
synced 2025-12-20 16:23:51 +03:00
Add bcast_msg_flags to connection struct. Allows sender to filter when
sending broadcast messages. Also initial cut-down of printing notify messages (not yet finished). Jeremy.
This commit is contained in:
@@ -67,10 +67,6 @@
|
||||
#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 */
|
||||
|
||||
@@ -59,4 +59,12 @@
|
||||
#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
|
||||
|
||||
@@ -718,6 +718,7 @@ struct connections_data {
|
||||
char addr[24];
|
||||
char machine[FSTRING_LEN];
|
||||
time_t start;
|
||||
uint32 bcast_msg_flags;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -382,6 +382,7 @@ void message_deregister(int msg_type)
|
||||
|
||||
struct msg_all {
|
||||
int msg_type;
|
||||
uint32 msg_flag;
|
||||
const void *buf;
|
||||
size_t len;
|
||||
BOOL duplicates;
|
||||
@@ -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;
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user