summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
Diffstat (limited to 'source3')
-rw-r--r--source3/param/loadparm.c4
-rw-r--r--source3/smbd/process.c28
-rw-r--r--source3/smbd/service.c24
3 files changed, 55 insertions, 1 deletions
diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c
index b5bd14cdde..6376e4aa91 100644
--- a/source3/param/loadparm.c
+++ b/source3/param/loadparm.c
@@ -249,6 +249,7 @@ typedef struct
BOOL bNullPasswords;
BOOL bObeyPamRestrictions;
BOOL bLoadPrinters;
+ int PrintcapCacheTime;
BOOL bLargeReadwrite;
BOOL bReadRaw;
BOOL bWriteRaw;
@@ -945,6 +946,7 @@ static struct parm_struct parm_table[] = {
{"max reported print jobs", P_INTEGER, P_LOCAL, &sDefault.iMaxReportedPrintJobs, NULL, NULL, FLAG_ADVANCED | FLAG_PRINT},
{"max print jobs", P_INTEGER, P_LOCAL, &sDefault.iMaxPrintJobs, NULL, NULL, FLAG_ADVANCED | FLAG_PRINT},
{"load printers", P_BOOL, P_GLOBAL, &Globals.bLoadPrinters, NULL, NULL, FLAG_ADVANCED | FLAG_PRINT},
+ {"printcap cache time", P_INTEGER, P_GLOBAL, &Globals.PrintcapCacheTime, NULL, NULL, FLAG_ADVANCED | FLAG_PRINT},
{"printcap name", P_STRING, P_GLOBAL, &Globals.szPrintcapname, NULL, NULL, FLAG_ADVANCED | FLAG_PRINT},
{"printcap", P_STRING, P_GLOBAL, &Globals.szPrintcapname, NULL, NULL, FLAG_HIDE},
{"printable", P_BOOL, P_LOCAL, &sDefault.bPrint_ok, NULL, NULL, FLAG_ADVANCED | FLAG_PRINT},
@@ -1362,6 +1364,7 @@ static void init_globals(void)
Globals.AlgorithmicRidBase = BASE_RID;
Globals.bLoadPrinters = True;
+ Globals.PrintcapCacheTime = 0;
/* Was 65535 (0xFFFF). 0x4101 matches W2K and causes major speed improvements... */
/* Discovered by 2 days of pain by Don McCall @ HP :-). */
Globals.max_xmit = 0x4104;
@@ -1614,6 +1617,7 @@ FN_GLOBAL_STRING(lp_configfile, &Globals.szConfigFile)
FN_GLOBAL_STRING(lp_smb_passwd_file, &Globals.szSMBPasswdFile)
FN_GLOBAL_STRING(lp_private_dir, &Globals.szPrivateDir)
FN_GLOBAL_STRING(lp_serverstring, &Globals.szServerString)
+FN_GLOBAL_INTEGER(lp_printcap_cache_time, &Globals.PrintcapCacheTime)
FN_GLOBAL_STRING(lp_printcapname, &Globals.szPrintcapname)
FN_GLOBAL_STRING(lp_enumports_cmd, &Globals.szEnumPortsCommand)
FN_GLOBAL_STRING(lp_addprinter_cmd, &Globals.szAddPrinterCommand)
diff --git a/source3/smbd/process.c b/source3/smbd/process.c
index d0dfc6dd7d..283b791afd 100644
--- a/source3/smbd/process.c
+++ b/source3/smbd/process.c
@@ -1078,15 +1078,41 @@ static int setup_select_timeout(void)
void check_reload(int t)
{
static time_t last_smb_conf_reload_time = 0;
+ static time_t last_load_printers_reload_time = 0;
+ time_t printcap_cache_time = (time_t)lp_printcap_cache_time();
- if(last_smb_conf_reload_time == 0)
+ if(last_smb_conf_reload_time == 0) {
last_smb_conf_reload_time = t;
+ /* Our printing subsystem might not be ready at smbd start up.
+ Then no printer is available till the first printers check
+ is performed. A lower initial interval circumvents this. */
+ if ( printcap_cache_time > 60 )
+ last_load_printers_reload_time = t - printcap_cache_time + 60;
+ else
+ last_load_printers_reload_time = t;
+ }
if (reload_after_sighup || (t >= last_smb_conf_reload_time+SMBD_RELOAD_CHECK)) {
reload_services(True);
reload_after_sighup = False;
last_smb_conf_reload_time = t;
}
+
+ /* 'printcap cache time = 0' disable the feature */
+
+ if ( printcap_cache_time != 0 )
+ {
+ /* see if it's time to reload or if the clock has been set back */
+
+ if ( (t >= last_load_printers_reload_time+printcap_cache_time)
+ || (t-last_load_printers_reload_time < 0) )
+ {
+ DEBUG( 3,( "Printcap cache time expired.\n"));
+ remove_stale_printers();
+ load_printers();
+ last_load_printers_reload_time = t;
+ }
+ }
}
/****************************************************************************
diff --git a/source3/smbd/service.c b/source3/smbd/service.c
index 04cade9577..c74537c299 100644
--- a/source3/smbd/service.c
+++ b/source3/smbd/service.c
@@ -826,3 +826,27 @@ void close_cnum(connection_struct *conn, uint16 vuid)
conn_free(conn);
}
+
+/****************************************************************************
+ Remove stale printers
+****************************************************************************/
+
+void remove_stale_printers( void )
+{
+ int snum, iNumServices, printersServiceNum;
+ const char *pname;
+
+ iNumServices = lp_numservices();
+ printersServiceNum = lp_servicenumber( PRINTERS_NAME);
+ for( snum = 0; snum < iNumServices; snum++) {
+ /* Never remove PRINTERS_NAME */
+ if ( snum == printersServiceNum)
+ continue;
+ pname = lp_printername( snum);
+ /* Is snum a print service and still in the printing subsystem? */
+ if ( lp_print_ok( snum) && !pcap_printername_ok( pname, NULL)) {
+ DEBUG( 3, ( "Removing printer: %s\n", pname));
+ lp_killservice( snum);
+ }
+ }
+}