--- samba-3.0.3/docs/manpages/smb.conf.5 +++ samba-3.0.3/docs/manpages/smb.conf.5 2004-05-05 11:27:01 @@ -3003,6 +3003,15 @@ Default: \fB\fIprintable\fR = no \fR .TP +printcap cache time (G) +Specifies the number of seconds it takes before the printing subsystem is again asked for the known printers. + +Set it to zero to disable any printer rescan after the initial smbd startup. + +Default: \fB\fIprintcap cache time = 750 \fR +Example: \fB\fIprintcap cache time = 0 \fR + +.TP printcap This parameter is a synonym for printcap name\&. --- samba-3.0.3/source/param/loadparm.c +++ samba-3.0.3/source/param/loadparm.c 2004-05-07 16:49:59 @@ -249,6 +249,7 @@ BOOL bNullPasswords; BOOL bObeyPamRestrictions; BOOL bLoadPrinters; + int PrintcapCacheTime; BOOL bLargeReadwrite; BOOL bReadRaw; BOOL bWriteRaw; @@ -947,6 +948,7 @@ {"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}, @@ -1365,6 +1367,7 @@ Globals.AlgorithmicRidBase = BASE_RID; Globals.bLoadPrinters = True; + Globals.PrintcapCacheTime = 750; /* 12.5 minutes */ /* 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; @@ -1616,6 +1619,7 @@ 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) --- samba-3.0.3/source/smbd/process.c +++ samba-3.0.3/source/smbd/process.c 2004-05-08 16:31:30 @@ -1077,15 +1077,32 @@ 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 = 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; } + + if ( printcap_cache_time != 0 && t >= last_load_printers_reload_time+printcap_cache_time) { + DEBUG( 3,( "Printcap cache time expired.\n")); + remove_stale_printers(); + load_printers(); + last_load_printers_reload_time = t; + } } /**************************************************************************** --- samba-3.0.3/source/smbd/service.c +++ samba-3.0.3/source/smbd/service.c 2004-05-07 18:56:01 @@ -832,3 +832,27 @@ conn_free(conn); } + +/**************************************************************************** + Remove stale printers +****************************************************************************/ + +void remove_stale_printers() +{ + 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); + } + } +}