Changeset 862 for trunk/server/source3/printing
- Timestamp:
- May 13, 2014, 11:39:04 AM (11 years ago)
- Location:
- trunk/server
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server
- Property svn:mergeinfo changed
/vendor/current merged: 860
- Property svn:mergeinfo changed
-
trunk/server/source3/printing/nt_printing_ads.c
r745 r862 88 88 } 89 89 90 WERROR nt_printer_guid_get(TALLOC_CTX *mem_ctx, 91 const struct auth_serversupplied_info *session_info, 92 struct messaging_context *msg_ctx, 93 const char *printer, struct GUID *guid) 94 { 95 TALLOC_CTX *tmp_ctx; 96 enum winreg_Type type; 97 DATA_BLOB blob; 98 uint32_t len; 99 NTSTATUS status; 100 WERROR result; 101 102 tmp_ctx = talloc_new(mem_ctx); 103 if (tmp_ctx == NULL) { 104 DEBUG(0, ("out of memory?!\n")); 105 return WERR_NOMEM; 106 } 107 108 result = winreg_get_printer_dataex_internal(tmp_ctx, session_info, 109 msg_ctx, printer, 110 SPOOL_DSSPOOLER_KEY, 111 "objectGUID", 112 &type, 113 &blob.data, 114 &len); 115 if (!W_ERROR_IS_OK(result)) { 116 DEBUG(0, ("Failed to get GUID for printer %s\n", printer)); 117 goto out_ctx_free; 118 } 119 blob.length = (size_t)len; 120 121 /* We used to store the guid as REG_BINARY, then swapped 122 to REG_SZ for Vista compatibility so check for both */ 123 124 switch (type) { 125 case REG_SZ: { 126 bool ok; 127 const char *guid_str; 128 ok = pull_reg_sz(tmp_ctx, &blob, &guid_str); 129 if (!ok) { 130 DEBUG(0, ("Failed to unmarshall GUID for printer %s\n", 131 printer)); 132 result = WERR_REG_CORRUPT; 133 goto out_ctx_free; 134 } 135 status = GUID_from_string(guid_str, guid); 136 if (!NT_STATUS_IS_OK(status)) { 137 DEBUG(0, ("bad GUID for printer %s\n", printer)); 138 result = ntstatus_to_werror(status); 139 goto out_ctx_free; 140 } 141 break; 142 } 143 case REG_BINARY: 144 if (blob.length != sizeof(struct GUID)) { 145 DEBUG(0, ("bad GUID for printer %s\n", printer)); 146 result = WERR_REG_CORRUPT; 147 goto out_ctx_free; 148 } 149 memcpy(guid, blob.data, sizeof(struct GUID)); 150 break; 151 default: 152 DEBUG(0,("GUID value stored as invalid type (%d)\n", type)); 153 result = WERR_REG_CORRUPT; 154 goto out_ctx_free; 155 break; 156 } 157 result = WERR_OK; 158 159 out_ctx_free: 160 talloc_free(tmp_ctx); 161 return result; 162 } 163 164 static WERROR nt_printer_info_to_mods(TALLOC_CTX *ctx, 165 struct spoolss_PrinterInfo2 *info2, 166 ADS_MODLIST *mods) 167 { 168 char *info_str; 169 170 ads_mod_str(ctx, mods, SPOOL_REG_PRINTERNAME, info2->sharename); 171 ads_mod_str(ctx, mods, SPOOL_REG_SHORTSERVERNAME, global_myname()); 172 ads_mod_str(ctx, mods, SPOOL_REG_SERVERNAME, get_mydnsfullname()); 173 174 info_str = talloc_asprintf(ctx, "\\\\%s\\%s", 175 get_mydnsfullname(), info2->sharename); 176 if (info_str == NULL) { 177 return WERR_NOMEM; 178 } 179 ads_mod_str(ctx, mods, SPOOL_REG_UNCNAME, info_str); 180 181 info_str = talloc_asprintf(ctx, "%d", 4); 182 if (info_str == NULL) { 183 return WERR_NOMEM; 184 } 185 ads_mod_str(ctx, mods, SPOOL_REG_VERSIONNUMBER, info_str); 186 187 /* empty strings in the mods list result in an attrubute error */ 188 if (strlen(info2->drivername) != 0) 189 ads_mod_str(ctx, mods, SPOOL_REG_DRIVERNAME, info2->drivername); 190 if (strlen(info2->location) != 0) 191 ads_mod_str(ctx, mods, SPOOL_REG_LOCATION, info2->location); 192 if (strlen(info2->comment) != 0) 193 ads_mod_str(ctx, mods, SPOOL_REG_DESCRIPTION, info2->comment); 194 if (strlen(info2->portname) != 0) 195 ads_mod_str(ctx, mods, SPOOL_REG_PORTNAME, info2->portname); 196 if (strlen(info2->sepfile) != 0) 197 ads_mod_str(ctx, mods, SPOOL_REG_PRINTSEPARATORFILE, info2->sepfile); 198 199 info_str = talloc_asprintf(ctx, "%u", info2->starttime); 200 if (info_str == NULL) { 201 return WERR_NOMEM; 202 } 203 ads_mod_str(ctx, mods, SPOOL_REG_PRINTSTARTTIME, info_str); 204 205 info_str = talloc_asprintf(ctx, "%u", info2->untiltime); 206 if (info_str == NULL) { 207 return WERR_NOMEM; 208 } 209 ads_mod_str(ctx, mods, SPOOL_REG_PRINTENDTIME, info_str); 210 211 info_str = talloc_asprintf(ctx, "%u", info2->priority); 212 if (info_str == NULL) { 213 return WERR_NOMEM; 214 } 215 ads_mod_str(ctx, mods, SPOOL_REG_PRIORITY, info_str); 216 217 if (info2->attributes & PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS) { 218 ads_mod_str(ctx, mods, SPOOL_REG_PRINTKEEPPRINTEDJOBS, "TRUE"); 219 } else { 220 ads_mod_str(ctx, mods, SPOOL_REG_PRINTKEEPPRINTEDJOBS, "FALSE"); 221 } 222 223 switch (info2->attributes & 0x3) { 224 case 0: 225 ads_mod_str(ctx, mods, SPOOL_REG_PRINTSPOOLING, 226 SPOOL_REGVAL_PRINTWHILESPOOLING); 227 break; 228 case 1: 229 ads_mod_str(ctx, mods, SPOOL_REG_PRINTSPOOLING, 230 SPOOL_REGVAL_PRINTAFTERSPOOLED); 231 break; 232 case 2: 233 ads_mod_str(ctx, mods, SPOOL_REG_PRINTSPOOLING, 234 SPOOL_REGVAL_PRINTDIRECT); 235 break; 236 default: 237 DEBUG(3, ("unsupported printer attributes %x\n", 238 info2->attributes)); 239 } 240 241 return WERR_OK; 242 } 243 90 244 static WERROR nt_printer_publish_ads(struct messaging_context *msg_ctx, 91 245 ADS_STRUCT *ads, … … 113 267 114 268 /* figure out where to publish */ 115 ads_find_machine_acct(ads, &res, global_myname()); 269 ads_rc = ads_find_machine_acct(ads, &res, global_myname()); 270 if (!ADS_ERR_OK(ads_rc)) { 271 DEBUG(0, ("failed to find machine account for %s\n", 272 global_myname())); 273 TALLOC_FREE(ctx); 274 return WERR_NOT_FOUND; 275 } 116 276 117 277 /* We use ldap_get_dn here as we need the answer … … 119 279 120 280 srv_dn_utf8 = ldap_get_dn((LDAP *)ads->ldap.ld, (LDAPMessage *)res); 281 ads_msgfree(ads, res); 121 282 if (!srv_dn_utf8) { 122 283 TALLOC_FREE(ctx); 123 284 return WERR_SERVER_UNAVAILABLE; 124 285 } 125 ads_msgfree(ads, res);126 286 srv_cn_utf8 = ldap_explode_dn(srv_dn_utf8, 1); 127 287 if (!srv_cn_utf8) { … … 168 328 169 329 if (mods == NULL) { 170 SAFE_FREE(prt_dn); 171 TALLOC_FREE(ctx); 172 return WERR_NOMEM; 173 } 174 175 ads_mod_str(ctx, &mods, SPOOL_REG_PRINTERNAME, printer); 330 TALLOC_FREE(ctx); 331 return WERR_NOMEM; 332 } 333 334 win_rc = nt_printer_info_to_mods(ctx, pinfo2, &mods); 335 if (!W_ERROR_IS_OK(win_rc)) { 336 TALLOC_FREE(ctx); 337 return win_rc; 338 } 176 339 177 340 /* publish it */ … … 267 430 break; 268 431 case DSPRINT_UNPUBLISH: 269 pinfo2->attributes ^= PRINTER_ATTRIBUTE_PUBLISHED;432 pinfo2->attributes &= (~PRINTER_ATTRIBUTE_PUBLISHED); 270 433 break; 271 434 default: … … 391 554 const struct auth_serversupplied_info *session_info, 392 555 struct messaging_context *msg_ctx, 393 const char *servername, char *printer, struct GUID *guid, 556 const char *servername, 557 const char *printer, 394 558 struct spoolss_PrinterInfo2 **info2) 395 559 { 396 560 struct spoolss_PrinterInfo2 *pinfo2 = NULL; 397 enum winreg_Type type;398 uint8_t *data;399 uint32_t data_size;400 561 WERROR result; 401 NTSTATUS status;402 562 struct dcerpc_binding_handle *b; 403 563 … … 421 581 } 422 582 423 if (!guid) {424 goto done;425 }426 427 /* fetching printer guids really ought to be a separate function. */428 429 result = winreg_get_printer_dataex(mem_ctx, b,430 printer,431 SPOOL_DSSPOOLER_KEY, "objectGUID",432 &type, &data, &data_size);433 if (!W_ERROR_IS_OK(result)) {434 TALLOC_FREE(pinfo2);435 return false;436 }437 438 /* We used to store the guid as REG_BINARY, then swapped439 to REG_SZ for Vista compatibility so check for both */440 441 switch (type) {442 case REG_SZ:443 status = GUID_from_string((char *)data, guid);444 if (!NT_STATUS_IS_OK(status)) {445 TALLOC_FREE(pinfo2);446 return false;447 }448 break;449 450 case REG_BINARY:451 if (data_size != sizeof(struct GUID)) {452 TALLOC_FREE(pinfo2);453 return false;454 }455 memcpy(guid, data, sizeof(struct GUID));456 break;457 default:458 DEBUG(0,("is_printer_published: GUID value stored as "459 "invaluid type (%d)\n", type));460 break;461 }462 463 done:464 583 if (info2) { 465 584 *info2 = talloc_move(mem_ctx, &pinfo2); … … 469 588 } 470 589 #else 590 WERROR nt_printer_guid_get(TALLOC_CTX *mem_ctx, 591 const struct auth_serversupplied_info *session_info, 592 struct messaging_context *msg_ctx, 593 const char *printer, struct GUID *guid) 594 { 595 return WERR_NOT_SUPPORTED; 596 } 597 471 598 WERROR nt_printer_publish(TALLOC_CTX *mem_ctx, 472 599 const struct auth_serversupplied_info *session_info, … … 486 613 const struct auth_serversupplied_info *session_info, 487 614 struct messaging_context *msg_ctx, 488 const char *servername, char *printer, struct GUID *guid, 615 const char *servername, 616 const char *printer, 489 617 struct spoolss_PrinterInfo2 **info2) 490 618 { -
trunk/server/source3/printing/nt_printing_migrate.c
r751 r862 104 104 const char *key_name, 105 105 unsigned char *data, 106 size_t length) 106 size_t length, 107 bool do_string_conversion) 107 108 { 108 109 struct dcerpc_binding_handle *b = winreg_pipe->binding_handle; … … 122 123 ZERO_STRUCT(r); 123 124 125 if (do_string_conversion) { 126 r.string_flags = LIBNDR_FLAG_STR_ASCII; 127 } 128 124 129 ndr_err = ndr_pull_struct_blob(&blob, mem_ctx, &r, 125 130 (ndr_pull_flags_fn_t)ndr_pull_ntprinting_driver); … … 178 183 const char *key_name, 179 184 unsigned char *data, 180 size_t length) 185 size_t length, 186 bool do_string_conversion) 181 187 { 182 188 struct dcerpc_binding_handle *b = winreg_pipe->binding_handle; … … 200 206 201 207 ZERO_STRUCT(r); 208 209 if (do_string_conversion) { 210 r.info.string_flags = LIBNDR_FLAG_STR_ASCII; 211 } 202 212 203 213 ndr_err = ndr_pull_struct_blob(&blob, mem_ctx, &r, -
trunk/server/source3/printing/nt_printing_migrate.h
r745 r862 31 31 const char *key_name, 32 32 unsigned char *data, 33 size_t length); 33 size_t length, 34 bool do_string_conversion); 34 35 NTSTATUS printing_tdb_migrate_printer(TALLOC_CTX *mem_ctx, 35 36 struct rpc_pipe_client *winreg_pipe, 36 37 const char *key_name, 37 38 unsigned char *data, 38 size_t length); 39 size_t length, 40 bool do_string_conversion); 39 41 NTSTATUS printing_tdb_migrate_secdesc(TALLOC_CTX *mem_ctx, 40 42 struct rpc_pipe_client *winreg_pipe, -
trunk/server/source3/printing/nt_printing_migrate_internal.c
r745 r862 115 115 (const char *) kbuf.dptr + strlen(DRIVERS_PREFIX), 116 116 dbuf.dptr, 117 dbuf.dsize); 117 dbuf.dsize, 118 false); 118 119 SAFE_FREE(dbuf.dptr); 119 120 if (!NT_STATUS_IS_OK(status)) { … … 131 132 printer_name, 132 133 dbuf.dptr, 133 dbuf.dsize); 134 dbuf.dsize, 135 false); 134 136 SAFE_FREE(dbuf.dptr); 135 137 if (!NT_STATUS_IS_OK(status)) { -
trunk/server/source3/printing/printing.c
r751 r862 1661 1661 } 1662 1662 1663 /**************************************************************************** 1664 Notify smbds of new printcap data 1665 **************************************************************************/ 1666 static void reload_pcap_change_notify(struct tevent_context *ev, 1667 struct messaging_context *msg_ctx) 1668 { 1669 /* 1670 * Reload the printers first in the background process so that 1671 * newly added printers get default values created in the registry. 1672 * 1673 * This will block the process for some time (~1 sec per printer), but 1674 * it doesn't block smbd's servering clients. 1675 */ 1676 reload_printers_full(ev, msg_ctx); 1677 1678 message_send_all(msg_ctx, MSG_PRINTER_PCAP, NULL, 0, NULL); 1679 } 1680 1663 1681 static bool printer_housekeeping_fn(const struct timeval *now, 1664 1682 void *private_data) … … 1683 1701 } 1684 1702 1703 static void printing_sig_term_handler(struct tevent_context *ev, 1704 struct tevent_signal *se, 1705 int signum, 1706 int count, 1707 void *siginfo, 1708 void *private_data) 1709 { 1710 exit_server_cleanly("termination signal"); 1711 } 1712 1713 static void printing_sig_hup_handler(struct tevent_context *ev, 1714 struct tevent_signal *se, 1715 int signum, 1716 int count, 1717 void *siginfo, 1718 void *private_data) 1719 { 1720 struct messaging_context *msg_ctx = talloc_get_type_abort( 1721 private_data, struct messaging_context); 1722 1723 DEBUG(1,("Reloading printers after SIGHUP\n")); 1724 pcap_cache_reload(ev, msg_ctx, 1725 &reload_pcap_change_notify); 1726 } 1727 1728 static void printing_conf_updated(struct messaging_context *msg, 1729 void *private_data, 1730 uint32_t msg_type, 1731 struct server_id server_id, 1732 DATA_BLOB *data) 1733 { 1734 DEBUG(5,("Reloading printers after conf change\n")); 1735 pcap_cache_reload(messaging_event_context(msg), msg, 1736 &reload_pcap_change_notify); 1737 } 1738 1739 1685 1740 static pid_t background_lpq_updater_pid = -1; 1686 1741 … … 1718 1773 int ret; 1719 1774 NTSTATUS status; 1775 struct tevent_signal *se; 1720 1776 1721 1777 /* Child. */ … … 1732 1788 } 1733 1789 1734 smbd_setup_sig_term_handler(); 1735 smbd_setup_sig_hup_handler(ev, msg_ctx); 1790 se = tevent_add_signal(ev, ev, SIGTERM, 0, 1791 printing_sig_term_handler, 1792 NULL); 1793 if (se == NULL) { 1794 smb_panic("failed to setup SIGTERM handler"); 1795 } 1796 se = tevent_add_signal(ev, ev, SIGHUP, 0, 1797 printing_sig_hup_handler, 1798 msg_ctx); 1799 if (se == NULL) { 1800 smb_panic("failed to setup SIGHUP handler"); 1801 } 1736 1802 1737 1803 if (!serverid_register(procid_self(), … … 1747 1813 messaging_register(msg_ctx, NULL, MSG_PRINTER_UPDATE, 1748 1814 print_queue_receive); 1815 messaging_register(msg_ctx, NULL, MSG_SMB_CONF_UPDATED, 1816 printing_conf_updated); 1749 1817 1750 1818 fde = tevent_add_fd(ev, ev, pause_pipe[1], TEVENT_FD_READ, … … 1755 1823 smb_panic("tevent_add_fd() failed for pause_pipe"); 1756 1824 } 1825 1826 /* reload on startup to ensure parent smbd is refreshed */ 1827 pcap_cache_reload(server_event_context(), 1828 smbd_messaging_context(), 1829 &reload_pcap_change_notify); 1757 1830 1758 1831 if (!(event_add_idle(ev, NULL, -
trunk/server/source3/printing/spoolssd.c
r745 r862 72 72 DEBUG(10, ("Got message saying smb.conf was updated. Reloading.\n")); 73 73 change_to_root_user(); 74 spoolss_reopen_logs(); 75 } 76 77 static void spoolss_pcap_updated(struct messaging_context *msg, 78 void *private_data, 79 uint32_t msg_type, 80 struct server_id server_id, 81 DATA_BLOB *data) 82 { 83 struct tevent_context *ev_ctx = talloc_get_type_abort(private_data, 84 struct tevent_context); 85 86 DEBUG(10, ("Got message saying pcap was updated. Reloading.\n")); 87 change_to_root_user(); 74 88 reload_printers(ev_ctx, msg); 75 spoolss_reopen_logs();76 89 } 77 90 … … 112 125 change_to_root_user(); 113 126 DEBUG(1,("Reloading printers after SIGHUP\n")); 114 reload_printers(ev, msg_ctx);115 127 spoolss_reopen_logs(); 116 128 } … … 199 211 messaging_register(msg_ctx, ev_ctx, 200 212 MSG_SMB_CONF_UPDATED, smb_conf_updated); 213 messaging_register(msg_ctx, ev_ctx, 214 MSG_PRINTER_PCAP, spoolss_pcap_updated); 201 215 202 216 /*
Note:
See TracChangeset
for help on using the changeset viewer.