diff options
Diffstat (limited to 'source3')
-rw-r--r-- | source3/libads/ldap_printer.c | 2 | ||||
-rw-r--r-- | source3/printing/nt_printing.c | 281 | ||||
-rw-r--r-- | source3/printing/printing.c | 4 | ||||
-rw-r--r-- | source3/rpc_server/srv_spoolss_nt.c | 24 |
4 files changed, 182 insertions, 129 deletions
diff --git a/source3/libads/ldap_printer.c b/source3/libads/ldap_printer.c index 1448074ea0..d8e4cefcfa 100644 --- a/source3/libads/ldap_printer.c +++ b/source3/libads/ldap_printer.c @@ -36,7 +36,7 @@ ADS_STATUS ads_find_printer_on_server(ADS_STRUCT *ads, void **res, status = ads_find_machine_acct(ads, res, servername); if (!ADS_ERR_OK(status)) { - DEBUG(1, ("ads_add_printer: cannot find host %s in ads\n", + DEBUG(1, ("ads_find_printer_on_server: cannot find host %s in ads\n", servername)); return status; } diff --git a/source3/printing/nt_printing.c b/source3/printing/nt_printing.c index c3551c9d90..f047daabee 100644 --- a/source3/printing/nt_printing.c +++ b/source3/printing/nt_printing.c @@ -289,6 +289,7 @@ BOOL nt_printing_init(void) { static pid_t local_pid; const char *vstring = "INFO/version"; + WERROR win_rc; if (tdb_drivers && tdb_printers && tdb_forms && local_pid == sys_getpid()) return True; @@ -377,6 +378,10 @@ BOOL nt_printing_init(void) msgs. This is done in claim_connection() */ + win_rc = check_published_printers(); + if (!W_ERROR_IS_OK(win_rc)) + DEBUG(3, ("error checking published printers: %s\n", W_ERROR_V(win_rc))); + return True; } @@ -2631,56 +2636,20 @@ static void store_printer_guid(NT_PRINTER_INFO_LEVEL_2 *info2, (char *) &guid, sizeof(struct uuid)); } -static WERROR publish_it(NT_PRINTER_INFO_LEVEL *printer) +static WERROR nt_printer_publish_ads(ADS_STRUCT *ads, + NT_PRINTER_INFO_LEVEL *printer) { ADS_STATUS ads_rc; - TALLOC_CTX *ctx = talloc_init("publish_it"); - ADS_MODLIST mods = ads_init_mods(ctx); + void *res; char *prt_dn = NULL, *srv_dn, *srv_cn_0; char *srv_dn_utf8, **srv_cn_utf8; - void *res = NULL; - ADS_STRUCT *ads; + TALLOC_CTX *ctx; + ADS_MODLIST mods; const char *attrs[] = {"objectGUID", NULL}; struct uuid guid; WERROR win_rc = WERR_OK; - ZERO_STRUCT(guid); - /* set the DsSpooler info and attributes */ - if (!(map_nt_printer_info2_to_dsspooler(printer->info_2))) - return WERR_NOMEM; - printer->info_2->attributes |= PRINTER_ATTRIBUTE_PUBLISHED; - win_rc = mod_a_printer(*printer, 2); - if (!W_ERROR_IS_OK(win_rc)) { - DEBUG(3, ("err %d saving data\n", - W_ERROR_V(win_rc))); - return win_rc; - } - - /* Build the ads mods */ - get_local_printer_publishing_data(ctx, &mods, - &printer->info_2->data); - ads_mod_str(ctx, &mods, SPOOL_REG_PRINTERNAME, - printer->info_2->sharename); - - /* initial ads structure */ - - ads = ads_init(NULL, NULL, NULL); - if (!ads) { - DEBUG(3, ("ads_init() failed\n")); - return WERR_SERVER_UNAVAILABLE; - } - setenv(KRB5_ENV_CCNAME, "MEMORY:prtpub_cache", 1); - SAFE_FREE(ads->auth.password); - ads->auth.password = secrets_fetch_machine_password(lp_workgroup(), - NULL, NULL); - - /* ads_connect() will find the DC for us */ - ads_rc = ads_connect(ads); - if (!ADS_ERR_OK(ads_rc)) { - DEBUG(3, ("ads_connect failed: %s\n", ads_errstr(ads_rc))); - ads_destroy(&ads); - return WERR_ACCESS_DENIED; - } + DEBUG(5, ("publishing printer %s\n", printer->info_2->printername)); /* figure out where to publish */ ads_find_machine_acct(ads, &res, global_myname()); @@ -2724,70 +2693,55 @@ static WERROR publish_it(NT_PRINTER_INFO_LEVEL *printer) SAFE_FREE(srv_dn); SAFE_FREE(srv_cn_0); + /* build the ads mods */ + ctx = talloc_init("nt_printer_publish_ads"); + mods = ads_init_mods(ctx); + + get_local_printer_publishing_data(ctx, &mods, + &printer->info_2->data); + ads_mod_str(ctx, &mods, SPOOL_REG_PRINTERNAME, + printer->info_2->sharename); + /* publish it */ ads_rc = ads_add_printer_entry(ads, prt_dn, ctx, &mods); if (LDAP_ALREADY_EXISTS == ads_rc.err.rc) - ads_rc = ads_mod_printer_entry(ads, prt_dn, ctx,&mods); + ads_rc = ads_mod_printer_entry(ads, prt_dn, ctx, &mods); + talloc_destroy(ctx); + /* retreive the guid and store it locally */ if (ADS_ERR_OK(ads_search_dn(ads, &res, prt_dn, attrs))) { + ZERO_STRUCT(guid); ads_pull_guid(ads, res, &guid); ads_msgfree(ads, res); store_printer_guid(printer->info_2, guid); - win_rc = mod_a_printer(*printer, 2); + win_rc = mod_a_printer(printer, 2); } SAFE_FREE(prt_dn); - ads_destroy(&ads); - - return WERR_OK; + return win_rc; } -WERROR unpublish_it(NT_PRINTER_INFO_LEVEL *printer) +static WERROR nt_printer_unpublish_ads(ADS_STRUCT *ads, + NT_PRINTER_INFO_LEVEL *printer) { ADS_STATUS ads_rc; - ADS_STRUCT *ads; void *res; char *prt_dn = NULL; - WERROR win_rc; - printer->info_2->attributes ^= PRINTER_ATTRIBUTE_PUBLISHED; - win_rc = mod_a_printer(*printer, 2); - if (!W_ERROR_IS_OK(win_rc)) { - DEBUG(3, ("err %d saving data\n", - W_ERROR_V(win_rc))); - return win_rc; - } - - ads = ads_init(NULL, NULL, NULL); - if (!ads) { - DEBUG(3, ("ads_init() failed\n")); - return WERR_SERVER_UNAVAILABLE; - } - setenv(KRB5_ENV_CCNAME, "MEMORY:prtpub_cache", 1); - SAFE_FREE(ads->auth.password); - ads->auth.password = secrets_fetch_machine_password(lp_workgroup(), - NULL, NULL); + DEBUG(5, ("unpublishing printer %s\n", printer->info_2->printername)); - /* ads_connect() will find the DC for us */ - ads_rc = ads_connect(ads); - if (!ADS_ERR_OK(ads_rc)) { - DEBUG(3, ("ads_connect failed: %s\n", ads_errstr(ads_rc))); - ads_destroy(&ads); - return WERR_ACCESS_DENIED; - } - /* remove the printer from the directory */ ads_rc = ads_find_printer_on_server(ads, &res, printer->info_2->sharename, global_myname()); + if (ADS_ERR_OK(ads_rc) && ads_count_replies(ads, res)) { prt_dn = ads_get_dn(ads, res); - ads_msgfree(ads, res); ads_rc = ads_del_dn(ads, prt_dn); ads_memfree(ads, prt_dn); } - ads_destroy(&ads); + ads_msgfree(ads, res); return WERR_OK; } @@ -2800,30 +2754,134 @@ WERROR unpublish_it(NT_PRINTER_INFO_LEVEL *printer) WERROR nt_printer_publish(Printer_entry *print_hnd, int snum, int action) { + ADS_STATUS ads_rc; + ADS_STRUCT *ads = NULL; NT_PRINTER_INFO_LEVEL *printer = NULL; WERROR win_rc; win_rc = get_a_printer(print_hnd, &printer, 2, lp_servicename(snum)); if (!W_ERROR_IS_OK(win_rc)) - return win_rc; + goto done; - switch(action) { + switch (action) { case SPOOL_DS_PUBLISH: case SPOOL_DS_UPDATE: - win_rc = publish_it(printer); + /* set the DsSpooler info and attributes */ + if (!(map_nt_printer_info2_to_dsspooler(printer->info_2))) { + win_rc = WERR_NOMEM; + goto done; + } + + printer->info_2->attributes |= PRINTER_ATTRIBUTE_PUBLISHED; break; case SPOOL_DS_UNPUBLISH: - win_rc = unpublish_it(printer); + printer->info_2->attributes ^= PRINTER_ATTRIBUTE_PUBLISHED; break; default: win_rc = WERR_NOT_SUPPORTED; + goto done; + } + + win_rc = mod_a_printer(printer, 2); + if (!W_ERROR_IS_OK(win_rc)) { + DEBUG(3, ("err %d saving data\n", W_ERROR_V(win_rc))); + goto done; } - + ads = ads_init(NULL, NULL, NULL); + if (!ads) { + DEBUG(3, ("ads_init() failed\n")); + win_rc = WERR_SERVER_UNAVAILABLE; + goto done; + } + setenv(KRB5_ENV_CCNAME, "MEMORY:prtpub_cache", 1); + SAFE_FREE(ads->auth.password); + ads->auth.password = secrets_fetch_machine_password(lp_workgroup(), + NULL, NULL); + + /* ads_connect() will find the DC for us */ + ads_rc = ads_connect(ads); + if (!ADS_ERR_OK(ads_rc)) { + DEBUG(3, ("ads_connect failed: %s\n", ads_errstr(ads_rc))); + win_rc = WERR_ACCESS_DENIED; + goto done; + } + + switch (action) { + case SPOOL_DS_PUBLISH: + case SPOOL_DS_UPDATE: + win_rc = nt_printer_publish_ads(ads, printer); + break; + case SPOOL_DS_UNPUBLISH: + win_rc = nt_printer_unpublish_ads(ads, printer); + break; + } + +done: free_a_printer(&printer, 2); + ads_destroy(&ads); return win_rc; } +WERROR check_published_printers(void) +{ + ADS_STATUS ads_rc; + ADS_STRUCT *ads = NULL; + void *res = NULL; + int snum; + int n_services = lp_numservices(); + NT_PRINTER_INFO_LEVEL *printer = NULL; + WERROR win_rc; + + ads = ads_init(NULL, NULL, NULL); + if (!ads) { + DEBUG(3, ("ads_init() failed\n")); + return WERR_SERVER_UNAVAILABLE; + } + setenv(KRB5_ENV_CCNAME, "MEMORY:prtpub_cache", 1); + SAFE_FREE(ads->auth.password); + ads->auth.password = secrets_fetch_machine_password(lp_workgroup(), + NULL, NULL); + + /* ads_connect() will find the DC for us */ + ads_rc = ads_connect(ads); + if (!ADS_ERR_OK(ads_rc)) { + DEBUG(3, ("ads_connect failed: %s\n", ads_errstr(ads_rc))); + ads_destroy(&ads); + return WERR_ACCESS_DENIED; + } + + for (snum = 0; snum < n_services; snum++) { + if (!(lp_snum_ok(snum) && lp_print_ok(snum))) + continue; + + if (!W_ERROR_IS_OK(get_a_printer(NULL, &printer, 2, + lp_servicename(snum))) || + !(printer->info_2->attributes & PRINTER_ATTRIBUTE_PUBLISHED)) + goto next; + + DEBUG(5, ("checking directory for printer %s\n", printer->info_2->printername)); + ads_rc = ads_find_printer_on_server(ads, &res, + printer->info_2->sharename, global_myname()); + if (ADS_ERR_OK(ads_rc) && ads_count_replies(ads, res)) { + DEBUG(5, ("printer %s is in directory\n", printer->info_2->printername)); + goto next; + } + + win_rc = nt_printer_publish_ads(ads, printer); + if (!W_ERROR_IS_OK(win_rc)) + DEBUG(3, ("error publishing %s: %s\n", printer->info_2->sharename, W_ERROR_V(win_rc))); + + next: + free_a_printer(&printer, 2); + ads_msgfree(ads, res); + res = NULL; + } + + ads_destroy(&ads); + return WERR_OK; +} + BOOL is_printer_published(Printer_entry *print_hnd, int snum, struct uuid *guid) { @@ -2833,43 +2891,42 @@ BOOL is_printer_published(Printer_entry *print_hnd, int snum, WERROR win_rc; int i; - win_rc = get_a_printer(print_hnd, &printer, 2, lp_servicename(snum)); - if (!W_ERROR_IS_OK(win_rc)) - return False; - - if (!(printer->info_2->attributes & PRINTER_ATTRIBUTE_PUBLISHED)) - return False; - - if ((i = lookup_printerkey(&printer->info_2->data, - SPOOL_DSSPOOLER_KEY)) < 0) - return False; - - if (!(ctr = &printer->info_2->data.keys[i].values)) { - return False; - } - if (!(guid_val = regval_ctr_getvalue(ctr, "objectGUID"))) { + if (!W_ERROR_IS_OK(win_rc) || + !(printer->info_2->attributes & PRINTER_ATTRIBUTE_PUBLISHED) || + ((i = lookup_printerkey(&printer->info_2->data, + SPOOL_DSSPOOLER_KEY)) < 0) || + !(ctr = &printer->info_2->data.keys[i].values) || + !(guid_val = regval_ctr_getvalue(ctr, "objectGUID"))) { + free_a_printer(&printer, 2); return False; } if (regval_size(guid_val) == sizeof(struct uuid)) memcpy(guid, regval_data_p(guid_val), sizeof(struct uuid)); + free_a_printer(&printer, 2); return True; } - #else WERROR nt_printer_publish(Printer_entry *print_hnd, int snum, int action) { return WERR_OK; } + +WERROR check_published_printers(void) +{ + return WERR_OK; +} + BOOL is_printer_published(Printer_entry *print_hnd, int snum, struct uuid *guid) { return False; } -#endif +#endif /* HAVE_ADS */ + /**************************************************************************** ***************************************************************************/ @@ -3391,7 +3448,7 @@ static WERROR get_a_printer_2(NT_PRINTER_INFO_LEVEL_2 **info_ptr, const char *sh /**************************************************************************** Debugging function, dump at level 6 the struct in the logs. ****************************************************************************/ -static uint32 dump_a_printer(NT_PRINTER_INFO_LEVEL printer, uint32 level) +static uint32 dump_a_printer(NT_PRINTER_INFO_LEVEL *printer, uint32 level) { uint32 result; NT_PRINTER_INFO_LEVEL_2 *info2; @@ -3401,11 +3458,11 @@ static uint32 dump_a_printer(NT_PRINTER_INFO_LEVEL printer, uint32 level) switch (level) { case 2: { - if (printer.info_2 == NULL) + if (printer->info_2 == NULL) result=5; else { - info2=printer.info_2; + info2=printer->info_2; DEBUGADD(106,("attributes:[%d]\n", info2->attributes)); DEBUGADD(106,("priority:[%d]\n", info2->priority)); @@ -3501,7 +3558,7 @@ static BOOL send_printer_mod_msg( char* printername ) Modify a printer. This is called from SETPRINTERDATA/DELETEPRINTERDATA. ****************************************************************************/ -WERROR mod_a_printer(NT_PRINTER_INFO_LEVEL printer, uint32 level) +WERROR mod_a_printer(NT_PRINTER_INFO_LEVEL *printer, uint32 level) { WERROR result; @@ -3513,8 +3570,8 @@ WERROR mod_a_printer(NT_PRINTER_INFO_LEVEL printer, uint32 level) * get_a_printer() */ - invalidate_printer_hnd_cache( printer.info_2->sharename ); - send_printer_mod_msg( printer.info_2->sharename ); + invalidate_printer_hnd_cache( printer->info_2->sharename ); + send_printer_mod_msg( printer->info_2->sharename ); switch (level) { case 2: @@ -3529,7 +3586,7 @@ WERROR mod_a_printer(NT_PRINTER_INFO_LEVEL printer, uint32 level) of client's spoolss service in order for the client's cache to show updates */ - printer.info_2->changeid = rev_changeid(); + printer->info_2->changeid = rev_changeid(); /* * Because one day someone will ask: @@ -3550,7 +3607,7 @@ WERROR mod_a_printer(NT_PRINTER_INFO_LEVEL printer, uint32 level) * 14/12/01 --jerry */ - result=update_a_printer_2(printer.info_2); + result=update_a_printer_2(printer->info_2); break; } @@ -3758,7 +3815,7 @@ done: Update (i.e. save) the driver init info (DEVMODE and values) for a printer ****************************************************************************/ -uint32 update_driver_init(NT_PRINTER_INFO_LEVEL printer, uint32 level) +static uint32 update_driver_init(NT_PRINTER_INFO_LEVEL *printer, uint32 level) { uint32 result; @@ -3766,7 +3823,7 @@ uint32 update_driver_init(NT_PRINTER_INFO_LEVEL printer, uint32 level) switch (level) { case 2: - result = update_driver_init_2(printer.info_2); + result = update_driver_init_2(printer->info_2); break; default: result = 1; @@ -3871,7 +3928,7 @@ static WERROR save_driver_init_2(NT_PRINTER_INFO_LEVEL *printer, uint8 *data, ui * */ - if ( update_driver_init(*printer, 2) != 0 ) { + if ( update_driver_init(printer, 2) != 0 ) { DEBUG(10,("save_driver_init_2: error updating DEVMODE\n")); status = WERR_NOMEM; goto done; @@ -3882,7 +3939,7 @@ static WERROR save_driver_init_2(NT_PRINTER_INFO_LEVEL *printer, uint8 *data, ui * printer to match it. This allows initialization of the current printer * as well as the driver. */ - status = mod_a_printer(*printer, 2); + status = mod_a_printer(printer, 2); if (!W_ERROR_IS_OK(status)) { DEBUG(10,("save_driver_init_2: error setting DEVMODE on printer [%s]\n", printer->info_2->printername)); @@ -4058,7 +4115,7 @@ WERROR get_a_printer( Printer_entry *print_hnd, NT_PRINTER_INFO_LEVEL **pp_print /* we have a new printer now. Save it with this handle */ if ( W_ERROR_IS_OK(result) ) { - dump_a_printer(*printer, level); + dump_a_printer(printer, level); /* save a copy in cache */ if ( print_hnd && (print_hnd->printer_type==PRINTER_HANDLE_IS_PRINTER)) { diff --git a/source3/printing/printing.c b/source3/printing/printing.c index d9bc13d03a..60adcc4d7f 100644 --- a/source3/printing/printing.c +++ b/source3/printing/printing.c @@ -1184,10 +1184,6 @@ void start_background_queue(void) exit(1); } - if (!print_backend_init()) { - exit(1); - } - message_register(MSG_PRINTER_UPDATE, print_queue_receive); DEBUG(5,("start_background_queue: background LPQ thread waiting for messages\n")); diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index d50237905a..e7b1fdb1d0 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -1292,7 +1292,7 @@ void do_drv_upgrade_printer(int msg_type, pid_t src, void *buf, size_t len) /* all we care about currently is the change_id */ - result = mod_a_printer(*printer, 2); + result = mod_a_printer(printer, 2); if (!W_ERROR_IS_OK(result)) { DEBUG(3,("do_drv_upgrade_printer: mod_a_printer() failed with status [%s]\n", dos_errstr(result))); @@ -1396,7 +1396,7 @@ void reset_all_printerdata(int msg_type, pid_t src, void *buf, size_t len) printer->info_2->printername, printer->info_2->drivername)); } - result = mod_a_printer( *printer, 2 ); + result = mod_a_printer( printer, 2 ); if ( !W_ERROR_IS_OK(result) ) { DEBUG(3,("reset_all_printerdata: mod_a_printer() failed! (%s)\n", get_dos_error_msg(result))); @@ -6191,7 +6191,7 @@ static WERROR update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level, REG_SZ, (uint8*)buffer.buffer, buffer.uni_str_len*2 ); /* Update printer info */ - result = mod_a_printer(*printer, 2); + result = mod_a_printer(printer, 2); done: free_a_printer(&printer, 2); @@ -7433,7 +7433,7 @@ static WERROR spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_ } /* write the ASCII on disk */ - err = mod_a_printer(*printer, 2); + err = mod_a_printer(printer, 2); if (!W_ERROR_IS_OK(err)) { free_a_printer(&printer,2); return err; @@ -7971,7 +7971,7 @@ WERROR _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP status = set_printer_dataex( printer, SPOOL_PRINTERDATA_KEY, valuename, type, data, real_len ); if ( W_ERROR_IS_OK(status) ) - status = mod_a_printer(*printer, 2); + status = mod_a_printer(printer, 2); } done: @@ -8049,7 +8049,7 @@ WERROR _spoolss_deleteprinterdata(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATA *q_ status = delete_printer_dataex( printer, SPOOL_PRINTERDATA_KEY, valuename ); if ( W_ERROR_IS_OK(status) ) - mod_a_printer( *printer, 2 ); + mod_a_printer( printer, 2 ); free_a_printer(&printer, 2); @@ -8119,7 +8119,7 @@ WERROR _spoolss_addform( pipes_struct *p, SPOOL_Q_ADDFORM *q_u, SPOOL_R_ADDFORM */ if ( Printer->printer_type == PRINTER_HANDLE_IS_PRINTER ) - status = mod_a_printer(*printer, 2); + status = mod_a_printer(printer, 2); done: if ( printer ) @@ -8186,7 +8186,7 @@ WERROR _spoolss_deleteform( pipes_struct *p, SPOOL_Q_DELETEFORM *q_u, SPOOL_R_DE */ if ( Printer->printer_type == PRINTER_HANDLE_IS_PRINTER ) - status = mod_a_printer(*printer, 2); + status = mod_a_printer(printer, 2); done: if ( printer ) @@ -8252,7 +8252,7 @@ WERROR _spoolss_setform(pipes_struct *p, SPOOL_Q_SETFORM *q_u, SPOOL_R_SETFORM * */ if ( Printer->printer_type == PRINTER_HANDLE_IS_PRINTER ) - status = mod_a_printer(*printer, 2); + status = mod_a_printer(printer, 2); done: @@ -8864,7 +8864,7 @@ WERROR _spoolss_setprinterdataex(pipes_struct *p, SPOOL_Q_SETPRINTERDATAEX *q_u, REG_SZ, (void*)oid_string, strlen(oid_string)+1 ); } - status = mod_a_printer(*printer, 2); + status = mod_a_printer(printer, 2); } free_a_printer(&printer, 2); @@ -8914,7 +8914,7 @@ WERROR _spoolss_deleteprinterdataex(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATAEX status = delete_printer_dataex( printer, keyname, valuename ); if ( W_ERROR_IS_OK(status) ) - mod_a_printer( *printer, 2 ); + mod_a_printer( printer, 2 ); free_a_printer(&printer, 2); @@ -9037,7 +9037,7 @@ WERROR _spoolss_deleteprinterkey(pipes_struct *p, SPOOL_Q_DELETEPRINTERKEY *q_u, status = delete_all_printer_data( printer->info_2, key ); if ( W_ERROR_IS_OK(status) ) - status = mod_a_printer(*printer, 2); + status = mod_a_printer(printer, 2); free_a_printer( &printer, 2 ); |