2010-05-27 09:18:58 +04:00
/*
Unix SMB / CIFS implementation .
Main SMB server routines
Copyright ( C ) Andrew Tridgell 1992 - 1998
Copyright ( C ) Martin Pool 2002
Copyright ( C ) Jelmer Vernooij 2002 - 2003
Copyright ( C ) Volker Lendecke 1993 - 2007
Copyright ( C ) Jeremy Allison 1993 - 2007
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation ; either version 3 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
# include "includes.h"
2011-03-22 18:57:01 +03:00
# include "smbd/smbd.h"
2010-05-27 09:18:58 +04:00
# include "smbd/globals.h"
2010-07-31 02:47:20 +04:00
# include "nt_printing.h"
2010-12-19 21:52:08 +03:00
# include "printing/pcap.h"
2011-02-22 21:24:31 +03:00
# include "printing/load.h"
2011-03-24 15:46:20 +03:00
# include "auth.h"
2011-03-24 17:31:06 +03:00
# include "messages.h"
2011-06-29 09:33:54 +04:00
# include "lib/param/loadparm.h"
2010-05-27 09:18:58 +04:00
/****************************************************************************
2010-12-19 21:52:08 +03:00
purge stale printers and reload from pre - populated pcap cache
2010-05-27 09:18:58 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2010-12-19 21:52:08 +03:00
void reload_printers ( struct tevent_context * ev ,
struct messaging_context * msg_ctx )
2010-05-27 09:18:58 +04:00
{
2011-07-18 07:06:47 +04:00
struct auth_session_info * session_info = NULL ;
2010-04-27 01:34:24 +04:00
struct spoolss_PrinterInfo2 * pinfo2 = NULL ;
2010-05-27 09:18:58 +04:00
int snum ;
int n_services = lp_numservices ( ) ;
int pnum = lp_servicenumber ( PRINTERS_NAME ) ;
const char * pname ;
2010-04-27 01:34:24 +04:00
NTSTATUS status ;
bool skip = false ;
2010-05-27 09:18:58 +04:00
2010-12-19 21:52:08 +03:00
SMB_ASSERT ( pcap_cache_loaded ( ) ) ;
DEBUG ( 10 , ( " reloading printer services from pcap cache \n " ) ) ;
2010-05-27 09:18:58 +04:00
2011-02-21 12:25:52 +03:00
status = make_session_info_system ( talloc_tos ( ) , & session_info ) ;
2010-04-27 01:34:24 +04:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2010-08-10 15:45:55 +04:00
DEBUG ( 3 , ( " reload_printers: "
2011-02-21 12:25:52 +03:00
" Could not create system session_info \n " ) ) ;
2010-04-27 01:34:24 +04:00
/* can't remove stale printers before we
* are fully initilized */
skip = true ;
}
2010-05-27 09:18:58 +04:00
/* remove stale printers */
2010-04-27 01:34:24 +04:00
for ( snum = 0 ; skip = = false & & snum < n_services ; snum + + ) {
2010-05-27 09:18:58 +04:00
/* avoid removing PRINTERS_NAME or non-autoloaded printers */
if ( snum = = pnum | | ! ( lp_snum_ok ( snum ) & & lp_print_ok ( snum ) & &
lp_autoloaded ( snum ) ) )
continue ;
pname = lp_printername ( snum ) ;
if ( ! pcap_printername_ok ( pname ) ) {
DEBUG ( 3 , ( " removing stale printer %s \n " , pname ) ) ;
2011-02-21 12:25:52 +03:00
if ( is_printer_published ( session_info , session_info ,
2010-08-08 17:02:29 +04:00
msg_ctx ,
2010-04-27 01:34:24 +04:00
NULL , lp_servicename ( snum ) ,
NULL , & pinfo2 ) ) {
2011-02-21 12:25:52 +03:00
nt_printer_publish ( session_info ,
session_info ,
2010-08-08 17:02:29 +04:00
msg_ctx ,
2010-08-08 16:35:50 +04:00
pinfo2 ,
2010-04-27 01:34:24 +04:00
DSPRINT_UNPUBLISH ) ;
TALLOC_FREE ( pinfo2 ) ;
}
2011-02-21 12:25:52 +03:00
nt_printer_remove ( session_info , session_info , msg_ctx ,
2010-08-08 17:02:29 +04:00
pname ) ;
2010-05-27 09:18:58 +04:00
lp_killservice ( snum ) ;
}
}
2010-12-19 21:52:08 +03:00
load_printers ( ev , msg_ctx ) ;
2010-04-27 01:34:24 +04:00
2011-02-21 12:25:52 +03:00
TALLOC_FREE ( session_info ) ;
2010-05-27 09:18:58 +04:00
}
/****************************************************************************
Reload the services file .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2010-08-15 18:13:00 +04:00
bool reload_services ( struct messaging_context * msg_ctx , int smb_sock ,
bool test )
2010-05-27 09:18:58 +04:00
{
bool ret ;
if ( lp_loaded ( ) ) {
char * fname = lp_configfile ( ) ;
if ( file_exist ( fname ) & &
! strcsequal ( fname , get_dyn_CONFIGFILE ( ) ) ) {
set_dyn_CONFIGFILE ( fname ) ;
test = False ;
}
}
reopen_logs ( ) ;
if ( test & & ! lp_file_list_changed ( ) )
return ( True ) ;
2011-05-25 07:00:22 +04:00
if ( msg_ctx ) {
lp_killunused ( msg_ctx_to_sconn ( msg_ctx ) , conn_snum_used ) ;
} else {
lp_killunused ( NULL , NULL ) ;
}
2010-05-27 09:18:58 +04:00
ret = lp_load ( get_dyn_CONFIGFILE ( ) , False , False , True , True ) ;
/* perhaps the config filename is now set */
if ( ! test )
2010-08-15 18:13:00 +04:00
reload_services ( msg_ctx , smb_sock , True ) ;
2010-05-27 09:18:58 +04:00
reopen_logs ( ) ;
load_interfaces ( ) ;
2010-08-15 18:13:00 +04:00
if ( smb_sock ! = - 1 ) {
set_socket_options ( smb_sock , " SO_KEEPALIVE " ) ;
set_socket_options ( smb_sock , lp_socket_options ( ) ) ;
2010-05-27 09:18:58 +04:00
}
mangle_reset_cache ( ) ;
reset_stat_cache ( ) ;
/* this forces service parameters to be flushed */
set_current_service ( NULL , 0 , True ) ;
return ( ret ) ;
}