Ignore:
Timestamp:
May 13, 2014, 11:39:04 AM (11 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update trunk to 3.6.23

Location:
trunk/server
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source3/printing/nt_printing_ads.c

    r745 r862  
    8888}
    8989
     90WERROR 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
     159out_ctx_free:
     160        talloc_free(tmp_ctx);
     161        return result;
     162}
     163
     164static 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
    90244static WERROR nt_printer_publish_ads(struct messaging_context *msg_ctx,
    91245                                     ADS_STRUCT *ads,
     
    113267
    114268        /* 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        }
    116276
    117277        /* We use ldap_get_dn here as we need the answer
     
    119279
    120280        srv_dn_utf8 = ldap_get_dn((LDAP *)ads->ldap.ld, (LDAPMessage *)res);
     281        ads_msgfree(ads, res);
    121282        if (!srv_dn_utf8) {
    122283                TALLOC_FREE(ctx);
    123284                return WERR_SERVER_UNAVAILABLE;
    124285        }
    125         ads_msgfree(ads, res);
    126286        srv_cn_utf8 = ldap_explode_dn(srv_dn_utf8, 1);
    127287        if (!srv_cn_utf8) {
     
    168328
    169329        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        }
    176339
    177340        /* publish it */
     
    267430                break;
    268431        case DSPRINT_UNPUBLISH:
    269                 pinfo2->attributes ^= PRINTER_ATTRIBUTE_PUBLISHED;
     432                pinfo2->attributes &= (~PRINTER_ATTRIBUTE_PUBLISHED);
    270433                break;
    271434        default:
     
    391554                          const struct auth_serversupplied_info *session_info,
    392555                          struct messaging_context *msg_ctx,
    393                           const char *servername, char *printer, struct GUID *guid,
     556                          const char *servername,
     557                          const char *printer,
    394558                          struct spoolss_PrinterInfo2 **info2)
    395559{
    396560        struct spoolss_PrinterInfo2 *pinfo2 = NULL;
    397         enum winreg_Type type;
    398         uint8_t *data;
    399         uint32_t data_size;
    400561        WERROR result;
    401         NTSTATUS status;
    402562        struct dcerpc_binding_handle *b;
    403563
     
    421581        }
    422582
    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 swapped
    439            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:
    464583        if (info2) {
    465584                *info2 = talloc_move(mem_ctx, &pinfo2);
     
    469588}
    470589#else
     590WERROR 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
    471598WERROR nt_printer_publish(TALLOC_CTX *mem_ctx,
    472599                          const struct auth_serversupplied_info *session_info,
     
    486613                          const struct auth_serversupplied_info *session_info,
    487614                          struct messaging_context *msg_ctx,
    488                           const char *servername, char *printer, struct GUID *guid,
     615                          const char *servername,
     616                          const char *printer,
    489617                          struct spoolss_PrinterInfo2 **info2)
    490618{
  • trunk/server/source3/printing/nt_printing_migrate.c

    r751 r862  
    104104                                     const char *key_name,
    105105                                     unsigned char *data,
    106                                      size_t length)
     106                                     size_t length,
     107                                     bool do_string_conversion)
    107108{
    108109        struct dcerpc_binding_handle *b = winreg_pipe->binding_handle;
     
    122123        ZERO_STRUCT(r);
    123124
     125        if (do_string_conversion) {
     126                r.string_flags = LIBNDR_FLAG_STR_ASCII;
     127        }
     128
    124129        ndr_err = ndr_pull_struct_blob(&blob, mem_ctx, &r,
    125130                   (ndr_pull_flags_fn_t)ndr_pull_ntprinting_driver);
     
    178183                                      const char *key_name,
    179184                                      unsigned char *data,
    180                                       size_t length)
     185                                      size_t length,
     186                                      bool do_string_conversion)
    181187{
    182188        struct dcerpc_binding_handle *b = winreg_pipe->binding_handle;
     
    200206
    201207        ZERO_STRUCT(r);
     208
     209        if (do_string_conversion) {
     210                r.info.string_flags = LIBNDR_FLAG_STR_ASCII;
     211        }
    202212
    203213        ndr_err = ndr_pull_struct_blob(&blob, mem_ctx, &r,
  • trunk/server/source3/printing/nt_printing_migrate.h

    r745 r862  
    3131                                     const char *key_name,
    3232                                     unsigned char *data,
    33                                      size_t length);
     33                                     size_t length,
     34                                     bool do_string_conversion);
    3435NTSTATUS printing_tdb_migrate_printer(TALLOC_CTX *mem_ctx,
    3536                                      struct rpc_pipe_client *winreg_pipe,
    3637                                      const char *key_name,
    3738                                      unsigned char *data,
    38                                       size_t length);
     39                                      size_t length,
     40                                      bool do_string_conversion);
    3941NTSTATUS printing_tdb_migrate_secdesc(TALLOC_CTX *mem_ctx,
    4042                                      struct rpc_pipe_client *winreg_pipe,
  • trunk/server/source3/printing/nt_printing_migrate_internal.c

    r745 r862  
    115115                                                (const char *) kbuf.dptr + strlen(DRIVERS_PREFIX),
    116116                                                dbuf.dptr,
    117                                                 dbuf.dsize);
     117                                                dbuf.dsize,
     118                                                false);
    118119                        SAFE_FREE(dbuf.dptr);
    119120                        if (!NT_STATUS_IS_OK(status)) {
     
    131132                                                 printer_name,
    132133                                                 dbuf.dptr,
    133                                                  dbuf.dsize);
     134                                                 dbuf.dsize,
     135                                                 false);
    134136                        SAFE_FREE(dbuf.dptr);
    135137                        if (!NT_STATUS_IS_OK(status)) {
  • trunk/server/source3/printing/printing.c

    r751 r862  
    16611661}
    16621662
     1663/****************************************************************************
     1664 Notify smbds of new printcap data
     1665**************************************************************************/
     1666static 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
    16631681static bool printer_housekeeping_fn(const struct timeval *now,
    16641682                                    void *private_data)
     
    16831701}
    16841702
     1703static 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
     1713static 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
     1728static 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
    16851740static pid_t background_lpq_updater_pid = -1;
    16861741
     
    17181773                int ret;
    17191774                NTSTATUS status;
     1775                struct tevent_signal *se;
    17201776
    17211777                /* Child. */
     
    17321788                }
    17331789
    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                }
    17361802
    17371803                if (!serverid_register(procid_self(),
     
    17471813                messaging_register(msg_ctx, NULL, MSG_PRINTER_UPDATE,
    17481814                                   print_queue_receive);
     1815                messaging_register(msg_ctx, NULL, MSG_SMB_CONF_UPDATED,
     1816                                   printing_conf_updated);
    17491817
    17501818                fde = tevent_add_fd(ev, ev, pause_pipe[1], TEVENT_FD_READ,
     
    17551823                        smb_panic("tevent_add_fd() failed for pause_pipe");
    17561824                }
     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);
    17571830
    17581831                if (!(event_add_idle(ev, NULL,
  • trunk/server/source3/printing/spoolssd.c

    r745 r862  
    7272        DEBUG(10, ("Got message saying smb.conf was updated. Reloading.\n"));
    7373        change_to_root_user();
     74        spoolss_reopen_logs();
     75}
     76
     77static 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();
    7488        reload_printers(ev_ctx, msg);
    75         spoolss_reopen_logs();
    7689}
    7790
     
    112125        change_to_root_user();
    113126        DEBUG(1,("Reloading printers after SIGHUP\n"));
    114         reload_printers(ev, msg_ctx);
    115127        spoolss_reopen_logs();
    116128}
     
    199211        messaging_register(msg_ctx, ev_ctx,
    200212                           MSG_SMB_CONF_UPDATED, smb_conf_updated);
     213        messaging_register(msg_ctx, ev_ctx,
     214                           MSG_PRINTER_PCAP, spoolss_pcap_updated);
    201215
    202216        /*
Note: See TracChangeset for help on using the changeset viewer.