Ignore:
Timestamp:
Nov 24, 2016, 1:14:11 PM (9 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to version 4.4.3

Location:
vendor/current/source3/printing
Files:
2 added
25 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source3/printing/load.c

    r746 r988  
    2121#include "printing/pcap.h"
    2222#include "printing/load.h"
     23#include "lib/param/loadparm.h"
    2324
    2425/***************************************************************************
     
    4041                return;
    4142
    42         auto_serv = lp_auto_services();
     43        auto_serv = lp_auto_services(talloc_tos());
    4344        str = SMB_STRDUP(auto_serv);
    4445        TALLOC_FREE(auto_serv);
     
    6566                   struct messaging_context *msg_ctx)
    6667{
    67         SMB_ASSERT(pcap_cache_loaded());
     68        SMB_ASSERT(pcap_cache_loaded(NULL));
    6869
    6970        add_auto_printers();
     
    7172        /* load all printcap printers */
    7273        if (lp_load_printers() && lp_servicenumber(PRINTERS_NAME) >= 0)
    73                 pcap_printer_fn(lp_add_one_printer, NULL);
     74                pcap_printer_read_fn(lp_add_one_printer, NULL);
    7475}
  • vendor/current/source3/printing/lpq_parse.c

    r746 r988  
    802802                char *p = strrchr_m(tok[6],'/');
    803803                if (p) {
     804                        size_t len = strlen(tok[6])+1;
    804805                        fstrcpy(tmp,p+1);
    805                         fstrcpy(tok[6],tmp);
     806                        strlcpy(tok[6],tmp, len);
    806807                }
    807808        }
     
    11171118                        handle them so that most severe condition is shown */
    11181119                int i;
    1119                 strlower_m(line);
     1120                if (!strlower_m(line)) {
     1121                        return false;
     1122                }
    11201123     
    11211124                switch (status->status) {
  • vendor/current/source3/printing/notify.c

    r740 r988  
    3636        struct spoolss_notify_msg *msg;
    3737        struct timeval tv;
    38         uint8 *buf;
     38        uint8_t *buf;
    3939        size_t buflen;
    4040} *notify_queue_head = NULL;
     
    6363{
    6464        int snum = lp_servicenumber(qname);
    65         if (snum == -1 || !lp_print_ok(snum))
     65        if (snum == -1 || !lp_printable(snum))
    6666                return -1;
    6767        return snum;
     
    8484{
    8585        struct spoolss_notify_msg *msg = q->msg;
    86         uint8 *buf = NULL;
     86        uint8_t *buf = NULL;
    8787        size_t buflen = 0, len;
    8888
     
    9595
    9696        len += tdb_pack(buf + len, buflen - len, "ddddddd",
    97                         (uint32)q->tv.tv_sec, (uint32)q->tv.tv_usec,
     97                        (uint32_t)q->tv.tv_sec, (uint32_t)q->tv.tv_usec,
    9898                        msg->type, msg->field, msg->id, msg->len, msg->flags);
    9999
     
    108108
    109109        if (buflen != len) {
    110                 buf = (uint8 *)TALLOC_REALLOC(send_ctx, buf, len);
     110                buf = (uint8_t *)TALLOC_REALLOC(send_ctx, buf, len);
    111111                if (!buf)
    112112                        return False;
     
    195195                                   pid_to_procid(pid_list[i]),
    196196                                   MSG_PRINTER_NOTIFY2 | MSG_FLAG_LOWPRIORITY,
    197                                    (uint8 *)buf, offset);
     197                                   (uint8_t *)buf, offset);
    198198
    199199                if ((timeout != 0) && timeval_expired(&end_time)) {
     
    255255       
    256256        if ( from->len ) {
    257                 to->notify.data = (char *)TALLOC_MEMDUP(send_ctx, from->notify.data, from->len );
     257                to->notify.data = (char *)talloc_memdup(send_ctx, from->notify.data, from->len );
    258258                if ( !to->notify.data ) {
    259                         DEBUG(0,("copy_notify2_msg: TALLOC_MEMDUP() of size [%d] failed!\n", from->len ));
     259                        DEBUG(0,("copy_notify2_msg: talloc_memdup() of size [%d] failed!\n", from->len ));
    260260                        return False;
    261261                }
     
    306306        /* Store the message on the pending queue. */
    307307
    308         pnqueue = TALLOC_P(send_ctx, struct notify_queue);
     308        pnqueue = talloc(send_ctx, struct notify_queue);
    309309        if (!pnqueue) {
    310310                DEBUG(0,("send_spoolss_notify2_msg: Out of memory.\n"));
     
    314314        /* allocate a new msg structure and copy the fields */
    315315       
    316         if ( !(pnqueue->msg = TALLOC_P(send_ctx, SPOOLSS_NOTIFY_MSG)) ) {
     316        if ( !(pnqueue->msg = talloc(send_ctx, SPOOLSS_NOTIFY_MSG)) ) {
    317317                DEBUG(0,("send_spoolss_notify2_msg: talloc() of size [%lu] failed!\n",
    318318                        (unsigned long)sizeof(SPOOLSS_NOTIFY_MSG)));
     
    332332         */
    333333
    334         DLIST_ADD_END(notify_queue_head, pnqueue, struct notify_queue *);
     334        DLIST_ADD_END(notify_queue_head, pnqueue);
    335335        num_messages++;
    336336
     
    346346static void send_notify_field_values(struct tevent_context *ev,
    347347                                     struct messaging_context *msg_ctx,
    348                                      const char *sharename, uint32 type,
    349                                      uint32 field, uint32 id, uint32 value1,
    350                                      uint32 value2, uint32 flags)
     348                                     const char *sharename, uint32_t type,
     349                                     uint32_t field, uint32_t id, uint32_t value1,
     350                                     uint32_t value2, uint32_t flags)
    351351{
    352352        struct spoolss_notify_msg *msg;
     
    358358                return;
    359359
    360         msg = TALLOC_P(send_ctx, struct spoolss_notify_msg);
     360        msg = talloc_zero(send_ctx, struct spoolss_notify_msg);
    361361        if (!msg)
    362362                return;
    363 
    364         ZERO_STRUCTP(msg);
    365363
    366364        fstrcpy(msg->printer, sharename);
     
    377375static void send_notify_field_buffer(struct tevent_context *ev,
    378376                                     struct messaging_context *msg_ctx,
    379                                      const char *sharename, uint32 type,
    380                                      uint32 field, uint32 id, uint32 len,
     377                                     const char *sharename, uint32_t type,
     378                                     uint32_t field, uint32_t id, uint32_t len,
    381379                                     const char *buffer)
    382380{
     
    389387                return;
    390388
    391         msg = TALLOC_P(send_ctx, struct spoolss_notify_msg);
     389        msg = talloc_zero(send_ctx, struct spoolss_notify_msg);
    392390        if (!msg)
    393391                return;
    394 
    395         ZERO_STRUCTP(msg);
    396392
    397393        fstrcpy(msg->printer, sharename);
     
    400396        msg->id = id;
    401397        msg->len = len;
    402         msg->notify.data = CONST_DISCARD(char *,buffer);
     398        msg->notify.data = discard_const_p(char, buffer);
    403399
    404400        send_spoolss_notify2_msg(ev, msg_ctx, msg);
     
    409405void notify_printer_status_byname(struct tevent_context *ev,
    410406                                  struct messaging_context *msg_ctx,
    411                                   const char *sharename, uint32 status)
     407                                  const char *sharename, uint32_t status)
    412408{
    413409        /* Printer status stored in value1 */
     
    422418void notify_printer_status(struct tevent_context *ev,
    423419                           struct messaging_context *msg_ctx,
    424                            int snum, uint32 status)
    425 {
    426         const char *sharename = lp_servicename(snum);
     420                           int snum, uint32_t status)
     421{
     422        const char *sharename = lp_servicename(talloc_tos(), snum);
    427423
    428424        if (sharename)
     
    432428void notify_job_status_byname(struct tevent_context *ev,
    433429                              struct messaging_context *msg_ctx,
    434                               const char *sharename, uint32 jobid,
    435                               uint32 status,
    436                               uint32 flags)
     430                              const char *sharename, uint32_t jobid,
     431                              uint32_t status,
     432                              uint32_t flags)
    437433{
    438434        /* Job id stored in id field, status in value1 */
     
    446442void notify_job_status(struct tevent_context *ev,
    447443                       struct messaging_context *msg_ctx,
    448                        const char *sharename, uint32 jobid, uint32 status)
     444                       const char *sharename, uint32_t jobid, uint32_t status)
    449445{
    450446        notify_job_status_byname(ev, msg_ctx, sharename, jobid, status, 0);
     
    453449void notify_job_total_bytes(struct tevent_context *ev,
    454450                            struct messaging_context *msg_ctx,
    455                             const char *sharename, uint32 jobid,
    456                             uint32 size)
     451                            const char *sharename, uint32_t jobid,
     452                            uint32_t size)
    457453{
    458454        /* Job id stored in id field, status in value1 */
     
    466462void notify_job_total_pages(struct tevent_context *ev,
    467463                            struct messaging_context *msg_ctx,
    468                             const char *sharename, uint32 jobid,
    469                             uint32 pages)
     464                            const char *sharename, uint32_t jobid,
     465                            uint32_t pages)
    470466{
    471467        /* Job id stored in id field, status in value1 */
     
    479475void notify_job_username(struct tevent_context *ev,
    480476                         struct messaging_context *msg_ctx,
    481                          const char *sharename, uint32 jobid, char *name)
     477                         const char *sharename, uint32_t jobid, char *name)
    482478{
    483479        send_notify_field_buffer(
     
    489485void notify_job_name(struct tevent_context *ev,
    490486                     struct messaging_context *msg_ctx,
    491                      const char *sharename, uint32 jobid, char *name)
     487                     const char *sharename, uint32_t jobid, char *name)
    492488{
    493489        send_notify_field_buffer(
     
    499495void notify_job_submitted(struct tevent_context *ev,
    500496                          struct messaging_context *msg_ctx,
    501                           const char *sharename, uint32 jobid,
     497                          const char *sharename, uint32_t jobid,
    502498                          time_t submitted)
    503499{
     
    512508                           int snum, const char *driver_name)
    513509{
    514         const char *sharename = lp_servicename(snum);
     510        const char *sharename = lp_servicename(talloc_tos(), snum);
    515511
    516512        send_notify_field_buffer(
     
    524520                            int snum, const char *comment)
    525521{
    526         const char *sharename = lp_servicename(snum);
     522        const char *sharename = lp_servicename(talloc_tos(), snum);
    527523
    528524        send_notify_field_buffer(
     
    536532                              int snum, const char *share_name)
    537533{
    538         const char *sharename = lp_servicename(snum);
     534        const char *sharename = lp_servicename(talloc_tos(), snum);
    539535
    540536        send_notify_field_buffer(
     
    548544                                int snum, const char *printername)
    549545{
    550         const char *sharename = lp_servicename(snum);
     546        const char *sharename = lp_servicename(talloc_tos(), snum);
    551547
    552548        send_notify_field_buffer(
     
    560556                         int snum, const char *port_name)
    561557{
    562         const char *sharename = lp_servicename(snum);
     558        const char *sharename = lp_servicename(talloc_tos(), snum);
    563559
    564560        send_notify_field_buffer(
     
    572568                             int snum, const char *location)
    573569{
    574         const char *sharename = lp_servicename(snum);
     570        const char *sharename = lp_servicename(talloc_tos(), snum);
    575571
    576572        send_notify_field_buffer(
     
    584580                            int snum, const char *sepfile)
    585581{
    586         const char *sharename = lp_servicename(snum);
     582        const char *sharename = lp_servicename(talloc_tos(), snum);
    587583
    588584        send_notify_field_buffer(
     
    595591void notify_printer_byname(struct tevent_context *ev,
    596592                           struct messaging_context *msg_ctx,
    597                            const char *printername, uint32 change,
     593                           const char *printername, uint32_t change,
    598594                           const char *value)
    599595{
     
    633629        tdb = pdb->tdb;
    634630
    635         if (tdb_read_lock_bystring_with_timeout(tdb, NOTIFY_PID_LIST_KEY, 10) == -1) {
     631        if (tdb_read_lock_bystring_with_timeout(tdb, NOTIFY_PID_LIST_KEY, 10) != 0) {
    636632                DEBUG(0,("print_notify_pid_list: Failed to lock printer %s database\n",
    637633                                        printername));
     
    651647
    652648        if (num_pids) {
    653                 if ((pid_list = TALLOC_ARRAY(mem_ctx, pid_t, num_pids)) == NULL) {
     649                if ((pid_list = talloc_array(mem_ctx, pid_t, num_pids)) == NULL) {
    654650                        ret = False;
    655651                        goto done;
  • vendor/current/source3/printing/notify.h

    r740 r988  
    3030void notify_printer_status_byname(struct tevent_context *ev,
    3131                                  struct messaging_context *msg_ctx,
    32                                   const char *sharename, uint32 status);
     32                                  const char *sharename, uint32_t status);
    3333void notify_printer_status(struct tevent_context *ev,
    3434                           struct messaging_context *msg_ctx,
    35                            int snum, uint32 status);
     35                           int snum, uint32_t status);
    3636void notify_job_status_byname(struct tevent_context *ev,
    3737                              struct messaging_context *msg_ctx,
    38                               const char *sharename, uint32 jobid,
    39                               uint32 status,
    40                               uint32 flags);
     38                              const char *sharename, uint32_t jobid,
     39                              uint32_t status,
     40                              uint32_t flags);
    4141void notify_job_status(struct tevent_context *ev,
    4242                       struct messaging_context *msg_ctx,
    43                        const char *sharename, uint32 jobid, uint32 status);
     43                       const char *sharename, uint32_t jobid, uint32_t status);
    4444void notify_job_total_bytes(struct tevent_context *ev,
    4545                            struct messaging_context *msg_ctx,
    46                             const char *sharename, uint32 jobid,
    47                             uint32 size);
     46                            const char *sharename, uint32_t jobid,
     47                            uint32_t size);
    4848void notify_job_total_pages(struct tevent_context *ev,
    4949                            struct messaging_context *msg_ctx,
    50                             const char *sharename, uint32 jobid,
    51                             uint32 pages);
     50                            const char *sharename, uint32_t jobid,
     51                            uint32_t pages);
    5252void notify_job_username(struct tevent_context *ev,
    5353                         struct messaging_context *msg_ctx,
    54                          const char *sharename, uint32 jobid, char *name);
     54                         const char *sharename, uint32_t jobid, char *name);
    5555void notify_job_name(struct tevent_context *ev,
    5656                     struct messaging_context *msg_ctx,
    57                      const char *sharename, uint32 jobid, char *name);
     57                     const char *sharename, uint32_t jobid, char *name);
    5858void notify_job_submitted(struct tevent_context *ev,
    5959                          struct messaging_context *msg_ctx,
    60                           const char *sharename, uint32 jobid,
     60                          const char *sharename, uint32_t jobid,
    6161                          time_t submitted);
    6262void notify_printer_driver(struct tevent_context *ev,
     
    8080void notify_printer_byname(struct tevent_context *ev,
    8181                           struct messaging_context *msg_ctx,
    82                            const char *printername, uint32 change,
     82                           const char *printername, uint32_t change,
    8383                           const char *value);
    8484void notify_printer_sepfile(struct tevent_context *ev,
  • vendor/current/source3/printing/nt_printing.c

    r746 r988  
    3030#include "passdb/machine_sid.h"
    3131#include "smbd/smbd.h"
     32#include "smbd/globals.h"
    3233#include "auth.h"
    3334#include "messages.h"
     
    7475};
    7576
     77static bool print_driver_directories_init(void)
     78{
     79        int service, i;
     80        char *driver_path;
     81        bool ok;
     82        TALLOC_CTX *mem_ctx = talloc_stackframe();
     83
     84        service = lp_servicenumber("print$");
     85        if (service < 0) {
     86                /* We don't have a print$ share */
     87                DEBUG(5, ("No print$ share has been configured.\n"));
     88                talloc_free(mem_ctx);
     89                return true;
     90        }
     91
     92        driver_path = lp_path(mem_ctx, service);
     93        if (driver_path == NULL) {
     94                talloc_free(mem_ctx);
     95                return false;
     96        }
     97
     98        ok = directory_create_or_exist(driver_path, 0755);
     99        if (!ok) {
     100                DEBUG(1, ("Failed to create printer driver directory %s\n",
     101                          driver_path));
     102                talloc_free(mem_ctx);
     103                return false;
     104        }
     105
     106        for (i = 0; archi_table[i].long_archi != NULL; i++) {
     107                const char *arch_path;
     108
     109                arch_path = talloc_asprintf(mem_ctx,
     110                                            "%s/%s",
     111                                            driver_path,
     112                                            archi_table[i].short_archi);
     113                if (arch_path == NULL) {
     114                        talloc_free(mem_ctx);
     115                        return false;
     116                }
     117
     118                ok = directory_create_or_exist(arch_path, 0755);
     119                if (!ok) {
     120                        DEBUG(1, ("Failed to create printer driver "
     121                                  "architecture directory %s\n",
     122                                  arch_path));
     123                        talloc_free(mem_ctx);
     124                        return false;
     125                }
     126        }
     127
     128        talloc_free(mem_ctx);
     129        return true;
     130}
     131
     132/****************************************************************************
     133 Forward a MSG_PRINTER_DRVUPGRADE message from another smbd to the
     134 background lpq updater.
     135****************************************************************************/
     136
     137static void forward_drv_upgrade_printer_msg(struct messaging_context *msg,
     138                                void *private_data,
     139                                uint32_t msg_type,
     140                                struct server_id server_id,
     141                                DATA_BLOB *data)
     142{
     143        extern pid_t background_lpq_updater_pid;
     144
     145        if (background_lpq_updater_pid == -1) {
     146                DEBUG(3,("no background lpq queue updater\n"));
     147                return;
     148        }
     149
     150        messaging_send_buf(msg,
     151                        pid_to_procid(background_lpq_updater_pid),
     152                        MSG_PRINTER_DRVUPGRADE,
     153                        data->data,
     154                        data->length);
     155}
     156
    76157/****************************************************************************
    77158 Open the NT printing tdbs. Done once before fork().
     
    82163        WERROR win_rc;
    83164
     165        if (!print_driver_directories_init()) {
     166                return false;
     167        }
     168
    84169        if (!nt_printing_tdb_upgrade()) {
    85170                return false;
     
    88173        /*
    89174         * register callback to handle updating printers as new
    90          * drivers are installed
     175         * drivers are installed. Forwards to background lpq updater.
    91176         */
    92177        messaging_register(msg_ctx, NULL, MSG_PRINTER_DRVUPGRADE,
    93                            do_drv_upgrade_printer);
     178                        forward_drv_upgrade_printer_msg);
    94179
    95180        /* of course, none of the message callbacks matter if you don't
     
    149234                i++;
    150235        } while ( (archi_table[i].long_archi!=NULL ) &&
    151                   StrCaseCmp(long_archi, archi_table[i].long_archi) );
     236                  strcasecmp_m(long_archi, archi_table[i].long_archi) );
    152237
    153238        if (archi_table[i].long_archi==NULL) {
     
    173258****************************************************************************/
    174259
    175 static int get_file_version(files_struct *fsp, char *fname,uint32 *major, uint32 *minor)
     260static int get_file_version(files_struct *fsp, char *fname,uint32_t *major, uint32_t *minor)
    176261{
    177262        int     i;
     
    199284
    200285        /* Skip OEM header (if any) and the DOS stub to start of Windows header */
    201         if (SMB_VFS_LSEEK(fsp, SVAL(buf,DOS_HEADER_LFANEW_OFFSET), SEEK_SET) == (SMB_OFF_T)-1) {
     286        if (SMB_VFS_LSEEK(fsp, SVAL(buf,DOS_HEADER_LFANEW_OFFSET), SEEK_SET) == (off_t)-1) {
    202287                DEBUG(3,("get_file_version: File [%s] too short, errno = %d\n",
    203288                                fname, errno));
     
    222307                if (SMB_VFS_LSEEK(fsp,
    223308                                SVAL(buf,PE_HEADER_OPTIONAL_HEADER_SIZE)-(NE_HEADER_SIZE-PE_HEADER_SIZE),
    224                                 SEEK_CUR) == (SMB_OFF_T)-1) {
     309                                SEEK_CUR) == (off_t)-1) {
    225310                        DEBUG(3,("get_file_version: File [%s] Windows optional header too short, errno = %d\n",
    226311                                fname, errno));
     
    266351
    267352                                /* Seek to the start of the .rsrc section info */
    268                                 if (SMB_VFS_LSEEK(fsp, section_pos, SEEK_SET) == (SMB_OFF_T)-1) {
     353                                if (SMB_VFS_LSEEK(fsp, section_pos, SEEK_SET) == (off_t)-1) {
    269354                                        DEBUG(3,("get_file_version: PE file [%s] too short for section info, errno = %d\n",
    270355                                                        fname, errno));
     
    411496        bool use_version = true;
    412497
    413         uint32 new_major;
    414         uint32 new_minor;
     498        uint32_t new_major;
     499        uint32_t new_minor;
    415500        time_t new_create_time;
    416501
    417         uint32 old_major;
    418         uint32 old_minor;
     502        uint32_t old_major;
     503        uint32_t old_minor;
    419504        time_t old_create_time;
    420505
     
    447532                FILE_ATTRIBUTE_NORMAL,                  /* file_attributes */
    448533                INTERNAL_OPEN_ONLY,                     /* oplock_request */
     534                NULL,                                   /* lease */
    449535                0,                                      /* allocation_size */
    450536                0,                                      /* private_flags */
     
    452538                NULL,                                   /* ea_list */
    453539                &fsp,                                   /* result */
    454                 NULL);                                  /* pinfo */
     540                NULL,                                   /* pinfo */
     541                NULL, NULL);                            /* create context */
    455542
    456543        if (!NT_STATUS_IS_OK(status)) {
     
    500587                FILE_ATTRIBUTE_NORMAL,                  /* file_attributes */
    501588                INTERNAL_OPEN_ONLY,                     /* oplock_request */
     589                NULL,                                   /* lease */
    502590                0,                                      /* allocation_size */
    503591                0,                                      /* private_flags */
     
    505593                NULL,                                   /* ea_list */
    506594                &fsp,                                   /* result */
    507                 NULL);                                  /* pinfo */
     595                NULL,                                   /* pinfo */
     596                NULL, NULL);                            /* create context */
    508597
    509598        if (!NT_STATUS_IS_OK(status)) {
     
    575664Determine the correct cVersion associated with an architecture and driver
    576665****************************************************************************/
    577 static uint32 get_correct_cversion(struct auth_serversupplied_info *session_info,
     666static uint32_t get_correct_cversion(struct auth_session_info *session_info,
    578667                                   const char *architecture,
    579668                                   const char *driverpath_in,
     
    616705        }
    617706
    618         nt_status = create_conn_struct(talloc_tos(), &conn, printdollar_snum,
    619                                        lp_pathname(printdollar_snum),
    620                                        session_info, &oldcwd);
     707        nt_status = create_conn_struct_cwd(talloc_tos(),
     708                                           server_event_context(),
     709                                           server_messaging_context(),
     710                                           &conn,
     711                                           printdollar_snum,
     712                                           lp_path(talloc_tos(), printdollar_snum),
     713                                           session_info, &oldcwd);
    621714        if (!NT_STATUS_IS_OK(nt_status)) {
    622715                DEBUG(0,("get_correct_cversion: create_conn_struct "
     
    674767                FILE_ATTRIBUTE_NORMAL,                  /* file_attributes */
    675768                INTERNAL_OPEN_ONLY,                     /* oplock_request */
     769                NULL,                                   /* lease */
    676770                0,                                      /* private_flags */
    677771                0,                                      /* allocation_size */
     
    679773                NULL,                                   /* ea_list */
    680774                &fsp,                                   /* result */
    681                 NULL);                                  /* pinfo */
     775                NULL,                                   /* pinfo */
     776                NULL, NULL);                            /* create context */
    682777
    683778        if (!NT_STATUS_IS_OK(nt_status)) {
     
    687782                goto error_exit;
    688783        } else {
    689                 uint32 major;
    690                 uint32 minor;
     784                uint32_t major;
     785                uint32_t minor;
    691786                int    ret;
    692787
     
    745840                conn_free(conn);
    746841        }
    747         if (!NT_STATUS_IS_OK(*perr)) {
     842        if (!W_ERROR_IS_OK(*perr)) {
    748843                cversion = -1;
    749844        }
     
    763858
    764859static WERROR clean_up_driver_struct_level(TALLOC_CTX *mem_ctx,
    765                                            struct auth_serversupplied_info *session_info,
     860                                           struct auth_session_info *session_info,
    766861                                           const char *architecture,
    767862                                           const char **driver_path,
     
    836931
    837932WERROR clean_up_driver_struct(TALLOC_CTX *mem_ctx,
    838                               struct auth_serversupplied_info *session_info,
     933                              struct auth_session_info *session_info,
    839934                              struct spoolss_AddDriverInfoCtr *r)
    840935{
     
    9211016
    9221017                /* Setup a synthetic smb_filename struct */
    923                 smb_fname_new = TALLOC_ZERO_P(mem_ctx, struct smb_filename);
     1018                smb_fname_new = talloc_zero(mem_ctx, struct smb_filename);
    9241019                if (!smb_fname_new) {
    9251020                        ret = WERR_NOMEM;
     
    9551050}
    9561051
    957 WERROR move_driver_to_download_area(struct auth_serversupplied_info *session_info,
     1052WERROR move_driver_to_download_area(struct auth_session_info *session_info,
    9581053                                    struct spoolss_AddDriverInfoCtr *r)
    9591054{
     
    9991094        }
    10001095
    1001         nt_status = create_conn_struct(talloc_tos(), &conn, printdollar_snum,
    1002                                        lp_pathname(printdollar_snum),
    1003                                        session_info, &oldcwd);
     1096        nt_status = create_conn_struct_cwd(talloc_tos(),
     1097                                           server_event_context(),
     1098                                           server_messaging_context(),
     1099                                           &conn,
     1100                                           printdollar_snum,
     1101                                           lp_path(talloc_tos(), printdollar_snum),
     1102                                           session_info, &oldcwd);
    10041103        if (!NT_STATUS_IS_OK(nt_status)) {
    10051104                DEBUG(0,("move_driver_to_download_area: create_conn_struct "
     
    11751274
    11761275bool printer_driver_in_use(TALLOC_CTX *mem_ctx,
    1177                            const struct auth_serversupplied_info *session_info,
    1178                            struct messaging_context *msg_ctx,
    1179                            const struct spoolss_DriverInfo8 *r)
     1276                           struct dcerpc_binding_handle *b,
     1277                           const struct spoolss_DriverInfo8 *r)
    11801278{
    11811279        int snum;
     
    11841282        struct spoolss_PrinterInfo2 *pinfo2 = NULL;
    11851283        WERROR result;
    1186         struct dcerpc_binding_handle *b = NULL;
    11871284
    11881285        if (!r) {
     
    11951292
    11961293        for (snum=0; snum<n_services && !in_use; snum++) {
    1197                 if (!lp_snum_ok(snum) || !lp_print_ok(snum)) {
     1294                if (!lp_snum_ok(snum) || !lp_printable(snum)) {
    11981295                        continue;
    11991296                }
    12001297
    1201                 if (b == NULL) {
    1202                         result = winreg_printer_binding_handle(mem_ctx,
    1203                                                                session_info,
    1204                                                                msg_ctx,
    1205                                                                &b);
    1206                         if (!W_ERROR_IS_OK(result)) {
    1207                                 return false;
    1208                         }
    1209                 }
    1210 
    12111298                result = winreg_get_printer(mem_ctx, b,
    1212                                             lp_servicename(snum),
     1299                                            lp_servicename(talloc_tos(), snum),
    12131300                                            &pinfo2);
    12141301                if (!W_ERROR_IS_OK(result)) {
     
    12261313
    12271314        if ( in_use ) {
    1228                 struct spoolss_DriverInfo8 *driver;
     1315                struct spoolss_DriverInfo8 *driver = NULL;
    12291316                WERROR werr;
    12301317
     
    14141501
    14151502bool printer_driver_files_in_use(TALLOC_CTX *mem_ctx,
    1416                                  const struct auth_serversupplied_info *session_info,
    1417                                  struct messaging_context *msg_ctx,
     1503                                 struct dcerpc_binding_handle *b,
    14181504                                 struct spoolss_DriverInfo8 *info)
    14191505{
    14201506        int                             i;
    1421         uint32                          version;
     1507        uint32_t                                version;
    14221508        struct spoolss_DriverInfo8      *driver;
    14231509        bool in_use = false;
     
    14251511        const char **drivers;
    14261512        WERROR result;
    1427         struct dcerpc_binding_handle *b;
    14281513
    14291514        if ( !info )
     
    14371522
    14381523        /* get the list of drivers */
    1439 
    1440         result = winreg_printer_binding_handle(mem_ctx,
    1441                                                session_info,
    1442                                                msg_ctx,
    1443                                                &b);
    1444         if (!W_ERROR_IS_OK(result)) {
    1445                 return false;
    1446         }
    14471524
    14481525        result = winreg_get_driver_list(mem_ctx, b,
     
    15091586        }
    15101587
    1511         status = create_synthetic_smb_fname(tmp_ctx, print_dlr_path,
    1512                                             NULL, NULL, &smb_fname);
    1513         if (!NT_STATUS_IS_OK(status)) {
     1588        smb_fname = synthetic_smb_fname(tmp_ctx, print_dlr_path, NULL, NULL);
     1589        if (smb_fname == NULL) {
    15141590                goto err_out;
    15151591        }
     
    15271603****************************************************************************/
    15281604
    1529 bool delete_driver_files(const struct auth_serversupplied_info *session_info,
     1605bool delete_driver_files(const struct auth_session_info *session_info,
    15301606                         const struct spoolss_DriverInfo8 *r)
    15311607{
     
    15531629        }
    15541630
    1555         nt_status = create_conn_struct(talloc_tos(), &conn, printdollar_snum,
    1556                                        lp_pathname(printdollar_snum),
    1557                                        session_info, &oldcwd);
     1631        nt_status = create_conn_struct_cwd(talloc_tos(),
     1632                                           server_event_context(),
     1633                                           server_messaging_context(),
     1634                                           &conn,
     1635                                           printdollar_snum,
     1636                                           lp_path(talloc_tos(), printdollar_snum),
     1637                                           session_info, &oldcwd);
    15581638        if (!NT_STATUS_IS_OK(nt_status)) {
    15591639                DEBUG(0,("delete_driver_files: create_conn_struct "
     
    16371717        3: can't allocate memory
    16381718        4: can't free memory
    1639         5: non existant struct
     1719        5: non existent struct
    16401720*/
    16411721
     
    17151795
    17161796 ****************************************************************************/
    1717 bool print_access_check(const struct auth_serversupplied_info *session_info,
    1718                         struct messaging_context *msg_ctx, int snum,
    1719                         int access_type)
     1797WERROR print_access_check(const struct auth_session_info *session_info,
     1798                          struct messaging_context *msg_ctx, int snum,
     1799                          int access_type)
    17201800{
    17211801        struct spoolss_security_descriptor *secdesc = NULL;
    1722         uint32 access_granted;
     1802        uint32_t access_granted;
    17231803        size_t sd_size;
    17241804        NTSTATUS status;
     
    17311811        /* Always allow root or SE_PRINT_OPERATROR to do anything */
    17321812
    1733         if (session_info->utok.uid == sec_initial_uid()
    1734             || security_token_has_privilege(session_info->security_token, SEC_PRIV_PRINT_OPERATOR)) {
    1735                 return True;
     1813        if ((session_info->unix_token->uid == sec_initial_uid())
     1814            || security_token_has_privilege(session_info->security_token,
     1815                                            SEC_PRIV_PRINT_OPERATOR)) {
     1816                return WERR_OK;
    17361817        }
    17371818
    17381819        /* Get printer name */
    17391820
    1740         pname = lp_printername(snum);
     1821        pname = lp_printername(talloc_tos(), snum);
    17411822
    17421823        if (!pname || !*pname) {
    1743                 errno = EACCES;
    1744                 return False;
     1824                return WERR_ACCESS_DENIED;
    17451825        }
    17461826
     
    17481828
    17491829        if(!(mem_ctx = talloc_init("print_access_check"))) {
    1750                 errno = ENOMEM;
    1751                 return False;
     1830                return WERR_NOMEM;
    17521831        }
    17531832
     
    17591838        if (!W_ERROR_IS_OK(result)) {
    17601839                talloc_destroy(mem_ctx);
    1761                 errno = ENOMEM;
    1762                 return False;
     1840                return WERR_NOMEM;
    17631841        }
    17641842
     
    17781856                if (!NT_STATUS_IS_OK(status)) {
    17791857                        talloc_destroy(mem_ctx);
    1780                         errno = map_errno_from_nt_status(status);
    1781                         return False;
     1858                        return ntstatus_to_werror(status);
    17821859                }
    17831860
     
    17931870        DEBUG(4, ("access check was %s\n", NT_STATUS_IS_OK(status) ? "SUCCESS" : "FAILURE"));
    17941871
    1795         /* see if we need to try the printer admin list */
    1796 
    1797         if (!NT_STATUS_IS_OK(status) &&
    1798             (token_contains_name_in_list(uidtoname(session_info->utok.uid),
    1799                                          session_info->info3->base.domain.string,
    1800                                          NULL, session_info->security_token,
    1801                                          lp_printer_admin(snum)))) {
    1802                 talloc_destroy(mem_ctx);
    1803                 return True;
    1804         }
    1805 
    18061872        talloc_destroy(mem_ctx);
    18071873
    1808         if (!NT_STATUS_IS_OK(status)) {
    1809                 errno = EACCES;
    1810         }
    1811 
    1812         return NT_STATUS_IS_OK(status);
     1874        return ntstatus_to_werror(status);
    18131875}
    18141876
     
    18171879*****************************************************************************/
    18181880
    1819 bool print_time_access_check(const struct auth_serversupplied_info *session_info,
     1881bool print_time_access_check(const struct auth_session_info *session_info,
    18201882                             struct messaging_context *msg_ctx,
    18211883                             const char *servicename)
     
    18261888        time_t now = time(NULL);
    18271889        struct tm *t;
    1828         uint32 mins;
     1890        uint32_t mins;
    18291891
    18301892        result = winreg_get_printer_internal(NULL, session_info, msg_ctx,
     
    18391901
    18401902        t = gmtime(&now);
    1841         mins = (uint32)t->tm_hour*60 + (uint32)t->tm_min;
     1903        mins = (uint32_t)t->tm_hour*60 + (uint32_t)t->tm_min;
    18421904
    18431905        if (mins >= pinfo2->starttime && mins <= pinfo2->untiltime) {
     
    18551917
    18561918void nt_printer_remove(TALLOC_CTX *mem_ctx,
    1857                         const struct auth_serversupplied_info *session_info,
     1919                        const struct auth_session_info *session_info,
    18581920                        struct messaging_context *msg_ctx,
    18591921                        const char *printer)
     
    18651927        if (!W_ERROR_IS_OK(result)) {
    18661928                DEBUG(0, ("nt_printer_remove: failed to remove printer %s: "
    1867                           "%s\n", printer, win_errstr(result)));
     1929                "%s\n", printer, win_errstr(result)));
    18681930        }
    18691931}
    18701932
    18711933void nt_printer_add(TALLOC_CTX *mem_ctx,
    1872                     const struct auth_serversupplied_info *session_info,
     1934                    const struct auth_session_info *session_info,
    18731935                    struct messaging_context *msg_ctx,
    18741936                    const char *printer)
  • vendor/current/source3/printing/nt_printing_ads.c

    r860 r988  
    3636 ****************************************************************/
    3737
    38 static void store_printer_guid(struct messaging_context *msg_ctx,
    39                                const char *printer, struct GUID guid)
     38WERROR nt_printer_guid_store(struct messaging_context *msg_ctx,
     39                             const char *printer, struct GUID guid)
    4040{
    4141        TALLOC_CTX *tmp_ctx;
    42         struct auth_serversupplied_info *session_info = NULL;
     42        const struct auth_session_info *session_info;
    4343        const char *guid_str;
    4444        DATA_BLOB blob;
    45         NTSTATUS status;
    4645        WERROR result;
    4746
    4847        tmp_ctx = talloc_new(NULL);
    4948        if (!tmp_ctx) {
    50                 DEBUG(0, ("store_printer_guid: Out of memory?!\n"));
    51                 return;
    52         }
    53 
    54         status = make_session_info_system(tmp_ctx, &session_info);
    55         if (!NT_STATUS_IS_OK(status)) {
    56                 DEBUG(0, ("store_printer_guid: "
    57                           "Could not create system session_info\n"));
     49                DEBUG(0, ("Out of memory?!\n"));
     50                return WERR_NOMEM;
     51        }
     52
     53        session_info = get_session_info_system();
     54        if (session_info == NULL) {
     55                DEBUG(0, ("Could not get system session_info\n"));
     56                result = WERR_NOMEM;
    5857                goto done;
    5958        }
     
    6160        guid_str = GUID_string(tmp_ctx, &guid);
    6261        if (!guid_str) {
    63                 DEBUG(0, ("store_printer_guid: Out of memory?!\n"));
     62                DEBUG(0, ("Out of memory?!\n"));
     63                result = WERR_NOMEM;
    6464                goto done;
    6565        }
     
    6969
    7070        if (!push_reg_sz(tmp_ctx, &blob, guid_str)) {
    71                 DEBUG(0, ("store_printer_guid: "
    72                           "Could not marshall string %s for objectGUID\n",
     71                DEBUG(0, ("Could not marshall string %s for objectGUID\n",
    7372                          guid_str));
     73                result = WERR_NOMEM;
    7474                goto done;
    7575        }
     
    8080                                           REG_SZ, blob.data, blob.length);
    8181        if (!W_ERROR_IS_OK(result)) {
    82                 DEBUG(0, ("store_printer_guid: "
    83                           "Failed to store GUID for printer %s\n", printer));
    84         }
    85 
     82                DEBUG(0, ("Failed to store GUID for printer %s\n", printer));
     83                goto done;
     84        }
     85
     86        result = WERR_OK;
    8687done:
    8788        talloc_free(tmp_ctx);
     89
     90        return result;
     91}
     92
     93static WERROR nt_printer_dn_lookup(TALLOC_CTX *mem_ctx,
     94                                   ADS_STRUCT *ads,
     95                                   const char *printer,
     96                                   char **pprinter_dn)
     97{
     98        char *printer_dn = NULL;
     99        char *srv_dn = NULL;
     100        char *srv_cn_0 = NULL;
     101        char *srv_cn_escaped = NULL;
     102        char *sharename_escaped = NULL;
     103        char *srv_dn_utf8 = NULL;
     104        char **srv_cn_utf8 = NULL;
     105        size_t converted_size;
     106        ADS_STATUS ads_status;
     107        LDAPMessage *res;
     108        WERROR result;
     109        bool ok;
     110
     111        ads_status = ads_find_machine_acct(ads, &res, lp_netbios_name());
     112        if (!ADS_ERR_OK(ads_status)) {
     113                DEBUG(2, ("Failed to find machine account for %s\n",
     114                          lp_netbios_name()));
     115                result = WERR_NOT_FOUND;
     116                goto err_out;
     117        }
     118
     119        /*
     120         * We use ldap_get_dn here as we need the answer in utf8 to call
     121         * ldap_explode_dn(). JRA.
     122         */
     123        srv_dn_utf8 = ldap_get_dn((LDAP *)ads->ldap.ld, (LDAPMessage *)res);
     124        ads_msgfree(ads, res);
     125        if (srv_dn_utf8 == NULL) {
     126                result = WERR_SERVER_UNAVAILABLE;
     127                goto err_out;
     128        }
     129
     130        srv_cn_utf8 = ldap_explode_dn(srv_dn_utf8, 1);
     131        if (srv_cn_utf8 == NULL) {
     132                ldap_memfree(srv_dn_utf8);
     133                result = WERR_SERVER_UNAVAILABLE;
     134                goto err_out;
     135        }
     136
     137        /* Now convert to CH_UNIX. */
     138        ok = pull_utf8_talloc(mem_ctx, &srv_dn, srv_dn_utf8, &converted_size);
     139        ldap_memfree(srv_dn_utf8);
     140        if (!ok) {
     141                ldap_memfree(srv_cn_utf8);
     142                result = WERR_SERVER_UNAVAILABLE;
     143                goto err_out;
     144        }
     145
     146        ok = pull_utf8_talloc(mem_ctx, &srv_cn_0, srv_cn_utf8[0], &converted_size);
     147        ldap_memfree(srv_cn_utf8);
     148        if (!ok) {
     149                result = WERR_SERVER_UNAVAILABLE;
     150                goto err_out;
     151        }
     152
     153        srv_cn_escaped = escape_rdn_val_string_alloc(srv_cn_0);
     154        if (srv_cn_escaped == NULL) {
     155                result = WERR_SERVER_UNAVAILABLE;
     156                goto err_out;
     157        }
     158
     159        sharename_escaped = escape_rdn_val_string_alloc(printer);
     160        if (sharename_escaped == NULL) {
     161                result = WERR_SERVER_UNAVAILABLE;
     162                goto err_out;
     163        }
     164
     165        printer_dn = talloc_asprintf(mem_ctx,
     166                                     "cn=%s-%s,%s",
     167                                     srv_cn_escaped,
     168                                     sharename_escaped,
     169                                     srv_dn);
     170        if (printer_dn == NULL) {
     171                result = WERR_NOMEM;
     172                goto err_out;
     173        }
     174
     175        *pprinter_dn = printer_dn;
     176
     177        result = WERR_OK;
     178err_out:
     179        SAFE_FREE(sharename_escaped);
     180        SAFE_FREE(srv_cn_escaped);
     181        TALLOC_FREE(srv_cn_0);
     182        TALLOC_FREE(srv_dn);
     183        return result;
     184}
     185
     186static WERROR nt_printer_guid_retrieve_internal(ADS_STRUCT *ads,
     187                                                const char *printer_dn,
     188                                                struct GUID *pguid)
     189{
     190        ADS_STATUS ads_status;
     191        LDAPMessage *res;
     192        const char *attrs[] = {"objectGUID", NULL};
     193        struct GUID guid;
     194        bool ok;
     195
     196        ads_status = ads_search_dn(ads, &res, printer_dn, attrs);
     197        if (!ADS_ERR_OK(ads_status)) {
     198                DEBUG(2, ("Failed to retrieve GUID from DC - %s\n",
     199                          ads_errstr(ads_status)));
     200                return WERR_BADFILE;
     201        }
     202
     203        ZERO_STRUCT(guid);
     204        ok = ads_pull_guid(ads, res, &guid);
     205        ads_msgfree(ads, res);
     206        if (!ok) {
     207                return WERR_NOMEM;
     208        }
     209
     210        *pguid = guid;
     211
     212        return WERR_OK;
     213}
     214
     215WERROR nt_printer_guid_retrieve(TALLOC_CTX *mem_ctx, const char *printer,
     216                                struct GUID *pguid)
     217{
     218        ADS_STRUCT *ads = NULL;
     219        char *old_krb5ccname = NULL;
     220        char *printer_dn;
     221        WERROR result;
     222        ADS_STATUS ads_status;
     223        TALLOC_CTX *tmp_ctx;
     224
     225        tmp_ctx = talloc_new(mem_ctx);
     226        if (tmp_ctx == NULL) {
     227                return WERR_NOMEM;
     228        }
     229
     230        ads = ads_init(lp_realm(), lp_workgroup(), NULL);
     231        if (ads == NULL) {
     232                result = WERR_SERVER_UNAVAILABLE;
     233                goto out;
     234        }
     235
     236        old_krb5ccname = getenv(KRB5_ENV_CCNAME);
     237        setenv(KRB5_ENV_CCNAME, "MEMORY:prtpub_cache", 1);
     238        SAFE_FREE(ads->auth.password);
     239        ads->auth.password = secrets_fetch_machine_password(lp_workgroup(),
     240                                                            NULL, NULL);
     241
     242        ads_status = ads_connect(ads);
     243        if (!ADS_ERR_OK(ads_status)) {
     244                DEBUG(3, ("ads_connect failed: %s\n", ads_errstr(ads_status)));
     245                result = WERR_ACCESS_DENIED;
     246                goto out;
     247        }
     248
     249        result = nt_printer_dn_lookup(tmp_ctx, ads, printer, &printer_dn);
     250        if (!W_ERROR_IS_OK(result)) {
     251                goto out;
     252        }
     253
     254        result = nt_printer_guid_retrieve_internal(ads, printer_dn, pguid);
     255out:
     256        TALLOC_FREE(tmp_ctx);
     257        ads_destroy(&ads);
     258        ads_kdestroy("MEMORY:prtpub_cache");
     259        unsetenv(KRB5_ENV_CCNAME);
     260        if (old_krb5ccname != NULL) {
     261                setenv(KRB5_ENV_CCNAME, old_krb5ccname, 0);
     262        }
     263
     264        return result;
    88265}
    89266
    90267WERROR nt_printer_guid_get(TALLOC_CTX *mem_ctx,
    91                            const struct auth_serversupplied_info *session_info,
     268                           const struct auth_session_info *session_info,
    92269                           struct messaging_context *msg_ctx,
    93270                           const char *printer, struct GUID *guid)
     
    169346
    170347        ads_mod_str(ctx, mods, SPOOL_REG_PRINTERNAME, info2->sharename);
    171         ads_mod_str(ctx, mods, SPOOL_REG_SHORTSERVERNAME, global_myname());
     348        ads_mod_str(ctx, mods, SPOOL_REG_SHORTSERVERNAME, lp_netbios_name());
    172349        ads_mod_str(ctx, mods, SPOOL_REG_SERVERNAME, get_mydnsfullname());
    173350
     
    247424{
    248425        ADS_STATUS ads_rc;
    249         LDAPMessage *res;
    250         char *prt_dn = NULL, *srv_dn, *srv_cn_0, *srv_cn_escaped, *sharename_escaped;
    251         char *srv_dn_utf8, **srv_cn_utf8;
    252426        TALLOC_CTX *ctx;
    253427        ADS_MODLIST mods;
    254         const char *attrs[] = {"objectGUID", NULL};
    255428        struct GUID guid;
    256429        WERROR win_rc = WERR_OK;
    257         size_t converted_size;
    258430        const char *printer = pinfo2->sharename;
     431        char *printer_dn = NULL;
    259432
    260433        /* build the ads mods */
     
    266439        DEBUG(5, ("publishing printer %s\n", printer));
    267440
    268         /* figure out where to publish */
    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()));
     441        win_rc = nt_printer_dn_lookup(ctx, ads, printer, &printer_dn);
     442        if (!W_ERROR_IS_OK(win_rc)) {
     443                DEBUG(2, ("Failed to create printer dn\n"));
    273444                TALLOC_FREE(ctx);
    274                 return WERR_NOT_FOUND;
    275         }
    276 
    277         /* We use ldap_get_dn here as we need the answer
    278          * in utf8 to call ldap_explode_dn(). JRA. */
    279 
    280         srv_dn_utf8 = ldap_get_dn((LDAP *)ads->ldap.ld, (LDAPMessage *)res);
    281         ads_msgfree(ads, res);
    282         if (!srv_dn_utf8) {
    283                 TALLOC_FREE(ctx);
    284                 return WERR_SERVER_UNAVAILABLE;
    285         }
    286         srv_cn_utf8 = ldap_explode_dn(srv_dn_utf8, 1);
    287         if (!srv_cn_utf8) {
    288                 TALLOC_FREE(ctx);
    289                 ldap_memfree(srv_dn_utf8);
    290                 return WERR_SERVER_UNAVAILABLE;
    291         }
    292         /* Now convert to CH_UNIX. */
    293         if (!pull_utf8_talloc(ctx, &srv_dn, srv_dn_utf8, &converted_size)) {
    294                 TALLOC_FREE(ctx);
    295                 ldap_memfree(srv_dn_utf8);
    296                 ldap_memfree(srv_cn_utf8);
    297                 return WERR_SERVER_UNAVAILABLE;
    298         }
    299         if (!pull_utf8_talloc(ctx, &srv_cn_0, srv_cn_utf8[0], &converted_size)) {
    300                 TALLOC_FREE(ctx);
    301                 ldap_memfree(srv_dn_utf8);
    302                 ldap_memfree(srv_cn_utf8);
    303                 TALLOC_FREE(srv_dn);
    304                 return WERR_SERVER_UNAVAILABLE;
    305         }
    306 
    307         ldap_memfree(srv_dn_utf8);
    308         ldap_memfree(srv_cn_utf8);
    309 
    310         srv_cn_escaped = escape_rdn_val_string_alloc(srv_cn_0);
    311         if (!srv_cn_escaped) {
    312                 TALLOC_FREE(ctx);
    313                 return WERR_SERVER_UNAVAILABLE;
    314         }
    315         sharename_escaped = escape_rdn_val_string_alloc(printer);
    316         if (!sharename_escaped) {
    317                 SAFE_FREE(srv_cn_escaped);
    318                 TALLOC_FREE(ctx);
    319                 return WERR_SERVER_UNAVAILABLE;
    320         }
    321 
    322         prt_dn = talloc_asprintf(ctx, "cn=%s-%s,%s", srv_cn_escaped, sharename_escaped, srv_dn);
    323 
    324         SAFE_FREE(srv_cn_escaped);
    325         SAFE_FREE(sharename_escaped);
     445                return win_rc;
     446        }
    326447
    327448        mods = ads_init_mods(ctx);
     
    339460
    340461        /* publish it */
    341         ads_rc = ads_mod_printer_entry(ads, prt_dn, ctx, &mods);
     462        ads_rc = ads_mod_printer_entry(ads, printer_dn, ctx, &mods);
    342463        if (ads_rc.err.rc == LDAP_NO_SUCH_OBJECT) {
    343464                int i;
     
    345466                        ;
    346467                mods[i] = (LDAPMod *)-1;
    347                 ads_rc = ads_add_printer_entry(ads, prt_dn, ctx, &mods);
     468                ads_rc = ads_add_printer_entry(ads, printer_dn, ctx, &mods);
    348469        }
    349470
     
    351472                DEBUG(3, ("error publishing %s: %s\n",
    352473                          printer, ads_errstr(ads_rc)));
    353         }
    354 
    355         /* retreive the guid and store it locally */
    356         if (ADS_ERR_OK(ads_search_dn(ads, &res, prt_dn, attrs))) {
    357                 bool guid_ok;
    358                 ZERO_STRUCT(guid);
    359                 guid_ok = ads_pull_guid(ads, res, &guid);
    360                 ads_msgfree(ads, res);
    361                 if (guid_ok) {
    362                         store_printer_guid(msg_ctx, printer, guid);
    363                 }
    364         }
     474                /* XXX failed to publish, so no guid to retrieve */
     475        }
     476
     477        win_rc = nt_printer_guid_retrieve_internal(ads, printer_dn, &guid);
     478        if (!W_ERROR_IS_OK(win_rc)) {
     479                TALLOC_FREE(ctx);
     480                return win_rc;
     481        }
     482
     483        win_rc = nt_printer_guid_store(msg_ctx, printer, guid);
     484        if (!W_ERROR_IS_OK(win_rc)) {
     485                DEBUG(3, ("failed to store printer %s guid\n",
     486                          printer));
     487                /* not catastrophic, retrieve on next use */
     488                win_rc = WERR_OK;
     489        }
     490
    365491        TALLOC_FREE(ctx);
    366492
     
    379505        /* remove the printer from the directory */
    380506        ads_rc = ads_find_printer_on_server(ads, &res,
    381                                             printer, global_myname());
     507                                            printer, lp_netbios_name());
    382508
    383509        if (ADS_ERR_OK(ads_rc) && res && ads_count_replies(ads, res)) {
     
    408534
    409535WERROR nt_printer_publish(TALLOC_CTX *mem_ctx,
    410                           const struct auth_serversupplied_info *session_info,
     536                          const struct auth_session_info *session_info,
    411537                          struct messaging_context *msg_ctx,
    412538                          struct spoolss_PrinterInfo2 *pinfo2,
     
    418544        ADS_STRUCT *ads = NULL;
    419545        WERROR win_rc;
     546        char *old_krb5ccname = NULL;
    420547
    421548        sinfo2 = talloc_zero(mem_ctx, struct spoolss_SetPrinterInfo2);
     
    455582                goto done;
    456583        }
     584        old_krb5ccname = getenv(KRB5_ENV_CCNAME);
    457585        setenv(KRB5_ENV_CCNAME, "MEMORY:prtpub_cache", 1);
    458586        SAFE_FREE(ads->auth.password);
     
    480608done:
    481609        ads_destroy(&ads);
     610        ads_kdestroy("MEMORY:prtpub_cache");
     611        unsetenv(KRB5_ENV_CCNAME);
     612        if (old_krb5ccname) {
     613                setenv(KRB5_ENV_CCNAME, old_krb5ccname, 0);
     614        }
    482615        return win_rc;
    483616}
     
    490623        int n_services = lp_numservices();
    491624        TALLOC_CTX *tmp_ctx = NULL;
    492         struct auth_serversupplied_info *session_info = NULL;
     625        struct auth_session_info *session_info = NULL;
    493626        struct spoolss_PrinterInfo2 *pinfo2;
    494627        NTSTATUS status;
    495628        WERROR result;
     629        char *old_krb5ccname = NULL;
    496630
    497631        tmp_ctx = talloc_new(NULL);
     
    503637                return WERR_SERVER_UNAVAILABLE;
    504638        }
     639        old_krb5ccname = getenv(KRB5_ENV_CCNAME);
    505640        setenv(KRB5_ENV_CCNAME, "MEMORY:prtpub_cache", 1);
    506641        SAFE_FREE(ads->auth.password);
     
    525660
    526661        for (snum = 0; snum < n_services; snum++) {
    527                 if (!lp_snum_ok(snum) || !lp_print_ok(snum)) {
     662                if (!lp_snum_ok(snum) || !lp_printable(snum)) {
    528663                        continue;
    529664                }
    530665
    531666                result = winreg_get_printer_internal(tmp_ctx, session_info, msg_ctx,
    532                                             lp_servicename(snum),
     667                                            lp_servicename(talloc_tos(), snum),
    533668                                            &pinfo2);
    534669                if (!W_ERROR_IS_OK(result)) {
     
    547682        ads_destroy(&ads);
    548683        ads_kdestroy("MEMORY:prtpub_cache");
     684        unsetenv(KRB5_ENV_CCNAME);
     685        if (old_krb5ccname) {
     686                setenv(KRB5_ENV_CCNAME, old_krb5ccname, 0);
     687        }
    549688        talloc_free(tmp_ctx);
    550689        return result;
     
    552691
    553692bool is_printer_published(TALLOC_CTX *mem_ctx,
    554                           const struct auth_serversupplied_info *session_info,
     693                          const struct auth_session_info *session_info,
    555694                          struct messaging_context *msg_ctx,
    556695                          const char *servername,
     
    588727}
    589728#else
     729WERROR nt_printer_guid_store(struct messaging_context *msg_ctx,
     730                           const char *printer, struct GUID guid)
     731{
     732        return WERR_NOT_SUPPORTED;
     733}
     734
     735WERROR nt_printer_guid_retrieve(TALLOC_CTX *mem_ctx, const char *printer,
     736                                struct GUID *pguid)
     737{
     738        return WERR_NOT_SUPPORTED;
     739}
     740
    590741WERROR nt_printer_guid_get(TALLOC_CTX *mem_ctx,
    591                            const struct auth_serversupplied_info *session_info,
     742                           const struct auth_session_info *session_info,
    592743                           struct messaging_context *msg_ctx,
    593744                           const char *printer, struct GUID *guid)
     
    597748
    598749WERROR nt_printer_publish(TALLOC_CTX *mem_ctx,
    599                           const struct auth_serversupplied_info *session_info,
     750                          const struct auth_session_info *session_info,
    600751                          struct messaging_context *msg_ctx,
    601752                          struct spoolss_PrinterInfo2 *pinfo2,
     
    611762
    612763bool is_printer_published(TALLOC_CTX *mem_ctx,
    613                           const struct auth_serversupplied_info *session_info,
     764                          const struct auth_session_info *session_info,
    614765                          struct messaging_context *msg_ctx,
    615766                          const char *servername,
  • vendor/current/source3/printing/nt_printing_migrate.c

    r860 r988  
    44 *
    55 *  Copyright (c) Andreas Schneider            2010.
    6  *  Copyright (C) Bjoern Baumbach <bb@sernet.de> 2011
    76 *
    87 *  This program is free software; you can redistribute it and/or modify
     
    2827#include "librpc/gen_ndr/ndr_security.h"
    2928#include "rpc_client/cli_winreg_spoolss.h"
    30 
    31 static const char *driver_file_basename(const char *file)
    32 {
    33         const char *basefile;
    34 
    35         basefile = strrchr(file, '\\');
    36         if (basefile == NULL) {
    37                 basefile = file;
    38         } else {
    39                 basefile++;
    40         }
    41 
    42         return basefile;
    43 }
    4429
    4530NTSTATUS printing_tdb_migrate_form(TALLOC_CTX *mem_ctx,
     
    117102        const char *driver_name;
    118103        uint32_t driver_version;
    119         int i;
    120104
    121105        blob = data_blob_const(data, length);
     
    140124        ZERO_STRUCT(a);
    141125
    142         /* remove paths from file names */
    143         if (r.dependent_files != NULL) {
    144                 for (i = 0 ; r.dependent_files[i] != NULL; i++) {
    145                         r.dependent_files[i] = driver_file_basename(r.dependent_files[i]);
    146                 }
    147         }
    148126        a.string = r.dependent_files;
    149 
    150         r.driverpath = driver_file_basename(r.driverpath);
    151         r.configfile = driver_file_basename(r.configfile);
    152         r.datafile = driver_file_basename(r.datafile);
    153         r.helpfile = driver_file_basename(r.helpfile);
    154127
    155128        d3.architecture = r.environment;
     
    290263
    291264                devmode_ctr.devmode = &dm;
    292 
    293                 info2.devmode_ptr = 1;
    294265        }
    295266
     
    310281        for (j = 0; j < r.count; j++) {
    311282                char *valuename;
    312                 char *keyname;
     283                const char *keyname;
    313284
    314285                if (r.printer_data[j].type == REG_NONE) {
     
    316287                }
    317288
    318                 keyname = CONST_DISCARD(char *, r.printer_data[j].name);
     289                keyname = r.printer_data[j].name;
    319290                valuename = strchr(keyname, '\\');
    320291                if (valuename == NULL) {
  • vendor/current/source3/printing/nt_printing_migrate_internal.c

    r860 r988  
    187187bool nt_printing_tdb_migrate(struct messaging_context *msg_ctx)
    188188{
    189         const char *drivers_path = state_path("ntdrivers.tdb");
    190         const char *printers_path = state_path("ntprinters.tdb");
    191         const char *forms_path = state_path("ntforms.tdb");
    192         bool drivers_exists = file_exist(drivers_path);
    193         bool printers_exists = file_exist(printers_path);
    194         bool forms_exists = file_exist(forms_path);
    195         struct auth_serversupplied_info *session_info;
     189        const char *drivers_path;
     190        const char *printers_path;
     191        const char *forms_path;
     192        bool drivers_exists;
     193        bool printers_exists;
     194        bool forms_exists;
     195        struct auth_session_info *session_info;
    196196        struct rpc_pipe_client *winreg_pipe = NULL;
    197197        TALLOC_CTX *tmp_ctx = talloc_stackframe();
    198198        NTSTATUS status;
    199199
     200        /* paths talloced on new stackframe */
     201        drivers_path = state_path("ntdrivers.tdb");
     202        printers_path = state_path("ntprinters.tdb");
     203        forms_path = state_path("ntforms.tdb");
     204        if ((drivers_path == NULL) || (printers_path == NULL)
     205                                                || (forms_path == NULL)) {
     206                talloc_free(tmp_ctx);
     207                return false;
     208        }
     209        drivers_exists = file_exist(drivers_path);
     210        printers_exists = file_exist(printers_path);
     211        forms_exists = file_exist(forms_path);
     212
    200213        if (!drivers_exists && !printers_exists && !forms_exists) {
     214                talloc_free(tmp_ctx);
    201215                return true;
    202216        }
     
    211225
    212226        status = rpc_pipe_open_interface(tmp_ctx,
    213                                         &ndr_table_winreg.syntax_id,
     227                                        &ndr_table_winreg,
    214228                                        session_info,
    215229                                        NULL,
  • vendor/current/source3/printing/nt_printing_os2.c

    r740 r988  
    7474WERROR spoolss_map_to_os2_driver(TALLOC_CTX *mem_ctx, const char **pdrivername)
    7575{
    76         const char *mapfile = lp_os2_driver_map();
     76        const char *mapfile = lp_os2_driver_map(talloc_tos());
    7777        char **lines = NULL;
    7878        const char *drivername;
  • vendor/current/source3/printing/nt_printing_tdb.c

    r740 r988  
    5555
    5656        fstrcpy(share, sharename);
    57         strlower_m(share);
     57        (void)strlower_m(share);
    5858
    5959        keystr = talloc_asprintf(ctx, "%s%s", PRINTERS_PREFIX, share);
     
    7575
    7676        fstrcpy(share, sharename );
    77         strlower_m(share);
     77        (void)strlower_m(share);
    7878
    7979        keystr = talloc_asprintf(ctx, "%s%s", SECDESC_PREFIX, share);
     
    9494
    9595        for (kbuf = tdb_firstkey(tdb_drivers); kbuf.dptr;
    96                         newkey = tdb_nextkey(tdb_drivers, kbuf), free(kbuf.dptr), kbuf=newkey) {
     96             newkey = tdb_nextkey(tdb_drivers, kbuf), free(kbuf.dptr), kbuf=newkey) {
    9797
    9898                dbuf = tdb_fetch(tdb_drivers, kbuf);
     
    163163        TALLOC_CTX *ctx = state;
    164164        int result, i;
    165         uint32 sd_size;
    166165        size_t size_new_sec;
    167166
     
    237236        /* store it back */
    238237
    239         sd_size = ndr_size_security_descriptor(sd_store->sd, 0)
    240                 + sizeof(struct sec_desc_buf);
    241 
    242238        status = marshall_sec_desc_buf(ctx, sd_store, &data.dptr, &data.dsize);
    243239        if (!NT_STATUS_IS_OK(status)) {
     
    250246        /* 0 to continue and non-zero to stop traversal */
    251247
    252         return (result == -1);
     248        return (result != 0);
    253249}
    254250
     
    271267        talloc_destroy( ctx );
    272268
    273         return ( result != -1 );
     269        return ( result >= 0 );
    274270}
    275271
     
    339335        talloc_destroy( ctx );
    340336
    341         return ( result != -1 );
     337        return ( result >= 0 );
    342338}
    343339
    344340bool nt_printing_tdb_upgrade(void)
    345341{
    346         const char *drivers_path = state_path("ntdrivers.tdb");
    347         const char *printers_path = state_path("ntprinters.tdb");
    348         const char *forms_path = state_path("ntforms.tdb");
    349         bool drivers_exists = file_exist(drivers_path);
    350         bool printers_exists = file_exist(printers_path);
    351         bool forms_exists = file_exist(forms_path);
     342        char *drivers_path;
     343        char *printers_path;
     344        char *forms_path;
     345        bool drivers_exists;
     346        bool printers_exists;
     347        bool forms_exists;
    352348        const char *vstring = "INFO/version";
    353349        int32_t vers_id;
     350        bool ret;
     351
     352        drivers_path = state_path("ntdrivers.tdb");
     353        if (drivers_path == NULL) {
     354                ret = false;
     355                goto err_out;
     356        }
     357        printers_path = state_path("ntprinters.tdb");
     358        if (printers_path == NULL) {
     359                ret = false;
     360                goto err_drvdb_free;
     361        }
     362        forms_path = state_path("ntforms.tdb");
     363        if (forms_path == NULL) {
     364                ret = false;
     365                goto err_prdb_free;
     366        }
     367
     368        drivers_exists = file_exist(drivers_path);
     369        printers_exists = file_exist(printers_path);
     370        forms_exists = file_exist(forms_path);
    354371
    355372        if (!drivers_exists && !printers_exists && !forms_exists) {
    356                 return true;
     373                ret = true;
     374                goto err_formsdb_free;
    357375        }
    358376
     
    366384                         "database %s (%s)\n",
    367385                         drivers_path, strerror(errno)));
    368                 return false;
     386                ret = false;
     387                goto err_formsdb_free;
    369388        }
    370389
     
    378397                         "database %s (%s)\n",
    379398                         printers_path, strerror(errno)));
    380                 return false;
     399                ret = false;
     400                goto err_drvdb_close;
    381401        }
    382402
     
    390410                         "database %s (%s)\n",
    391411                         forms_path, strerror(errno)));
    392                 return false;
     412                ret = false;
     413                goto err_prdb_close;
    393414        }
    394415
     
    405426                    (IREV(vers_id) == NTDRIVERS_DATABASE_VERSION_1)) {
    406427                        if (!upgrade_to_version_3()) {
    407                                 return false;
     428                                ret = false;
     429                                goto err_formsdb_close;
    408430                        }
    409431
     
    425447                if (vers_id == NTDRIVERS_DATABASE_VERSION_3) {
    426448                        if (!upgrade_to_version_4()) {
    427                                 return false;
     449                                ret = false;
     450                                goto err_formsdb_close;
    428451                        }
    429452                        tdb_store_int32(tdb_drivers, vstring, NTDRIVERS_DATABASE_VERSION_4);
     
    433456                if (vers_id == NTDRIVERS_DATABASE_VERSION_4 ) {
    434457                        if (!upgrade_to_version_5()) {
    435                                 return false;
     458                                ret = false;
     459                                goto err_formsdb_close;
    436460                        }
    437461                        tdb_store_int32(tdb_drivers, vstring, NTDRIVERS_DATABASE_VERSION_5);
     
    441465                if (vers_id != NTDRIVERS_DATABASE_VERSION_5) {
    442466                        DEBUG(0,("nt_printing_init: Unknown printer database version [%d]\n", vers_id));
    443                         return false;
    444                 }
    445         }
    446 
     467                        ret = false;
     468                        goto err_formsdb_close;
     469                }
     470        }
     471        ret = true;
     472
     473err_formsdb_close:
     474        if (tdb_forms) {
     475                tdb_close(tdb_forms);
     476                tdb_forms = NULL;
     477        }
     478err_prdb_close:
     479        if (tdb_printers) {
     480                tdb_close(tdb_printers);
     481                tdb_printers = NULL;
     482        }
     483err_drvdb_close:
    447484        if (tdb_drivers) {
    448485                tdb_close(tdb_drivers);
    449486                tdb_drivers = NULL;
    450487        }
    451 
    452         if (tdb_printers) {
    453                 tdb_close(tdb_printers);
    454                 tdb_printers = NULL;
    455         }
    456 
    457         if (tdb_forms) {
    458                 tdb_close(tdb_forms);
    459                 tdb_forms = NULL;
    460         }
    461 
    462         return true;
    463 }
     488err_formsdb_free:
     489        talloc_free(forms_path);
     490err_prdb_free:
     491        talloc_free(printers_path);
     492err_drvdb_free:
     493        talloc_free(drivers_path);
     494err_out:
     495        return ret;
     496}
  • vendor/current/source3/printing/pcap.c

    r740 r988  
    8484}
    8585
    86 bool pcap_cache_add(const char *name, const char *comment, const char *location)
    87 {
     86bool pcap_cache_loaded(time_t *_last_change)
     87{
     88        NTSTATUS status;
     89        time_t last;
     90
     91        status = printer_list_get_last_refresh(&last);
     92        if (!NT_STATUS_IS_OK(status)) {
     93                return false;
     94        }
     95        if (_last_change != NULL) {
     96                *_last_change = last;
     97        }
     98        return true;
     99}
     100
     101bool pcap_cache_replace(const struct pcap_cache *pcache)
     102{
     103        const struct pcap_cache *p;
    88104        NTSTATUS status;
    89105        time_t t = time_mono(NULL);
    90106
    91         status = printer_list_set_printer(talloc_tos(), name, comment, location, t);
    92         return NT_STATUS_IS_OK(status);
    93 }
    94 
    95 bool pcap_cache_loaded(void)
    96 {
    97         NTSTATUS status;
    98         time_t last;
    99 
    100         status = printer_list_get_last_refresh(&last);
    101         return NT_STATUS_IS_OK(status);
    102 }
    103 
    104 bool pcap_cache_replace(const struct pcap_cache *pcache)
    105 {
    106         const struct pcap_cache *p;
    107         NTSTATUS status;
    108 
    109107        status = printer_list_mark_reload();
    110108        if (!NT_STATUS_IS_OK(status)) {
     
    114112
    115113        for (p = pcache; p; p = p->next) {
    116                 pcap_cache_add(p->name, p->comment, p->location);
     114                status = printer_list_set_printer(talloc_tos(), p->name,
     115                                                  p->comment, p->location, t);
     116                if (!NT_STATUS_IS_OK(status)) {
     117                        return false;
     118                }
    117119        }
    118120
     
    133135        const char *pcap_name = lp_printcapname();
    134136        bool pcap_reloaded = False;
    135         NTSTATUS status;
    136137        bool post_cache_fill_fn_handled = false;
     138        struct pcap_cache *pcache = NULL;
    137139
    138140        DEBUG(3, ("reloading printcap cache\n"));
     
    141143        if (pcap_name == NULL || *pcap_name == 0) {
    142144                DEBUG(0, ("No printcap file name configured!\n"));
    143                 return;
    144         }
    145 
    146         status = printer_list_mark_reload();
    147         if (!NT_STATUS_IS_OK(status)) {
    148                 DEBUG(0, ("Failed to mark printer list for reload!\n"));
    149145                return;
    150146        }
     
    165161#ifdef HAVE_IPRINT
    166162        if (strequal(pcap_name, "iprint")) {
    167                 pcap_reloaded = iprint_cache_reload();
     163                pcap_reloaded = iprint_cache_reload(&pcache);
    168164                goto done;
    169165        }
     
    172168#if defined(SYSV) || defined(HPUX)
    173169        if (strequal(pcap_name, "lpstat")) {
    174                 pcap_reloaded = sysv_cache_reload();
     170                pcap_reloaded = sysv_cache_reload(&pcache);
    175171                goto done;
    176172        }
     
    179175#ifdef AIX
    180176        if (strstr_m(pcap_name, "/qconfig") != NULL) {
    181                 pcap_reloaded = aix_cache_reload();
    182                 goto done;
    183         }
    184 #endif
    185 
    186         pcap_reloaded = std_pcap_cache_reload(pcap_name);
    187 
     177                pcap_reloaded = aix_cache_reload(&pcache);
     178                goto done;
     179        }
     180#endif
     181
     182        pcap_reloaded = std_pcap_cache_reload(pcap_name, &pcache);
     183
     184/* Fix silly compiler warning about done not being used if none of the above
     185 * ifdefs are used */
     186#if defined(HAVE_CUPS) || defined(HAVE_IPRINT) || defined(SYSV) || defined(HPUX) || defined(AIX)
    188187done:
     188#endif
    189189        DEBUG(3, ("reload status: %s\n", (pcap_reloaded) ? "ok" : "error"));
    190190
     
    192192                /* cleanup old entries only if the operation was successful,
    193193                 * otherwise keep around the old entries until we can
    194                  * successfuly reaload */
    195                 status = printer_list_clean_old();
    196                 if (!NT_STATUS_IS_OK(status)) {
    197                         DEBUG(0, ("Failed to cleanup printer list!\n"));
     194                 * successfully reload */
     195
     196                if (!pcap_cache_replace(pcache)) {
     197                        DEBUG(0, ("Failed to replace printer list!\n"));
    198198                }
     199
    199200                if (post_cache_fill_fn != NULL) {
    200201                        post_cache_fill_fn(ev, msg_ctx);
    201202                }
    202203        }
     204        pcap_cache_destroy_specific(&pcache);
    203205
    204206        return;
     
    230232}
    231233
    232 void pcap_printer_fn(void (*fn)(const char *, const char *, const char *, void *), void *pdata)
    233 {
    234         NTSTATUS status;
    235 
    236         status = printer_list_run_fn(fn, pdata);
     234void pcap_printer_read_fn(void (*fn)(const char *, const char *, const char *, void *), void *pdata)
     235{
     236        NTSTATUS status;
     237
     238        status = printer_list_read_run_fn(fn, pdata);
    237239        if (!NT_STATUS_IS_OK(status)) {
    238240                DEBUG(3, ("Failed to run fn for all printers!\n"));
  • vendor/current/source3/printing/pcap.h

    r740 r988  
    3636bool pcap_cache_add_specific(struct pcap_cache **ppcache, const char *name, const char *comment, const char *location);
    3737void pcap_cache_destroy_specific(struct pcap_cache **ppcache);
    38 bool pcap_cache_add(const char *name, const char *comment, const char *location);
    39 bool pcap_cache_loaded(void);
     38bool pcap_cache_loaded(time_t *_last_change);
    4039bool pcap_cache_replace(const struct pcap_cache *cache);
    4140void pcap_printer_fn_specific(const struct pcap_cache *, void (*fn)(const char *, const char *, const char *, void *), void *);
    42 void pcap_printer_fn(void (*fn)(const char *, const char *, const char *, void *), void *);
     41void pcap_printer_read_fn(void (*fn)(const char *, const char *, const char *, void *), void *);
    4342
    4443void pcap_cache_reload(struct tevent_context *ev,
     
    5049/* The following definitions come from printing/print_aix.c  */
    5150
    52 bool aix_cache_reload(void);
     51bool aix_cache_reload(struct pcap_cache **_pcache);
    5352
    5453/* The following definitions come from printing/print_cups.c  */
     
    6160/* The following definitions come from printing/print_iprint.c  */
    6261
    63 bool iprint_cache_reload(void);
     62bool iprint_cache_reload(struct pcap_cache **_pcache);
    6463
    6564/* The following definitions come from printing/print_svid.c  */
    6665
    67 bool sysv_cache_reload(void);
     66bool sysv_cache_reload(struct pcap_cache **_pcache);
    6867
    6968/* The following definitions come from printing/print_standard.c  */
    70 bool std_pcap_cache_reload(const char *pcap_name);
     69bool std_pcap_cache_reload(const char *pcap_name, struct pcap_cache **_pcache);
    7170
    7271#endif /* _PRINTING_PCAP_H_ */
  • vendor/current/source3/printing/print_aix.c

    r740 r988  
    3030
    3131#ifdef AIX
    32 bool aix_cache_reload(void)
     32bool aix_cache_reload(struct pcap_cache **_pcache)
    3333{
    3434        int iEtat;
     
    3636        char *line = NULL, *p;
    3737        char *name = NULL;
     38        struct pcap_cache *pcache = NULL;
    3839        TALLOC_CTX *ctx = talloc_init("aix_cache_reload");
    3940
     
    5354        /* scan qconfig file for searching <printername>:       */
    5455        for (;(line = fgets_slash(NULL, 1024, pfile)); free(line)) {
     56                bool ok;
     57
    5558                if (*line == '*' || *line == 0)
    5659                        continue;
     
    6871                                        name = talloc_strdup(ctx, p);
    6972                                        if (!name) {
     73                                                pcap_cache_destroy_specific(&pcache);
    7074                                                SAFE_FREE(line);
    7175                                                x_fclose(pfile);
     
    8791                                /* probably a good printer ???          */
    8892                                iEtat = 0;
    89                                 if (!pcap_cache_add(name, NULL, NULL)) {
     93                                ok = pcap_cache_add_specific(&pcache,
     94                                                             name, NULL, NULL);
     95                                if (!ok) {
     96                                        pcap_cache_destroy_specific(&pcache);
    9097                                        SAFE_FREE(line);
    9198                                        x_fclose(pfile);
     
    102109                                /* it's a good virtual printer */
    103110                                iEtat = 0;
    104                                 if (!pcap_cache_add(name, NULL, NULL)) {
     111                                ok = pcap_cache_add_specific(&pcache,
     112                                                             name, NULL, NULL);
     113                                if (!ok) {
     114                                        pcap_cache_destroy_specific(&pcache);
    105115                                        SAFE_FREE(line);
    106116                                        x_fclose(pfile);
     
    114124        }
    115125
     126        *_pcache = pcache;
    116127        x_fclose(pfile);
    117128        TALLOC_FREE(ctx);
  • vendor/current/source3/printing/print_cups.c

    r746 r988  
    2727#include "printing/pcap.h"
    2828#include "librpc/gen_ndr/ndr_printcap.h"
     29#include "lib/util/sys_rw.h"
    2930
    3031#ifdef HAVE_CUPS
     
    108109        size_t size;
    109110
    110         if (lp_cups_server() != NULL && strlen(lp_cups_server()) > 0) {
    111                 if (!push_utf8_talloc(frame, &server, lp_cups_server(), &size)) {
     111        if (lp_cups_server(talloc_tos()) != NULL && strlen(lp_cups_server(talloc_tos())) > 0) {
     112                if (!push_utf8_talloc(frame, &server, lp_cups_server(talloc_tos()), &size)) {
    112113                        return NULL;
    113114                }
     
    148149
    149150        if (http == NULL) {
    150                 DEBUG(0,("Unable to connect to CUPS server %s:%d - %s\n",
     151                DEBUG(3,("Unable to connect to CUPS server %s:%d - %s\n",
    151152                         server, port, strerror(errno)));
    152153        }
     
    429430}
    430431
    431 static struct fd_event *cache_fd_event;
     432static struct tevent_fd *cache_fd_event;
    432433
    433434static bool cups_pcap_load_async(struct tevent_context *ev,
     
    453454        }
    454455
    455         pid = sys_fork();
     456        pid = fork();
    456457        if (pid == (pid_t)-1) {
    457458                DEBUG(10,("cups_pcap_load_async: fork failed %s\n",
     
    475476        close_all_print_db();
    476477
    477         status = reinit_after_fork(msg_ctx, ev, procid_self(), true);
     478        status = reinit_after_fork(msg_ctx, ev, true, NULL);
    478479        if (!NT_STATUS_IS_OK(status)) {
    479480                DEBUG(0,("cups_pcap_load_async: reinit_after_fork() failed\n"));
     
    484485        cups_cache_reload_async(fds[1]);
    485486        close(fds[1]);
     487        TALLOC_FREE(msg_ctx);
    486488        _exit(0);
    487489}
     
    489491struct cups_async_cb_args {
    490492        int pipe_fd;
    491         struct event_context *event_ctx;
     493        struct tevent_context *event_ctx;
    492494        struct messaging_context *msg_ctx;
    493         void (*post_cache_fill_fn)(struct event_context *,
     495        void (*post_cache_fill_fn)(struct tevent_context *,
    494496                                   struct messaging_context *);
    495497};
    496498
    497 static void cups_async_callback(struct event_context *event_ctx,
    498                                 struct fd_event *event,
    499                                 uint16 flags,
     499static void cups_async_callback(struct tevent_context *event_ctx,
     500                                struct tevent_fd *event,
     501                                uint16_t flags,
    500502                                void *p)
    501503{
     
    525527
    526528        if (!NT_STATUS_IS_OK(pcap_data.status)) {
    527                 DEBUG(0,("failed to retrieve printer list: %s\n",
     529                DEBUG(3,("failed to retrieve printer list: %s\n",
    528530                         nt_errstr(pcap_data.status)));
    529531                goto err_out;
     
    566568        int *p_pipe_fd;
    567569
    568         cb_args = TALLOC_P(NULL, struct cups_async_cb_args);
     570        cb_args = talloc(NULL, struct cups_async_cb_args);
    569571        if (cb_args == NULL) {
    570572                return false;
     
    587589
    588590        /* Trigger an event when the pipe can be read. */
    589         cache_fd_event = event_add_fd(ev,
     591        cache_fd_event = tevent_add_fd(ev,
    590592                                NULL, *p_pipe_fd,
    591                                 EVENT_FD_READ,
     593                                TEVENT_FD_READ,
    592594                                cups_async_callback,
    593595                                (void *)cb_args);
     
    956958                     "attributes-natural-language", NULL, language->language);
    957959
    958         if (!push_utf8_talloc(frame, &printername, lp_printername(snum),
     960        if (!push_utf8_talloc(frame, &printername,
     961                              lp_printername(talloc_tos(), snum),
    959962                              &size)) {
    960963                goto out;
     
    993996         */
    994997
    995         if (!push_utf8_talloc(frame, &cupsoptions, lp_cups_options(snum), &size)) {
     998        if (!push_utf8_talloc(frame, &cupsoptions,
     999                              lp_cups_options(talloc_tos(), snum), &size)) {
    9961000                goto out;
    9971001        }
     
    10151019                if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) {
    10161020                        DEBUG(0,("Unable to print file to %s - %s\n",
    1017                                  lp_printername(snum),
     1021                                 lp_printername(talloc_tos(), snum),
    10181022                                 ippErrorString(cupsLastError())));
    10191023                } else {
     
    10291033        } else {
    10301034                DEBUG(0,("Unable to print file to `%s' - %s\n",
    1031                          lp_printername(snum),
     1035                         lp_printername(talloc_tos(), snum),
    10321036                         ippErrorString(cupsLastError())));
    10331037        }
     
    11541158                     "attributes-natural-language", NULL, language->language);
    11551159
    1156         ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
     1160        ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
    11571161                      "requested-attributes",
    11581162                      (sizeof(jattrs) / sizeof(jattrs[0])),
     
    14541458                     "attributes-natural-language", NULL, language->language);
    14551459
    1456         if (!push_utf8_talloc(frame, &printername, lp_printername(snum),
    1457                               &size)) {
     1460        if (!push_utf8_talloc(frame, &printername,
     1461                              lp_printername(talloc_tos(), snum), &size)) {
    14581462                goto out;
    14591463        }
     
    14761480                if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) {
    14771481                        DEBUG(0,("Unable to pause printer %s - %s\n",
    1478                                  lp_printername(snum),
     1482                                 lp_printername(talloc_tos(), snum),
    14791483                                ippErrorString(cupsLastError())));
    14801484                } else {
     
    14831487        } else {
    14841488                DEBUG(0,("Unable to pause printer %s - %s\n",
    1485                          lp_printername(snum),
     1489                         lp_printername(talloc_tos(), snum),
    14861490                        ippErrorString(cupsLastError())));
    14871491        }
     
    15581562                     "attributes-natural-language", NULL, language->language);
    15591563
    1560         if (!push_utf8_talloc(frame, &printername, lp_printername(snum),
     1564        if (!push_utf8_talloc(frame, &printername, lp_printername(talloc_tos(), snum),
    15611565                              &size)) {
    15621566                goto out;
     
    15801584                if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) {
    15811585                        DEBUG(0,("Unable to resume printer %s - %s\n",
    1582                                  lp_printername(snum),
     1586                                 lp_printername(talloc_tos(), snum),
    15831587                                ippErrorString(cupsLastError())));
    15841588                } else {
     
    15871591        } else {
    15881592                DEBUG(0,("Unable to resume printer %s - %s\n",
    1589                          lp_printername(snum),
     1593                         lp_printername(talloc_tos(), snum),
    15901594                        ippErrorString(cupsLastError())));
    15911595        }
  • vendor/current/source3/printing/print_generic.c

    r746 r988  
    7474        if (do_sub && snum != -1) {
    7575                syscmd = talloc_sub_advanced(ctx,
    76                                 lp_servicename(snum),
     76                                lp_servicename(talloc_tos(), snum),
    7777                                current_user_info.unix_name,
    7878                                "",
     
    118118        /* need to pause the spooled entry */
    119119        slprintf(jobstr, sizeof(jobstr)-1, "%d", pjob->sysjob);
    120         return print_run_command(snum, lp_printername(snum), True,
    121                                  lp_lppausecommand(snum), NULL,
     120        return print_run_command(snum, lp_printername(talloc_tos(), snum), True,
     121                                 lp_lppause_command(talloc_tos(), snum), NULL,
    122122                                 "%j", jobstr,
    123123                                 NULL);
     
    133133        /* need to pause the spooled entry */
    134134        slprintf(jobstr, sizeof(jobstr)-1, "%d", pjob->sysjob);
    135         return print_run_command(snum, lp_printername(snum), True,
    136                                  lp_lpresumecommand(snum), NULL,
     135        return print_run_command(snum, lp_printername(talloc_tos(), snum), True,
     136                                 lp_lpresume_command(talloc_tos(), snum), NULL,
    137137                                 "%j", jobstr,
    138138                                 NULL);
     
    216216        /* we print from the directory path to give the best chance of
    217217           parsing the lpq output */
    218         current_directory = TALLOC_ARRAY(ctx,
    219                                         char,
    220                                         PATH_MAX+1);
     218        wd = sys_getwd();
     219        if (!wd) {
     220                return -1;
     221        }
     222
     223        current_directory = talloc_strdup(ctx, wd);
     224        SAFE_FREE(wd);
     225
    221226        if (!current_directory) {
    222227                return -1;
    223228        }
    224         wd = sys_getwd(current_directory);
    225         if (!wd) {
    226                 return -1;
    227         }
    228 
    229229        print_directory = talloc_strdup(ctx, pjob->filename);
    230230        if (!print_directory) {
     
    255255
    256256        /* send it to the system spooler */
    257         ret = print_run_command(snum, lp_printername(snum), True,
    258                         lp_printcommand(snum), NULL,
     257        ret = print_run_command(snum, lp_printername(talloc_tos(), snum), True,
     258                        lp_print_command(talloc_tos(), snum), NULL,
    259259                        "%s", p,
    260260                        "%J", jobname,
     
    273273         */
    274274        pjob->sysjob = -1;
    275         ret = generic_queue_get(lp_printername(snum), printing_type, lpq_cmd,
    276                                 &q, &status);
     275        ret = generic_queue_get(lp_printername(talloc_tos(), snum),
     276                                printing_type, lpq_cmd, &q, &status);
    277277        if (ret > 0) {
    278278                int i;
     
    296296 out:
    297297
    298         if (chdir(wd) == -1) {
     298        if (chdir(current_directory) == -1) {
    299299                smb_panic("chdir failed in generic_job_submit");
    300300        }
     
    308308static int generic_queue_pause(int snum)
    309309{
    310         return print_run_command(snum, lp_printername(snum), True,
    311                                  lp_queuepausecommand(snum), NULL, NULL);
     310        return print_run_command(snum, lp_printername(talloc_tos(), snum), True,
     311                                 lp_queuepause_command(talloc_tos(), snum), NULL, NULL);
    312312}
    313313
     
    317317static int generic_queue_resume(int snum)
    318318{
    319         return print_run_command(snum, lp_printername(snum), True,
    320                                  lp_queueresumecommand(snum), NULL, NULL);
     319        return print_run_command(snum, lp_printername(talloc_tos(), snum), True,
     320                                 lp_queueresume_command(talloc_tos(), snum), NULL, NULL);
    321321}
    322322
  • vendor/current/source3/printing/print_iprint.c

    r746 r988  
    9494static const char *iprint_server(void)
    9595{
    96         if ((lp_iprint_server() != NULL) && (strlen(lp_iprint_server()) > 0)) {
     96        const char *server = lp_iprint_server(talloc_tos());
     97
     98        if ((server != NULL) && (strlen(server) > 0)) {
    9799                DEBUG(10, ("iprint server explicitly set to %s\n",
    98                            lp_iprint_server()));
    99                 return lp_iprint_server();
     100                           server));
     101                return server;
    100102        }
    101103
     
    205207static int iprint_cache_add_printer(http_t *http,
    206208                                   int reqId,
    207                                    char* url)
     209                                   const char *url,
     210                                   struct pcap_cache **pcache)
    208211{
    209212        ipp_t           *request = NULL,        /* IPP Request */
     
    211214        ipp_attribute_t *attr;                  /* Current attribute */
    212215        cups_lang_t     *language = NULL;       /* Default language */
    213         char            *name,                  /* printer-name attribute */
    214                         *info,                  /* printer-info attribute */
    215                         smb_enabled,            /* smb-enabled attribute */
     216        const char      *name,                  /* printer-name attribute */
     217                        *info;                  /* printer-info attribute */
     218        char            smb_enabled,            /* smb-enabled attribute */
    216219                        secure;                 /* security-enabled attrib. */
    217220
    218         char            *httpPath;      /* path portion of the printer-uri */
     221        const char      *httpPath;      /* path portion of the printer-uri */
    219222
    220223        static const char *pattrs[] =   /* Requested printer attributes */
     
    341344
    342345                if (name != NULL && !secure && smb_enabled)
    343                         pcap_cache_add(name, info, NULL);
     346                        pcap_cache_add_specific(pcache, name, info, NULL);
    344347        }
    345348
     
    350353}
    351354
    352 bool iprint_cache_reload(void)
     355bool iprint_cache_reload(struct pcap_cache **_pcache)
    353356{
    354357        http_t          *http = NULL;           /* HTTP connection to server */
     
    358361        cups_lang_t     *language = NULL;       /* Default language */
    359362        int             i;
    360         bool ret = False;
     363        bool ret = false;
     364        struct pcap_cache *pcache = NULL;
    361365
    362366        DEBUG(5, ("reloading iprint printcap cache\n"));
     
    437441                                for (i = 0; i<ippGetCount(attr); i++)
    438442                                {
    439                                         char *url = ippGetString(attr, i, NULL);
     443                                        const char *url = ippGetString(attr, i, NULL);
    440444                                        if (!url || !strlen(url))
    441445                                                continue;
    442                                         iprint_cache_add_printer(http, i+2, url);
     446                                        iprint_cache_add_printer(http, i+2, url,
     447                                                                 &pcache);
    443448                                }
    444449                        }
     
    447452        }
    448453
    449         ret = True;
     454        ret = true;
     455        *_pcache = pcache;
    450456
    451457 out:
     
    619625
    620626        slprintf(uri, sizeof(uri) - 1, "ipp://%s/ipp/%s", iprint_server(),
    621                  lp_printername(snum));
     627                 lp_printername(talloc_tos(), snum));
    622628
    623629        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
     
    633639
    634640        slprintf(httpPath, sizeof(httpPath) - 1, "/ipp/%s",
    635                  lp_printername(snum));
     641                 lp_printername(talloc_tos(), snum));
    636642
    637643        if ((response = cupsDoRequest(http, request, httpPath)) != NULL) {
     
    719725
    720726        slprintf(uri, sizeof(uri) - 1, "ipp://%s/ipp/%s", iprint_server(),
    721                  lp_printername(snum));
     727                 lp_printername(talloc_tos(), snum));
    722728
    723729        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
     
    733739
    734740        slprintf(httpPath, sizeof(httpPath) - 1, "/ipp/%s",
    735                  lp_printername(snum));
     741                 lp_printername(talloc_tos(), snum));
    736742
    737743        if ((response = cupsDoRequest(http, request, httpPath)) != NULL) {
     
    820826
    821827        slprintf(uri, sizeof(uri) - 1, "ipp://%s/ipp/%s", iprint_server(),
    822                  lp_printername(snum));
     828                 lp_printername(talloc_tos(), snum));
    823829
    824830        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
     
    839845        */
    840846
    841         slprintf(uri, sizeof(uri) - 1, "/ipp/%s", lp_printername(snum));
     847        slprintf(uri, sizeof(uri) - 1, "/ipp/%s", lp_printername(talloc_tos(), snum));
    842848
    843849        if ((response = cupsDoFileRequest(http, request, uri, pjob->filename)) != NULL) {
    844850                if (ippGetStatusCode(response) >= IPP_OK_CONFLICT) {
    845851                        DEBUG(0,("Unable to print file to %s - %s\n",
    846                                  lp_printername(snum),
     852                                 lp_printername(talloc_tos(), snum),
    847853                                 ippErrorString(cupsLastError())));
    848854                } else {
     
    851857        } else {
    852858                DEBUG(0,("Unable to print file to `%s' - %s\n",
    853                          lp_printername(snum),
     859                         lp_printername(talloc_tos(), snum),
    854860                         ippErrorString(cupsLastError())));
    855861        }
  • vendor/current/source3/printing/print_standard.c

    r740 r988  
    6060
    6161/* handle standard printcap - moved from pcap_printer_fn() */
    62 bool std_pcap_cache_reload(const char *pcap_name)
     62bool std_pcap_cache_reload(const char *pcap_name, struct pcap_cache **_pcache)
    6363{
    6464        XFILE *pcap_file;
    6565        char *pcap_line;
     66        struct pcap_cache *pcache = NULL;
    6667
    6768        if ((pcap_file = x_fopen(pcap_name, O_RDONLY, 0)) == NULL) {
     
    118119                }
    119120
    120                 if (*name && !pcap_cache_add(name, comment, NULL)) {
     121                if ((*name != '\0')
     122                 && !pcap_cache_add_specific(&pcache, name, comment, NULL)) {
    121123                        x_fclose(pcap_file);
     124                        pcap_cache_destroy_specific(&pcache);
    122125                        return false;
    123126                }
     
    125128
    126129        x_fclose(pcap_file);
     130        *_pcache = pcache;
    127131        return true;
    128132}
  • vendor/current/source3/printing/print_svid.c

    r740 r988  
    3636
    3737#if defined(SYSV) || defined(HPUX)
    38 bool sysv_cache_reload(void)
     38bool sysv_cache_reload(struct pcap_cache **_pcache)
    3939{
    4040        char **lines;
    4141        int i;
     42        struct pcap_cache *pcache = NULL;
    4243
    4344#if defined(HPUX)
     
    112113               
    113114                /* add it to the cache */
    114                 if (!pcap_cache_add(name, NULL, NULL)) {
     115                if (!pcap_cache_add_specific(&pcache, name, NULL, NULL)) {
    115116                        TALLOC_FREE(lines);
    116                         return False;
     117                        pcap_cache_destroy_specific(&pcache);
     118                        return false;
    117119                }
    118120        }
    119121
    120122        TALLOC_FREE(lines);
    121         return True;
     123        *_pcache = pcache;
     124        return true;
    122125}
    123126
  • vendor/current/source3/printing/printer_list.c

    r746 r988  
    2020#include "includes.h"
    2121#include "system/filesys.h"
    22 #include "dbwrap.h"
     22#include "dbwrap/dbwrap.h"
     23#include "dbwrap/dbwrap_open.h"
    2324#include "util_tdb.h"
    2425#include "printer_list.h"
    2526
    26 #define PL_DB_NAME() lock_path("printer_list.tdb")
    2727#define PL_KEY_PREFIX "PRINTERLIST/PRN/"
    2828#define PL_KEY_FORMAT PL_KEY_PREFIX"%s"
     
    3434{
    3535        static struct db_context *db;
     36        char *db_path;
    3637
    3738        if (db != NULL) {
    3839                return db;
    3940        }
    40         db = db_open(NULL, PL_DB_NAME(), 0,
     41
     42        db_path = lock_path("printer_list.tdb");
     43        if (db_path == NULL) {
     44                return NULL;
     45        }
     46
     47        db = db_open(NULL, db_path, 0,
    4148                     TDB_DEFAULT|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
    42                      O_RDWR|O_CREAT, 0644);
     49                     O_RDWR|O_CREAT, 0644, DBWRAP_LOCK_ORDER_1,
     50                     DBWRAP_FLAG_NONE);
     51        TALLOC_FREE(db_path);
    4352        return db;
    4453}
     
    9099        }
    91100
    92         data = dbwrap_fetch_bystring_upper(db, key, key);
    93         if (data.dptr == NULL) {
     101        status = dbwrap_fetch_bystring_upper(db, key, key, &data);
     102        if (!NT_STATUS_IS_OK(status)) {
    94103                DEBUG(6, ("Failed to fetch record! "
    95104                          "The printer database is empty?\n"));
    96                 status = NT_STATUS_NOT_FOUND;
    97105                goto done;
    98106        }
     
    134142        SAFE_FREE(nstr);
    135143        SAFE_FREE(cstr);
     144        SAFE_FREE(lstr);
    136145        TALLOC_FREE(key);
    137146        return status;
     
    149158        uint64_t time_64;
    150159        uint32_t time_h, time_l;
    151         const char *str = NULL;
    152         const char *str2 = NULL;
    153160        NTSTATUS status;
    154161        int len;
     
    165172        }
    166173
    167         if (comment) {
    168                 str = comment;
    169         } else {
    170                 str = "";
    171         }
    172 
    173         if (location) {
    174                 str2 = location;
    175         } else {
    176                 str2 = "";
    177         }
    178 
     174        if (comment == NULL) {
     175                comment = "";
     176        }
     177
     178        if (location == NULL) {
     179                location = "";
     180        }
    179181
    180182        time_64 = last_refresh;
     
    182184        time_h = time_64 >> 32;
    183185
    184         len = tdb_pack(NULL, 0, PL_DATA_FORMAT, time_h, time_l, name, str, str2);
     186        len = tdb_pack(NULL, 0,
     187                       PL_DATA_FORMAT,
     188                       time_h,
     189                       time_l,
     190                       name,
     191                       comment,
     192                       location);
    185193
    186194        data.dptr = talloc_array(key, uint8_t, len);
     
    193201
    194202        len = tdb_pack(data.dptr, data.dsize,
    195                        PL_DATA_FORMAT, time_h, time_l, name, str, str2);
     203                       PL_DATA_FORMAT,
     204                       time_h,
     205                       time_l,
     206                       name,
     207                       comment,
     208                       location);
    196209
    197210        status = dbwrap_store_bystring_upper(db, key, data, TDB_REPLACE);
     
    217230        ZERO_STRUCT(data);
    218231
    219         data = dbwrap_fetch_bystring(db, talloc_tos(), PL_TIMESTAMP_KEY);
    220         if (data.dptr == NULL) {
     232        status = dbwrap_fetch_bystring(db, talloc_tos(), PL_TIMESTAMP_KEY, &data);
     233        if (!NT_STATUS_IS_OK(status)) {
    221234                DEBUG(1, ("Failed to fetch record!\n"));
    222                 status = NT_STATUS_NOT_FOUND;
    223235                goto done;
    224236        }
     
    226238        ret = tdb_unpack(data.dptr, data.dsize,
    227239                         PL_TSTAMP_FORMAT, &time_h, &time_l);
     240        TALLOC_FREE(data.dptr);
    228241        if (ret == -1) {
    229242                DEBUG(1, ("Failed to un pack printer data"));
     
    280293
    281294static NTSTATUS printer_list_traverse(printer_list_trv_fn_t *fn,
    282                                                 void *private_data)
    283 {
    284         struct db_context *db;
    285         int ret;
     295                                      void *private_data,
     296                                      bool read_only)
     297{
     298        struct db_context *db;
     299        NTSTATUS status;
    286300
    287301        db = get_printer_list_db();
     
    290304        }
    291305
    292         ret = db->traverse(db, fn, private_data);
    293         if (ret < 0) {
    294                 return NT_STATUS_UNSUCCESSFUL;
    295         }
    296 
    297         return NT_STATUS_OK;
     306        if (read_only) {
     307                status = dbwrap_traverse_read(db, fn, private_data, NULL);
     308        } else {
     309                status = dbwrap_traverse(db, fn, private_data, NULL);
     310        }
     311
     312        return status;
    298313}
    299314
     
    313328        char *location;
    314329        int ret;
     330        TDB_DATA key;
     331        TDB_DATA value;
     332
     333        key = dbwrap_record_get_key(rec);
    315334
    316335        /* skip anything that does not contain PL_DATA_FORMAT data */
    317         if (strncmp((char *)rec->key.dptr,
     336        if (strncmp((char *)key.dptr,
    318337                    PL_KEY_PREFIX, sizeof(PL_KEY_PREFIX)-1)) {
    319338                return 0;
    320339        }
    321340
    322         ret = tdb_unpack(rec->value.dptr, rec->value.dsize,
     341        value = dbwrap_record_get_value(rec);
     342
     343        ret = tdb_unpack(value.dptr, value.dsize,
    323344                         PL_DATA_FORMAT, &time_h, &time_l, &name, &comment,
    324345                         &location);
     
    336357
    337358        if (refresh < state->last_refresh) {
    338                 state->status = rec->delete_rec(rec);
     359                state->status = dbwrap_record_delete(rec);
    339360                if (!NT_STATUS_IS_OK(state->status)) {
    340361                        return -1;
     
    357378        state.status = NT_STATUS_OK;
    358379
    359         status = printer_list_traverse(printer_list_clean_fn, &state);
     380        status = printer_list_traverse(printer_list_clean_fn, &state, false);
    360381        if (NT_STATUS_EQUAL(status, NT_STATUS_UNSUCCESSFUL) &&
    361382            !NT_STATUS_IS_OK(state.status)) {
     
    381402        char *location;
    382403        int ret;
     404        TDB_DATA key;
     405        TDB_DATA value;
     406
     407        key = dbwrap_record_get_key(rec);
    383408
    384409        /* always skip PL_TIMESTAMP_KEY key */
    385         if (strequal((const char *)rec->key.dptr, PL_TIMESTAMP_KEY)) {
     410        if (strequal((const char *)key.dptr, PL_TIMESTAMP_KEY)) {
    386411                return 0;
    387412        }
    388413
    389         ret = tdb_unpack(rec->value.dptr, rec->value.dsize,
     414        value = dbwrap_record_get_value(rec);
     415
     416        ret = tdb_unpack(value.dptr, value.dsize,
    390417                         PL_DATA_FORMAT, &time_h, &time_l, &name, &comment,
    391418                         &location);
     
    404431}
    405432
    406 NTSTATUS printer_list_run_fn(void (*fn)(const char *, const char *, const char *, void *),
    407                              void *private_data)
     433NTSTATUS printer_list_read_run_fn(void (*fn)(const char *, const char *, const char *, void *),
     434                                  void *private_data)
    408435{
    409436        struct printer_list_exec_state state;
     
    414441        state.status = NT_STATUS_OK;
    415442
    416         status = printer_list_traverse(printer_list_exec_fn, &state);
     443        status = printer_list_traverse(printer_list_exec_fn, &state, true);
    417444        if (NT_STATUS_EQUAL(status, NT_STATUS_UNSUCCESSFUL) &&
    418445            !NT_STATUS_IS_OK(state.status)) {
  • vendor/current/source3/printing/printer_list.h

    r740 r988  
    101101NTSTATUS printer_list_clean_old(void);
    102102
    103 NTSTATUS printer_list_run_fn(void (*fn)(const char *, const char *, const char *, void *),
    104                              void *private_data);
     103NTSTATUS printer_list_read_run_fn(void (*fn)(const char *, const char *, const char *, void *),
     104                                  void *private_data);
    105105#endif /* _PRINTER_LIST_H_ */
  • vendor/current/source3/printing/printing.c

    r860 r988  
    2929#include "printing/notify.h"
    3030#include "printing/pcap.h"
     31#include "printing/printer_list.h"
     32#include "printing/queue_process.h"
    3133#include "serverid.h"
    3234#include "smbd/smbd.h"
     
    3436#include "messages.h"
    3537#include "util_tdb.h"
     38#include "lib/param/loadparm.h"
     39#include "lib/util/sys_rw_data.h"
    3640
    3741extern struct current_user current_user;
     
    3943
    4044/* Current printer interface */
    41 static bool remove_from_jobs_added(const char* sharename, uint32 jobid);
     45static bool remove_from_jobs_added(const char* sharename, uint32_t jobid);
    4246
    4347/*
     
    5660
    5761static TDB_CONTEXT *rap_tdb;
    58 static uint16 next_rap_jobid;
     62static uint16_t next_rap_jobid;
    5963struct rap_jobid_key {
    6064        fstring sharename;
    61         uint32  jobid;
     65        uint32_t  jobid;
    6266};
    6367
     
    6771***************************************************************************/
    6872
    69 uint16 pjobid_to_rap(const char* sharename, uint32 jobid)
    70 {
    71         uint16 rap_jobid;
     73uint16_t pjobid_to_rap(const char* sharename, uint32_t jobid)
     74{
     75        uint16_t rap_jobid;
    7276        TDB_DATA data, key;
    7377        struct rap_jobid_key jinfo;
    74         uint8 buf[2];
     78        uint8_t buf[2];
    7579
    7680        DEBUG(10,("pjobid_to_rap: called.\n"));
     
    8690        fstrcpy( jinfo.sharename, sharename );
    8791        jinfo.jobid = jobid;
    88         key.dptr = (uint8 *)&jinfo;
     92        key.dptr = (uint8_t *)&jinfo;
    8993        key.dsize = sizeof(jinfo);
    9094
    9195        data = tdb_fetch(rap_tdb, key);
    92         if (data.dptr && data.dsize == sizeof(uint16)) {
     96        if (data.dptr && data.dsize == sizeof(uint16_t)) {
    9397                rap_jobid = SVAL(data.dptr, 0);
    9498                SAFE_FREE(data.dptr);
     
    113117}
    114118
    115 bool rap_to_pjobid(uint16 rap_jobid, fstring sharename, uint32 *pjobid)
     119bool rap_to_pjobid(uint16_t rap_jobid, fstring sharename, uint32_t *pjobid)
    116120{
    117121        TDB_DATA data, key;
    118         uint8 buf[2];
     122        uint8_t buf[2];
    119123
    120124        DEBUG(10,("rap_to_pjobid called.\n"));
     
    146150}
    147151
    148 void rap_jobid_delete(const char* sharename, uint32 jobid)
     152void rap_jobid_delete(const char* sharename, uint32_t jobid)
    149153{
    150154        TDB_DATA key, data;
    151         uint16 rap_jobid;
     155        uint16_t rap_jobid;
    152156        struct rap_jobid_key jinfo;
    153         uint8 buf[2];
     157        uint8_t buf[2];
    154158
    155159        DEBUG(10,("rap_jobid_delete: called.\n"));
     
    161165        fstrcpy( jinfo.sharename, sharename );
    162166        jinfo.jobid = jobid;
    163         key.dptr = (uint8 *)&jinfo;
     167        key.dptr = (uint8_t *)&jinfo;
    164168        key.dsize = sizeof(jinfo);
    165169
    166170        data = tdb_fetch(rap_tdb, key);
    167         if (!data.dptr || (data.dsize != sizeof(uint16))) {
     171        if (!data.dptr || (data.dsize != sizeof(uint16_t))) {
    168172                DEBUG(10,("rap_jobid_delete: cannot find jobid %u\n",
    169173                        (unsigned int)jobid ));
     
    195199        int services = lp_numservices();
    196200        int snum;
    197 
    198         unlink(cache_path("printing.tdb"));
    199         mkdir(cache_path("printing"),0755);
     201        bool ok;
     202        char *print_cache_path;
     203
     204        if (!printer_list_parent_init()) {
     205                return false;
     206        }
     207
     208        print_cache_path = cache_path("printing");
     209        if (print_cache_path == NULL) {
     210                return false;
     211        }
     212        ok = directory_create_or_exist(print_cache_path, 0755);
     213        TALLOC_FREE(print_cache_path);
     214        if (!ok) {
     215                return false;
     216        }
     217
     218        print_cache_path = cache_path("printing.tdb");
     219        if (print_cache_path == NULL) {
     220                return false;
     221        }
     222        unlink(print_cache_path);
     223        TALLOC_FREE(print_cache_path);
    200224
    201225        /* handle a Samba upgrade */
     
    203227        for (snum = 0; snum < services; snum++) {
    204228                struct tdb_print_db *pdb;
    205                 if (!lp_print_ok(snum))
     229                if (!lp_printable(snum))
    206230                        continue;
    207231
     
    209233                if (!pdb)
    210234                        continue;
    211                 if (tdb_lock_bystring(pdb->tdb, sversion) == -1) {
     235                if (tdb_lock_bystring(pdb->tdb, sversion) != 0) {
    212236                        DEBUG(0,("print_backend_init: Failed to open printer %s database\n", lp_const_servicename(snum) ));
    213237                        release_print_db(pdb);
     
    277301****************************************************************************/
    278302
    279 static TDB_DATA print_key(uint32 jobid, uint32 *tmp)
     303static TDB_DATA print_key(uint32_t jobid, uint32_t *tmp)
    280304{
    281305        TDB_DATA ret;
    282306
    283307        SIVAL(tmp, 0, jobid);
    284         ret.dptr = (uint8 *)tmp;
     308        ret.dptr = (uint8_t *)tmp;
    285309        ret.dsize = sizeof(*tmp);
    286310        return ret;
     
    290314 Pack the devicemode to store it in a tdb.
    291315****************************************************************************/
    292 static int pack_devicemode(struct spoolss_DeviceMode *devmode, uint8 *buf, int buflen)
     316static int pack_devicemode(struct spoolss_DeviceMode *devmode, uint8_t *buf, int buflen)
    293317{
    294318        enum ndr_err_code ndr_err;
     
    324348****************************************************************************/
    325349static int unpack_devicemode(TALLOC_CTX *mem_ctx,
    326                       const uint8 *buf, int buflen,
     350                      const uint8_t *buf, int buflen,
    327351                      struct spoolss_DeviceMode **devmode)
    328352{
     
    374398***********************************************************************/
    375399
    376 static int unpack_pjob(TALLOC_CTX *mem_ctx, uint8 *buf, int buflen,
     400static int unpack_pjob(TALLOC_CTX *mem_ctx, uint8_t *buf, int buflen,
    377401                       struct printjob *pjob)
    378402{
    379403        int     len = 0;
    380404        int     used;
    381         uint32 pjpid, pjjobid, pjsysjob, pjfd, pjstarttime, pjstatus;
    382         uint32 pjsize, pjpage_count, pjspooled, pjsmbjob;
     405        uint32_t pjpid, pjjobid, pjsysjob, pjfd, pjstarttime, pjstatus;
     406        uint32_t pjsize, pjpage_count, pjspooled, pjsmbjob;
    383407
    384408        if (!buf || !pjob) {
     
    435459static struct printjob *print_job_find(TALLOC_CTX *mem_ctx,
    436460                                       const char *sharename,
    437                                        uint32 jobid)
     461                                       uint32_t jobid)
    438462{
    439463        struct printjob         *pjob;
     
    479503}
    480504
    481 /* Convert a unix jobid to a smb jobid */
    482 
    483 struct unixjob_traverse_state {
     505struct job_traverse_state {
    484506        int sysjob;
    485         uint32 sysjob_to_jobid_value;
     507        uint32_t jobid;
    486508};
    487509
    488 static int unixjob_traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA key,
    489                                TDB_DATA data, void *private_data)
     510/* find spoolss jobid based on sysjob */
     511static int sysjob_to_jobid_traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA key,
     512                                       TDB_DATA data, void *private_data)
    490513{
    491514        struct printjob *pjob;
    492         struct unixjob_traverse_state *state =
    493                 (struct unixjob_traverse_state *)private_data;
     515        struct job_traverse_state *state =
     516                (struct job_traverse_state *)private_data;
    494517
    495518        if (!data.dptr || data.dsize == 0)
     
    497520
    498521        pjob = (struct printjob *)data.dptr;
    499         if (key.dsize != sizeof(uint32))
     522        if (key.dsize != sizeof(uint32_t))
    500523                return 0;
    501524
    502525        if (state->sysjob == pjob->sysjob) {
    503                 state->sysjob_to_jobid_value = pjob->jobid;
     526                state->jobid = pjob->jobid;
    504527                return 1;
    505528        }
     
    508531}
    509532
    510 static uint32 sysjob_to_jobid_pdb(struct tdb_print_db *pdb, int sysjob)
    511 {
    512         struct unixjob_traverse_state state;
     533uint32_t sysjob_to_jobid_pdb(struct tdb_print_db *pdb, int sysjob)
     534{
     535        struct job_traverse_state state;
    513536
    514537        state.sysjob = sysjob;
    515         state.sysjob_to_jobid_value = (uint32)-1;
    516 
    517         tdb_traverse(pdb->tdb, unixjob_traverse_fn, &state);
    518 
    519         return state.sysjob_to_jobid_value;
     538        state.jobid = (uint32_t)-1;
     539
     540        tdb_traverse(pdb->tdb, sysjob_to_jobid_traverse_fn, &state);
     541
     542        return state.jobid;
    520543}
    521544
     
    525548****************************************************************************/
    526549
    527 uint32 sysjob_to_jobid(int unix_jobid)
     550uint32_t sysjob_to_jobid(int unix_jobid)
    528551{
    529552        int services = lp_numservices();
    530553        int snum;
    531         struct unixjob_traverse_state state;
     554        struct job_traverse_state state;
    532555
    533556        state.sysjob = unix_jobid;
    534         state.sysjob_to_jobid_value = (uint32)-1;
     557        state.jobid = (uint32_t)-1;
    535558
    536559        for (snum = 0; snum < services; snum++) {
    537560                struct tdb_print_db *pdb;
    538                 if (!lp_print_ok(snum))
     561                if (!lp_printable(snum))
    539562                        continue;
    540563                pdb = get_print_db_byname(lp_const_servicename(snum));
     
    542565                        continue;
    543566                }
    544                 tdb_traverse(pdb->tdb, unixjob_traverse_fn, &state);
     567                tdb_traverse(pdb->tdb, sysjob_to_jobid_traverse_fn, &state);
    545568                release_print_db(pdb);
    546                 if (state.sysjob_to_jobid_value != (uint32)-1)
    547                         return state.sysjob_to_jobid_value;
    548         }
    549         return (uint32)-1;
     569                if (state.jobid != (uint32_t)-1)
     570                        return state.jobid;
     571        }
     572        return (uint32_t)-1;
     573}
     574
     575/* find sysjob based on spoolss jobid */
     576static int jobid_to_sysjob_traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA key,
     577                                       TDB_DATA data, void *private_data)
     578{
     579        struct printjob *pjob;
     580        struct job_traverse_state *state =
     581                (struct job_traverse_state *)private_data;
     582
     583        if (!data.dptr || data.dsize == 0)
     584                return 0;
     585
     586        pjob = (struct printjob *)data.dptr;
     587        if (key.dsize != sizeof(uint32_t))
     588                return 0;
     589
     590        if (state->jobid == pjob->jobid) {
     591                state->sysjob = pjob->sysjob;
     592                return 1;
     593        }
     594
     595        return 0;
     596}
     597
     598int jobid_to_sysjob_pdb(struct tdb_print_db *pdb, uint32_t jobid)
     599{
     600        struct job_traverse_state state;
     601
     602        state.sysjob = -1;
     603        state.jobid = jobid;
     604
     605        tdb_traverse(pdb->tdb, jobid_to_sysjob_traverse_fn, &state);
     606
     607        return state.sysjob;
    550608}
    551609
     
    575633   appropriate win32 API constant. */
    576634
    577 static uint32 map_to_spoolss_status(uint32 lpq_status)
     635static uint32_t map_to_spoolss_status(uint32_t lpq_status)
    578636{
    579637        int i = 0;
     
    598656
    599657        SIVAL(&store_jobid, 0, jobid);
    600         data.dptr = (uint8 *) &store_jobid;
     658        data.dptr = (uint8_t *) &store_jobid;
    601659        data.dsize = 4;
    602660
     
    627685        key = string_tdb_data("INFO/jobs_changed");
    628686
    629         if (tdb_chainlock_with_timeout(pdb->tdb, key, 5) == -1)
     687        if (tdb_chainlock_with_timeout(pdb->tdb, key, 5) != 0)
    630688                goto out;
    631689
     
    639697        job_count = data.dsize / 4;
    640698        for (i = 0; i < job_count; i++) {
    641                 uint32 ch_jobid;
     699                uint32_t ch_jobid;
    642700
    643701                ch_jobid = IVAL(data.dptr, i*4);
     
    646704                                memmove(data.dptr + (i*4), data.dptr + (i*4) + 4, (job_count - i - 1)*4 );
    647705                        data.dsize -= 4;
    648                         if (tdb_store(pdb->tdb, key, data, TDB_REPLACE) == -1)
     706                        if (tdb_store(pdb->tdb, key, data, TDB_REPLACE) != 0)
    649707                                goto out;
    650708                        break;
     
    668726static void pjob_store_notify(struct tevent_context *ev,
    669727                              struct messaging_context *msg_ctx,
    670                               const char* sharename, uint32 jobid,
     728                              const char* sharename, uint32_t jobid,
    671729                              struct printjob *old_data,
    672730                              struct printjob *new_data,
     
    734792static bool pjob_store(struct tevent_context *ev,
    735793                       struct messaging_context *msg_ctx,
    736                        const char* sharename, uint32 jobid,
     794                       const char* sharename, uint32_t jobid,
    737795                       struct printjob *pjob)
    738796{
     
    741799        bool                    ret = False;
    742800        struct tdb_print_db     *pdb = get_print_db_byname(sharename);
    743         uint8                   *buf = NULL;
     801        uint8_t                 *buf = NULL;
    744802        int                     len, newlen, buflen;
    745803
     
    760818                buflen = newlen;
    761819                len += tdb_pack(buf+len, buflen-len, "ddddddddddfffff",
    762                                 (uint32)pjob->pid,
    763                                 (uint32)pjob->jobid,
    764                                 (uint32)pjob->sysjob,
    765                                 (uint32)pjob->fd,
    766                                 (uint32)pjob->starttime,
    767                                 (uint32)pjob->status,
    768                                 (uint32)pjob->size,
    769                                 (uint32)pjob->page_count,
    770                                 (uint32)pjob->spooled,
    771                                 (uint32)pjob->smbjob,
     820                                (uint32_t)pjob->pid,
     821                                (uint32_t)pjob->jobid,
     822                                (uint32_t)pjob->sysjob,
     823                                (uint32_t)pjob->fd,
     824                                (uint32_t)pjob->starttime,
     825                                (uint32_t)pjob->status,
     826                                (uint32_t)pjob->size,
     827                                (uint32_t)pjob->page_count,
     828                                (uint32_t)pjob->spooled,
     829                                (uint32_t)pjob->smbjob,
    772830                                pjob->filename,
    773831                                pjob->jobname,
     
    779837
    780838                if (buflen != len) {
    781                         buf = (uint8 *)SMB_REALLOC(buf, len);
     839                        buf = (uint8_t *)SMB_REALLOC(buf, len);
    782840                        if (!buf) {
    783841                                DEBUG(0,("pjob_store: failed to enlarge buffer!\n"));
     
    843901static void pjob_delete(struct tevent_context *ev,
    844902                        struct messaging_context *msg_ctx,
    845                         const char* sharename, uint32 jobid)
     903                        const char* sharename, uint32_t jobid)
    846904{
    847905        uint32_t tmp;
    848906        struct printjob *pjob;
    849         uint32 job_status = 0;
     907        uint32_t job_status = 0;
    850908        struct tdb_print_db *pdb;
    851909        TALLOC_CTX *tmp_ctx = talloc_new(ev);
     
    891949                           struct messaging_context *msg_ctx,
    892950                           const char *sharename, print_queue_struct *q,
    893                            uint32 jobid)
     951                           uint32_t jobid)
    894952{
    895953        struct printjob pj, *old_pj;
     
    899957        }
    900958
    901         if (jobid == (uint32)-1) {
     959        if (jobid == (uint32_t)-1) {
    902960                jobid = q->sysjob + UNIX_JOB_START;
    903961        }
     
    9531011        struct traverse_struct *ts = (struct traverse_struct *)state;
    9541012        struct printjob pjob;
    955         uint32 jobid;
     1013        uint32_t jobid;
    9561014        int i = 0;
    9571015
     
    11331191        TDB_DATA key;
    11341192        TDB_DATA data;
    1135         pid_t updating_pid = sys_getpid();
    1136         uint8 buffer[4];
     1193        pid_t updating_pid = getpid();
     1194        uint8_t buffer[4];
    11371195
    11381196        struct tdb_print_db *pdb = get_print_db_byname(sharename);
     
    11441202        key = string_tdb_data(keystr);
    11451203
    1146         DEBUG(5, ("set_updating_pid: %s updating lpq cache for print share %s\n",
     1204        DEBUG(5, ("set_updating_pid: %supdating lpq cache for print share %s\n",
    11471205                updating ? "" : "not ",
    11481206                sharename ));
     
    11921250{
    11931251        TDB_DATA data;
    1194         int max_reported_jobs = lp_max_reported_jobs(pts->snum);
     1252        int max_reported_jobs = lp_max_reported_print_jobs(pts->snum);
    11951253        print_queue_struct *queue = pts->queue;
    11961254        size_t len;
     
    12121270                qcount++;
    12131271                data.dsize += tdb_pack(NULL, 0, "ddddddff",
    1214                                 (uint32)queue[i].sysjob,
    1215                                 (uint32)queue[i].size,
    1216                                 (uint32)queue[i].page_count,
    1217                                 (uint32)queue[i].status,
    1218                                 (uint32)queue[i].priority,
    1219                                 (uint32)queue[i].time,
     1272                                (uint32_t)queue[i].sysjob,
     1273                                (uint32_t)queue[i].size,
     1274                                (uint32_t)queue[i].page_count,
     1275                                (uint32_t)queue[i].status,
     1276                                (uint32_t)queue[i].priority,
     1277                                (uint32_t)queue[i].time,
    12201278                                queue[i].fs_user,
    12211279                                queue[i].fs_file);
    12221280        }
    12231281
    1224         if ((data.dptr = (uint8 *)SMB_MALLOC(data.dsize)) == NULL)
     1282        if ((data.dptr = (uint8_t *)SMB_MALLOC(data.dsize)) == NULL)
    12251283                return;
    12261284
     
    12321290
    12331291                len += tdb_pack(data.dptr + len, data.dsize - len, "ddddddff",
    1234                                 (uint32)queue[i].sysjob,
    1235                                 (uint32)queue[i].size,
    1236                                 (uint32)queue[i].page_count,
    1237                                 (uint32)queue[i].status,
    1238                                 (uint32)queue[i].priority,
    1239                                 (uint32)queue[i].time,
     1292                                (uint32_t)queue[i].sysjob,
     1293                                (uint32_t)queue[i].size,
     1294                                (uint32_t)queue[i].page_count,
     1295                                (uint32_t)queue[i].status,
     1296                                (uint32_t)queue[i].priority,
     1297                                (uint32_t)queue[i].time,
    12401298                                queue[i].fs_user,
    12411299                                queue[i].fs_file);
     
    12631321}
    12641322
    1265 static void check_job_added(const char *sharename, TDB_DATA data, uint32 jobid)
     1323static void check_job_added(const char *sharename, TDB_DATA data, uint32_t jobid)
    12661324{
    12671325        unsigned int i;
     
    12691327
    12701328        for (i = 0; i < job_count; i++) {
    1271                 uint32 ch_jobid;
     1329                uint32_t ch_jobid;
    12721330
    12731331                ch_jobid = IVAL(data.dptr, i*4);
     
    13051363
    13061364        if (last_qscan_time == ((time_t)-1)
    1307                 || (time_now - last_qscan_time) >= lp_lpqcachetime()
     1365                || (time_now - last_qscan_time) >= lp_lpq_cache_time()
    13081366                || last_qscan_time > (time_now + MAX_CACHE_VALID_TIME))
    13091367        {
    1310                 uint32 u;
     1368                uint32_t u;
    13111369                time_t msg_pending_time;
    13121370
     
    13141372                        "(last_qscan_time = %d, time now = %d, qcachetime = %d)\n",
    13151373                        sharename, (int)last_qscan_time, (int)time_now,
    1316                         (int)lp_lpqcachetime() ));
     1374                        (int)lp_lpq_cache_time() ));
    13171375
    13181376                /* check if another smbd has already sent a message to update the
     
    14081466
    14091467        for (i=0; i<qcount; i++) {
    1410                 uint32 jobid = sysjob_to_jobid_pdb(pdb, queue[i].sysjob);
    1411                 if (jobid == (uint32)-1) {
     1468                uint32_t jobid = sysjob_to_jobid_pdb(pdb, queue[i].sysjob);
     1469                if (jobid == (uint32_t)-1) {
    14121470                        /* assume its a unix print job */
    14131471                        print_unix_job(ev, msg_ctx,
     
    14781536
    14791537        status.qcount = qcount;
    1480         data.dptr = (uint8 *)&status;
     1538        data.dptr = (uint8_t *)&status;
    14811539        data.dsize = sizeof(status);
    14821540        tdb_store(pdb->tdb, key, data, TDB_REPLACE);
     
    14881546
    14891547        slprintf(keystr, sizeof(keystr)-1, "CACHE/%s", sharename);
    1490         tdb_store_int32(pdb->tdb, keystr, (int32)time(NULL));
     1548        tdb_store_int32(pdb->tdb, keystr, (int32_t)time(NULL));
    14911549
    14921550        /* clear the msg pending record for this queue */
     
    15461604        slprintf(keystr, sizeof(keystr) - 1, "LOCK/%s", sharename);
    15471605        /* Only wait 10 seconds for this. */
    1548         if (tdb_lock_bystring_with_timeout(pdb->tdb, keystr, 10) == -1) {
     1606        if (tdb_lock_bystring_with_timeout(pdb->tdb, keystr, 10) != 0) {
    15491607                DEBUG(0,("print_queue_update_with_lock: Failed to lock printer %s database\n", sharename));
    15501608                release_print_db(pdb);
     
    16061664        size_t len;
    16071665
    1608         len = tdb_unpack( (uint8 *)data->data, data->length, "fdPP",
     1666        len = tdb_unpack( (uint8_t *)data->data, data->length, "fdPP",
    16091667                sharename,
    16101668                &printing_type,
     
    16281686}
    16291687
    1630 static void printing_pause_fd_handler(struct tevent_context *ev,
    1631                                       struct tevent_fd *fde,
    1632                                       uint16_t flags,
    1633                                       void *private_data)
    1634 {
    1635         /*
    1636          * If pause_pipe[1] is closed it means the parent smbd
    1637          * and children exited or aborted.
    1638          */
    1639         exit_server_cleanly(NULL);
    1640 }
    1641 
    1642 extern struct child_pid *children;
    1643 extern int num_children;
    1644 
    1645 static void add_child_pid(pid_t pid)
    1646 {
    1647         struct child_pid *child;
    1648 
    1649         child = SMB_MALLOC_P(struct child_pid);
    1650         if (child == NULL) {
    1651                 DEBUG(0, ("Could not add child struct -- malloc failed\n"));
    1652                 return;
    1653         }
    1654         child->pid = pid;
    1655         DLIST_ADD(children, child);
    1656         num_children += 1;
    1657 }
    1658 
    1659 /****************************************************************************
    1660  Notify smbds of new printcap data
    1661 **************************************************************************/
    1662 static void reload_pcap_change_notify(struct tevent_context *ev,
    1663                                       struct messaging_context *msg_ctx)
    1664 {
    1665         /*
    1666          * Reload the printers first in the background process so that
    1667          * newly added printers get default values created in the registry.
    1668          *
    1669          * This will block the process for some time (~1 sec per printer), but
    1670          * it doesn't block smbd's servering clients.
    1671          */
    1672         reload_printers_full(ev, msg_ctx);
    1673 
    1674         message_send_all(msg_ctx, MSG_PRINTER_PCAP, NULL, 0, NULL);
    1675 }
    1676 
    1677 static bool printer_housekeeping_fn(const struct timeval *now,
    1678                                     void *private_data)
    1679 {
    1680         static time_t last_pcap_reload_time = 0;
    1681         time_t printcap_cache_time = (time_t)lp_printcap_cache_time();
    1682         time_t t = time_mono(NULL);
    1683 
    1684         DEBUG(5, ("printer housekeeping\n"));
    1685 
    1686         /* if periodic printcap rescan is enabled, see if it's time to reload */
    1687         if ((printcap_cache_time != 0)
    1688          && (t >= (last_pcap_reload_time + printcap_cache_time))) {
    1689                 DEBUG( 3,( "Printcap cache time expired.\n"));
    1690                 pcap_cache_reload(server_event_context(),
    1691                                   smbd_messaging_context(),
    1692                                   &reload_pcap_change_notify);
    1693                 last_pcap_reload_time = t;
    1694         }
    1695 
    1696         return true;
    1697 }
    1698 
    1699 static void printing_sig_term_handler(struct tevent_context *ev,
    1700                                       struct tevent_signal *se,
    1701                                       int signum,
    1702                                       int count,
    1703                                       void *siginfo,
    1704                                       void *private_data)
    1705 {
    1706         exit_server_cleanly("termination signal");
    1707 }
    1708 
    1709 static void printing_sig_hup_handler(struct tevent_context *ev,
    1710                                   struct tevent_signal *se,
    1711                                   int signum,
    1712                                   int count,
    1713                                   void *siginfo,
    1714                                   void *private_data)
    1715 {
    1716         struct messaging_context *msg_ctx = talloc_get_type_abort(
    1717                 private_data, struct messaging_context);
    1718 
    1719         DEBUG(1,("Reloading printers after SIGHUP\n"));
    1720         pcap_cache_reload(ev, msg_ctx,
    1721                           &reload_pcap_change_notify);
    1722 }
    1723 
    1724 static void printing_conf_updated(struct messaging_context *msg,
    1725                                   void *private_data,
    1726                                   uint32_t msg_type,
    1727                                   struct server_id server_id,
    1728                                   DATA_BLOB *data)
    1729 {
    1730         DEBUG(5,("Reloading printers after conf change\n"));
    1731         pcap_cache_reload(messaging_event_context(msg), msg,
    1732                           &reload_pcap_change_notify);
    1733 }
    1734 
    1735 
    1736 static pid_t background_lpq_updater_pid = -1;
    1737 
    1738 /****************************************************************************
    1739 main thread of the background lpq updater
    1740 ****************************************************************************/
    1741 void start_background_queue(struct tevent_context *ev,
    1742                             struct messaging_context *msg_ctx)
    1743 {
    1744         /* Use local variables for this as we don't
    1745          * need to save the parent side of this, just
    1746          * ensure it closes when the process exits.
    1747          */
    1748         int pause_pipe[2];
    1749 
    1750         DEBUG(3,("start_background_queue: Starting background LPQ thread\n"));
    1751 
    1752         if (pipe(pause_pipe) == -1) {
    1753                 DEBUG(5,("start_background_queue: cannot create pipe. %s\n", strerror(errno) ));
    1754                 exit(1);
    1755         }
    1756 
    1757         background_lpq_updater_pid = sys_fork();
    1758 
    1759         if (background_lpq_updater_pid == -1) {
    1760                 DEBUG(5,("start_background_queue: background LPQ thread failed to start. %s\n", strerror(errno) ));
    1761                 exit(1);
    1762         }
    1763 
    1764         /* Track the printing pid along with other smbd children */
    1765         add_child_pid(background_lpq_updater_pid);
    1766 
    1767         if(background_lpq_updater_pid == 0) {
    1768                 struct tevent_fd *fde;
    1769                 int ret;
    1770                 NTSTATUS status;
    1771                 struct tevent_signal *se;
    1772 
    1773                 /* Child. */
    1774                 DEBUG(5,("start_background_queue: background LPQ thread started\n"));
    1775 
    1776                 close(pause_pipe[0]);
    1777                 pause_pipe[0] = -1;
    1778 
    1779                 status = reinit_after_fork(msg_ctx, ev, procid_self(), true);
    1780 
    1781                 if (!NT_STATUS_IS_OK(status)) {
    1782                         DEBUG(0,("reinit_after_fork() failed\n"));
    1783                         smb_panic("reinit_after_fork() failed");
    1784                 }
    1785 
    1786                 se = tevent_add_signal(ev, ev, SIGTERM, 0,
    1787                                        printing_sig_term_handler,
    1788                                        NULL);
    1789                 if (se == NULL) {
    1790                         smb_panic("failed to setup SIGTERM handler");
    1791                 }
    1792                 se = tevent_add_signal(ev, ev, SIGHUP, 0,
    1793                                        printing_sig_hup_handler,
    1794                                        msg_ctx);
    1795                 if (se == NULL) {
    1796                         smb_panic("failed to setup SIGHUP handler");
    1797                 }
    1798 
    1799                 if (!serverid_register(procid_self(),
    1800                                        FLAG_MSG_GENERAL|FLAG_MSG_SMBD
    1801                                        |FLAG_MSG_PRINT_GENERAL)) {
    1802                         exit(1);
    1803                 }
    1804 
    1805                 if (!locking_init()) {
    1806                         exit(1);
    1807                 }
    1808 
    1809                 messaging_register(msg_ctx, NULL, MSG_PRINTER_UPDATE,
    1810                                    print_queue_receive);
    1811                 messaging_register(msg_ctx, NULL, MSG_SMB_CONF_UPDATED,
    1812                                    printing_conf_updated);
    1813 
    1814                 fde = tevent_add_fd(ev, ev, pause_pipe[1], TEVENT_FD_READ,
    1815                                     printing_pause_fd_handler,
    1816                                     NULL);
    1817                 if (!fde) {
    1818                         DEBUG(0,("tevent_add_fd() failed for pause_pipe\n"));
    1819                         smb_panic("tevent_add_fd() failed for pause_pipe");
    1820                 }
    1821 
    1822                 /* reload on startup to ensure parent smbd is refreshed */
    1823                 pcap_cache_reload(server_event_context(),
    1824                                   smbd_messaging_context(),
    1825                                   &reload_pcap_change_notify);
    1826 
    1827                 if (!(event_add_idle(ev, NULL,
    1828                                      timeval_set(SMBD_HOUSEKEEPING_INTERVAL, 0),
    1829                                      "printer_housekeeping",
    1830                                      printer_housekeeping_fn,
    1831                                      NULL))) {
    1832                         DEBUG(0, ("Could not add printing housekeeping event\n"));
    1833                         exit(1);
    1834                 }
    1835 
    1836                 DEBUG(5,("start_background_queue: background LPQ thread waiting for messages\n"));
    1837                 ret = tevent_loop_wait(ev);
    1838                 /* should not be reached */
    1839                 DEBUG(0,("background_queue: tevent_loop_wait() exited with %d - %s\n",
    1840                          ret, (ret == 0) ? "out of events" : strerror(errno)));
    1841                 exit(1);
    1842         }
    1843 
    1844         close(pause_pipe[1]);
    1845 }
    1846 
    18471688/****************************************************************************
    18481689update the internal database from the system print queue for a queue
    18491690****************************************************************************/
     1691
     1692extern pid_t background_lpq_updater_pid;
    18501693
    18511694static void print_queue_update(struct messaging_context *msg_ctx,
     
    18561699        char *lpqcommand = NULL;
    18571700        char *lprmcommand = NULL;
    1858         uint8 *buffer = NULL;
     1701        uint8_t *buffer = NULL;
    18591702        size_t len = 0;
    18601703        size_t newlen;
     
    18691712
    18701713        lpqcommand = talloc_string_sub2(ctx,
    1871                         lp_lpqcommand(snum),
     1714                        lp_lpq_command(talloc_tos(), snum),
    18721715                        "%p",
    1873                         lp_printername(snum),
     1716                        lp_printername(talloc_tos(), snum),
    18741717                        false, false, false);
    18751718        if (!lpqcommand) {
     
    18771720        }
    18781721        lpqcommand = talloc_sub_advanced(ctx,
    1879                         lp_servicename(snum),
     1722                        lp_servicename(talloc_tos(), snum),
    18801723                        current_user_info.unix_name,
    18811724                        "",
     
    18891732
    18901733        lprmcommand = talloc_string_sub2(ctx,
    1891                         lp_lprmcommand(snum),
     1734                        lp_lprm_command(talloc_tos(), snum),
    18921735                        "%p",
    1893                         lp_printername(snum),
     1736                        lp_printername(talloc_tos(), snum),
    18941737                        false, false, false);
    18951738        if (!lprmcommand) {
     
    18971740        }
    18981741        lprmcommand = talloc_sub_advanced(ctx,
    1899                         lp_servicename(snum),
     1742                        lp_servicename(talloc_tos(), snum),
    19001743                        current_user_info.unix_name,
    19011744                        "",
     
    19331776                lprmcommand );
    19341777
    1935         buffer = SMB_XMALLOC_ARRAY( uint8, len );
     1778        buffer = SMB_XMALLOC_ARRAY( uint8_t, len );
    19361779
    19371780        /* now pack the buffer */
     
    19721815
    19731816        messaging_send_buf(msg_ctx, pid_to_procid(background_lpq_updater_pid),
    1974                            MSG_PRINTER_UPDATE, (uint8 *)buffer, len);
     1817                           MSG_PRINTER_UPDATE, (uint8_t *)buffer, len);
    19751818
    19761819        SAFE_FREE( buffer );
     
    19901833        TDB_CONTEXT *tdb = NULL;
    19911834        const char *printername;
    1992         uint32 mypid = (uint32)sys_getpid();
     1835        uint32_t mypid = (uint32_t)getpid();
    19931836        bool ret = False;
    19941837        size_t i;
     
    20041847
    20051848                for ( idx=0; idx<num_services; idx++ ) {
    2006                         if (lp_snum_ok(idx) && lp_print_ok(idx) )
     1849                        if (lp_snum_ok(idx) && lp_printable(idx) )
    20071850                                print_notify_register_pid(idx);
    20081851                }
     
    20191862        }
    20201863
    2021         if (tdb_lock_bystring_with_timeout(tdb, NOTIFY_PID_LIST_KEY, 10) == -1) {
     1864        if (tdb_lock_bystring_with_timeout(tdb, NOTIFY_PID_LIST_KEY, 10) != 0) {
    20221865                DEBUG(0,("print_notify_register_pid: Failed to lock printer %s\n",
    20231866                                        printername));
     
    20331876        for (i = 0; i < data.dsize; i += 8) {
    20341877                if (IVAL(data.dptr,i) == mypid) {
    2035                         uint32 new_refcount = IVAL(data.dptr, i+4) + 1;
     1878                        uint32_t new_refcount = IVAL(data.dptr, i+4) + 1;
    20361879                        SIVAL(data.dptr, i+4, new_refcount);
    20371880                        break;
     
    20411884        if (i == data.dsize) {
    20421885                /* We weren't in the list. Realloc. */
    2043                 data.dptr = (uint8 *)SMB_REALLOC(data.dptr, data.dsize + 8);
     1886                data.dptr = (uint8_t *)SMB_REALLOC(data.dptr, data.dsize + 8);
    20441887                if (!data.dptr) {
    20451888                        DEBUG(0,("print_notify_register_pid: Relloc fail for printer %s\n",
     
    20531896
    20541897        /* Store back the record. */
    2055         if (tdb_store_bystring(tdb, NOTIFY_PID_LIST_KEY, data, TDB_REPLACE) == -1) {
     1898        if (tdb_store_bystring(tdb, NOTIFY_PID_LIST_KEY, data, TDB_REPLACE) != 0) {
    20561899                DEBUG(0,("print_notify_register_pid: Failed to update pid \
    20571900list for printer %s\n", printername));
     
    20811924        TDB_CONTEXT *tdb = NULL;
    20821925        const char *printername;
    2083         uint32 mypid = (uint32)sys_getpid();
     1926        uint32_t mypid = (uint32_t)getpid();
    20841927        size_t i;
    20851928        bool ret = False;
     
    20941937
    20951938                for ( idx=0; idx<num_services; idx++ ) {
    2096                         if ( lp_snum_ok(idx) && lp_print_ok(idx) )
     1939                        if ( lp_snum_ok(idx) && lp_printable(idx) )
    20971940                                print_notify_deregister_pid(idx);
    20981941                }
     
    21091952        }
    21101953
    2111         if (tdb_lock_bystring_with_timeout(tdb, NOTIFY_PID_LIST_KEY, 10) == -1) {
     1954        if (tdb_lock_bystring_with_timeout(tdb, NOTIFY_PID_LIST_KEY, 10) != 0) {
    21121955                DEBUG(0,("print_notify_register_pid: Failed to lock \
    21131956printer %s database\n", printername));
     
    21231966        for (i = 0; i < data.dsize; ) {
    21241967                if (IVAL(data.dptr,i) == mypid) {
    2125                         uint32 refcount = IVAL(data.dptr, i+4);
     1968                        uint32_t refcount = IVAL(data.dptr, i+4);
    21261969
    21271970                        refcount--;
     
    21431986
    21441987        /* Store back the record. */
    2145         if (tdb_store_bystring(tdb, NOTIFY_PID_LIST_KEY, data, TDB_REPLACE) == -1) {
     1988        if (tdb_store_bystring(tdb, NOTIFY_PID_LIST_KEY, data, TDB_REPLACE) != 0) {
    21461989                DEBUG(0,("print_notify_register_pid: Failed to update pid \
    21471990list for printer %s\n", printername));
     
    21642007****************************************************************************/
    21652008
    2166 bool print_job_exists(const char* sharename, uint32 jobid)
     2009bool print_job_exists(const char* sharename, uint32_t jobid)
    21672010{
    21682011        struct tdb_print_db *pdb = get_print_db_byname(sharename);
     
    21852028struct spoolss_DeviceMode *print_job_devmode(TALLOC_CTX *mem_ctx,
    21862029                                             const char *sharename,
    2187                                              uint32 jobid)
     2030                                             uint32_t jobid)
    21882031{
    21892032        struct printjob *pjob = print_job_find(mem_ctx, sharename, jobid);
     
    22012044bool print_job_set_name(struct tevent_context *ev,
    22022045                        struct messaging_context *msg_ctx,
    2203                         const char *sharename, uint32 jobid, const char *name)
     2046                        const char *sharename, uint32_t jobid, const char *name)
    22042047{
    22052048        struct printjob *pjob;
     
    22112054
    22122055        pjob = print_job_find(tmp_ctx, sharename, jobid);
    2213         if (!pjob || pjob->pid != sys_getpid()) {
     2056        if (!pjob || pjob->pid != getpid()) {
    22142057                ret = false;
    22152058                goto err_out;
     
    22322075
    22332076        pjob = print_job_find(mem_ctx, sharename, jobid);
    2234         if (!pjob || pjob->pid != sys_getpid()) {
     2077        if (!pjob || pjob->pid != getpid()) {
    22352078                return false;
    22362079        }
     
    22452088***************************************************************************/
    22462089
    2247 static bool remove_from_jobs_added(const char* sharename, uint32 jobid)
     2090static bool remove_from_jobs_added(const char* sharename, uint32_t jobid)
    22482091{
    22492092        struct tdb_print_db *pdb = get_print_db_byname(sharename);
     
    22612104        key = string_tdb_data("INFO/jobs_added");
    22622105
    2263         if (tdb_chainlock_with_timeout(pdb->tdb, key, 5) == -1)
     2106        if (tdb_chainlock_with_timeout(pdb->tdb, key, 5) != 0)
    22642107                goto out;
    22652108
     
    22732116        job_count = data.dsize / 4;
    22742117        for (i = 0; i < job_count; i++) {
    2275                 uint32 ch_jobid;
     2118                uint32_t ch_jobid;
    22762119
    22772120                ch_jobid = IVAL(data.dptr, i*4);
     
    22802123                                memmove(data.dptr + (i*4), data.dptr + (i*4) + 4, (job_count - i - 1)*4 );
    22812124                        data.dsize -= 4;
    2282                         if (tdb_store(pdb->tdb, key, data, TDB_REPLACE) == -1)
     2125                        if (tdb_store(pdb->tdb, key, data, TDB_REPLACE) != 0)
    22832126                                goto out;
    22842127                        break;
     
    23062149static bool print_job_delete1(struct tevent_context *ev,
    23072150                              struct messaging_context *msg_ctx,
    2308                               int snum, uint32 jobid)
     2151                              int snum, uint32_t jobid)
    23092152{
    23102153        const char* sharename = lp_const_servicename(snum);
     
    23502193        {
    23512194                result = (*(current_printif->job_delete))(
    2352                         lp_printername(snum),
    2353                         lp_lprmcommand(snum),
     2195                        lp_printername(talloc_tos(), snum),
     2196                        lp_lprm_command(talloc_tos(), snum),
    23542197                        pjob);
    23552198
     
    23842227****************************************************************************/
    23852228
    2386 static bool is_owner(const struct auth_serversupplied_info *server_info,
     2229static bool is_owner(const struct auth_session_info *server_info,
    23872230                     const char *servicename,
    2388                      uint32 jobid)
     2231                     uint32_t jobid)
    23892232{
    23902233        struct printjob *pjob;
     
    24012244        }
    24022245
    2403         ret = strequal(pjob->user, server_info->sanitized_username);
     2246        ret = strequal(pjob->user, server_info->unix_info->sanitized_username);
    24042247err_out:
    24052248        talloc_free(tmp_ctx);
     
    24112254****************************************************************************/
    24122255
    2413 WERROR print_job_delete(const struct auth_serversupplied_info *server_info,
     2256WERROR print_job_delete(const struct auth_session_info *server_info,
    24142257                        struct messaging_context *msg_ctx,
    24152258                        int snum, uint32_t jobid)
     
    24302273
    24312274        if (!owner &&
    2432             !print_access_check(server_info, msg_ctx, snum,
    2433                                 JOB_ACCESS_ADMINISTER)) {
    2434                 DEBUG(3, ("delete denied by security descriptor\n"));
    2435 
    2436                 /* BEGIN_ADMIN_LOG */
    2437                 sys_adminlog( LOG_ERR,
    2438                               "Permission denied-- user not allowed to delete, \
    2439 pause, or resume print job. User name: %s. Printer name: %s.",
    2440                               uidtoname(server_info->utok.uid),
    2441                               lp_printername(snum) );
    2442                 /* END_ADMIN_LOG */
     2275            !W_ERROR_IS_OK(print_access_check(server_info, msg_ctx, snum,
     2276                                              JOB_ACCESS_ADMINISTER))) {
     2277                DEBUG(0, ("print job delete denied."
     2278                          "User name: %s, Printer name: %s.",
     2279                          uidtoname(server_info->unix_token->uid),
     2280                          lp_printername(tmp_ctx, snum)));
    24432281
    24442282                werr = WERR_ACCESS_DENIED;
     
    24902328****************************************************************************/
    24912329
    2492 WERROR print_job_pause(const struct auth_serversupplied_info *server_info,
     2330WERROR print_job_pause(const struct auth_session_info *server_info,
    24932331                     struct messaging_context *msg_ctx,
    2494                      int snum, uint32 jobid)
     2332                     int snum, uint32_t jobid)
    24952333{
    24962334        const char* sharename = lp_const_servicename(snum);
     
    25202358
    25212359        if (!is_owner(server_info, lp_const_servicename(snum), jobid) &&
    2522             !print_access_check(server_info, msg_ctx, snum,
    2523                                 JOB_ACCESS_ADMINISTER)) {
    2524                 DEBUG(3, ("pause denied by security descriptor\n"));
    2525 
    2526                 /* BEGIN_ADMIN_LOG */
    2527                 sys_adminlog( LOG_ERR,
    2528                         "Permission denied-- user not allowed to delete, \
    2529 pause, or resume print job. User name: %s. Printer name: %s.",
    2530                               uidtoname(server_info->utok.uid),
    2531                               lp_printername(snum) );
    2532                 /* END_ADMIN_LOG */
     2360            !W_ERROR_IS_OK(print_access_check(server_info, msg_ctx, snum,
     2361                                              JOB_ACCESS_ADMINISTER))) {
     2362                DEBUG(0, ("print job pause denied."
     2363                          "User name: %s, Printer name: %s.",
     2364                          uidtoname(server_info->unix_token->uid),
     2365                          lp_printername(tmp_ctx, snum)));
    25332366
    25342367                werr = WERR_ACCESS_DENIED;
     
    25632396****************************************************************************/
    25642397
    2565 WERROR print_job_resume(const struct auth_serversupplied_info *server_info,
     2398WERROR print_job_resume(const struct auth_session_info *server_info,
    25662399                      struct messaging_context *msg_ctx,
    2567                       int snum, uint32 jobid)
     2400                      int snum, uint32_t jobid)
    25682401{
    25692402        const char *sharename = lp_const_servicename(snum);
     
    25922425
    25932426        if (!is_owner(server_info, lp_const_servicename(snum), jobid) &&
    2594             !print_access_check(server_info, msg_ctx, snum,
    2595                                 JOB_ACCESS_ADMINISTER)) {
    2596                 DEBUG(3, ("resume denied by security descriptor\n"));
    2597 
    2598                 /* BEGIN_ADMIN_LOG */
    2599                 sys_adminlog( LOG_ERR,
    2600                          "Permission denied-- user not allowed to delete, \
    2601 pause, or resume print job. User name: %s. Printer name: %s.",
    2602                               uidtoname(server_info->utok.uid),
    2603                               lp_printername(snum) );
    2604                 /* END_ADMIN_LOG */
     2427            !W_ERROR_IS_OK(print_access_check(server_info, msg_ctx, snum,
     2428                                              JOB_ACCESS_ADMINISTER))) {
     2429                DEBUG(0, ("print job resume denied."
     2430                          "User name: %s, Printer name: %s.",
     2431                          uidtoname(server_info->unix_token->uid),
     2432                          lp_printername(tmp_ctx, snum)));
     2433
    26052434                werr = WERR_ACCESS_DENIED;
    26062435                goto err_out;
     
    26342463ssize_t print_job_write(struct tevent_context *ev,
    26352464                        struct messaging_context *msg_ctx,
    2636                         int snum, uint32 jobid, const char *buf, size_t size)
     2465                        int snum, uint32_t jobid, const char *buf, size_t size)
    26372466{
    26382467        const char* sharename = lp_const_servicename(snum);
     
    26512480
    26522481        /* don't allow another process to get this info - it is meaningless */
    2653         if (pjob->pid != sys_getpid()) {
     2482        if (pjob->pid != getpid()) {
    26542483                return_code = -1;
    26552484                goto err_out;
     
    27382567
    27392568static WERROR allocate_print_jobid(struct tdb_print_db *pdb, int snum,
    2740                                    const char *sharename, uint32 *pjobid)
     2569                                   const char *sharename, uint32_t *pjobid)
    27412570{
    27422571        int i;
    2743         uint32 jobid;
     2572        uint32_t jobid;
    27442573        enum TDB_ERROR terr;
    27452574        int ret;
    27462575
    2747         *pjobid = (uint32)-1;
     2576        *pjobid = (uint32_t)-1;
    27482577
    27492578        for (i = 0; i < 3; i++) {
     
    27512580                ret = tdb_lock_bystring_with_timeout(pdb->tdb,
    27522581                                                     "INFO/nextjob", 20);
    2753                 if (ret == -1) {
     2582                if (ret != 0) {
    27542583                        DEBUG(0, ("allocate_print_jobid: "
    27552584                                  "Failed to lock printing database %s\n",
     
    27792608
    27802609                ret = tdb_store_int32(pdb->tdb, "INFO/nextjob", jobid);
    2781                 if (ret == -1) {
     2610                if (ret != 0) {
    27822611                        terr = tdb_error(pdb->tdb);
    27832612                        DEBUG(3, ("allocate_print_jobid: "
     
    28122641                dum.dsize = 0;
    28132642                if (tdb_store(pdb->tdb, print_key(jobid, &tmp), dum,
    2814                               TDB_INSERT) == -1) {
     2643                              TDB_INSERT) != 0) {
    28152644                        DEBUG(3, ("allocate_print_jobid: "
    28162645                                  "jobid (%d) failed to store placeholder.\n",
     
    28292658***************************************************************************/
    28302659
    2831 static bool add_to_jobs_added(struct tdb_print_db *pdb, uint32 jobid)
     2660static bool add_to_jobs_added(struct tdb_print_db *pdb, uint32_t jobid)
    28322661{
    28332662        TDB_DATA data;
    2834         uint32 store_jobid;
     2663        uint32_t store_jobid;
    28352664
    28362665        SIVAL(&store_jobid, 0, jobid);
    2837         data.dptr = (uint8 *)&store_jobid;
     2666        data.dptr = (uint8_t *)&store_jobid;
    28382667        data.dsize = 4;
    28392668
     
    28492678***************************************************************************/
    28502679
    2851 static WERROR print_job_checks(const struct auth_serversupplied_info *server_info,
     2680static WERROR print_job_checks(const struct auth_session_info *server_info,
    28522681                               struct messaging_context *msg_ctx,
    28532682                               int snum, int *njobs)
     
    28582687        int ret;
    28592688
    2860         if (!print_access_check(server_info, msg_ctx, snum,
    2861                                 PRINTER_ACCESS_USE)) {
     2689        if (!W_ERROR_IS_OK(print_access_check(server_info, msg_ctx, snum,
     2690                                              PRINTER_ACCESS_USE))) {
    28622691                DEBUG(3, ("print_job_checks: "
    28632692                          "job start denied by security descriptor\n"));
     
    28722701
    28732702        /* see if we have sufficient disk space */
    2874         if (lp_minprintspace(snum)) {
    2875                 minspace = lp_minprintspace(snum);
    2876                 ret = sys_fsusage(lp_pathname(snum), &dspace, &dsize);
     2703        if (lp_min_print_space(snum)) {
     2704                minspace = lp_min_print_space(snum);
     2705                ret = sys_fsusage(lp_path(talloc_tos(), snum), &dspace, &dsize);
    28772706                if (ret == 0 && dspace < 2*minspace) {
    28782707                        DEBUG(3, ("print_job_checks: "
     
    29132742        const char *path;
    29142743        int len;
     2744        mode_t mask;
    29152745
    29162746        /* if this file is within the printer path, it means that smbd
     
    29192749         * already already there */
    29202750        if (output_file) {
    2921                 path = lp_pathname(snum);
     2751                path = lp_path(talloc_tos(), snum);
    29222752                len = strlen(path);
    29232753                if (strncmp(output_file, path, len) == 0 &&
     
    29372767
    29382768                        DEBUG(3, ("print_job_spool_file:"
    2939                                   "External spooling activated"));
     2769                                  "External spooling activated\n"));
    29402770
    29412771                        /* we do not open the file until spooling is done */
     
    29482778
    29492779        slprintf(pjob->filename, sizeof(pjob->filename)-1,
    2950                  "%s/%sXXXXXX", lp_pathname(snum), PRINT_SPOOL_PREFIX);
     2780                 "%s/%sXXXXXX", lp_path(talloc_tos(), snum),
     2781                 PRINT_SPOOL_PREFIX);
     2782        mask = umask(S_IRWXO | S_IRWXG);
    29512783        pjob->fd = mkstemp(pjob->filename);
     2784        umask(mask);
    29522785
    29532786        if (pjob->fd == -1) {
     
    29742807***************************************************************************/
    29752808
    2976 WERROR print_job_start(const struct auth_serversupplied_info *server_info,
     2809WERROR print_job_start(const struct auth_session_info *server_info,
    29772810                       struct messaging_context *msg_ctx,
    29782811                       const char *clientmachine,
     
    29922825        }
    29932826
    2994         path = lp_pathname(snum);
     2827        path = lp_path(talloc_tos(), snum);
    29952828
    29962829        werr = print_job_checks(server_info, msg_ctx, snum, &njobs);
     
    30132846        ZERO_STRUCT(pjob);
    30142847
    3015         pjob.pid = sys_getpid();
     2848        pjob.pid = getpid();
    30162849        pjob.jobid = jobid;
    30172850        pjob.sysjob = -1;
     
    30292862
    30302863        fstrcpy(pjob.user, lp_printjob_username(snum));
    3031         standard_sub_advanced(sharename, server_info->sanitized_username,
    3032                               path, server_info->utok.gid,
    3033                               server_info->sanitized_username,
    3034                               server_info->info3->base.domain.string,
    3035                               pjob.user, sizeof(pjob.user)-1);
    3036         /* ensure NULL termination */
    3037         pjob.user[sizeof(pjob.user)-1] = '\0';
     2864        standard_sub_advanced(sharename, server_info->unix_info->sanitized_username,
     2865                              path, server_info->unix_token->gid,
     2866                              server_info->unix_info->sanitized_username,
     2867                              server_info->info->domain_name,
     2868                              pjob.user, sizeof(pjob.user));
    30382869
    30392870        fstrcpy(pjob.queuename, lp_const_servicename(snum));
     
    30752906
    30762907void print_job_endpage(struct messaging_context *msg_ctx,
    3077                        int snum, uint32 jobid)
     2908                       int snum, uint32_t jobid)
    30782909{
    30792910        const char* sharename = lp_const_servicename(snum);
     
    30892920        }
    30902921        /* don't allow another process to get this info - it is meaningless */
    3091         if (pjob->pid != sys_getpid()) {
     2922        if (pjob->pid != getpid()) {
    30922923                goto err_out;
    30932924        }
     
    31062937
    31072938NTSTATUS print_job_end(struct messaging_context *msg_ctx, int snum,
    3108                        uint32 jobid, enum file_close_type close_type)
     2939                       uint32_t jobid, enum file_close_type close_type)
    31092940{
    31102941        const char* sharename = lp_const_servicename(snum);
     
    31262957        }
    31272958
    3128         if (pjob->spooled || pjob->pid != sys_getpid()) {
     2959        if (pjob->spooled || pjob->pid != getpid()) {
    31292960                status = NT_STATUS_ACCESS_DENIED;
    31302961                goto err_out;
     
    31843015        /* don't strip out characters like '$' from the printername */
    31853016        lpq_cmd = talloc_string_sub2(tmp_ctx,
    3186                                      lp_lpqcommand(snum),
     3017                                     lp_lpq_command(talloc_tos(), snum),
    31873018                                     "%p",
    3188                                      lp_printername(snum),
     3019                                     lp_printername(talloc_tos(), snum),
    31893020                                     false, false, false);
    31903021        if (lpq_cmd == NULL) {
     
    31933024        }
    31943025        lpq_cmd = talloc_sub_advanced(tmp_ctx,
    3195                                       lp_servicename(snum),
     3026                                      lp_servicename(talloc_tos(), snum),
    31963027                                      current_user_info.unix_name,
    31973028                                      "",
     
    32463077        TDB_DATA data, cgdata, jcdata;
    32473078        print_queue_struct *queue = NULL;
    3248         uint32 qcount = 0;
    3249         uint32 extra_count = 0;
     3079        uint32_t qcount = 0;
     3080        uint32_t extra_count = 0;
    32503081        uint32_t changed_count = 0;
    32513082        int total_count = 0;
    32523083        size_t len = 0;
    3253         uint32 i;
    3254         int max_reported_jobs = lp_max_reported_jobs(snum);
    3255         bool ret = False;
    3256         const char* sharename = lp_servicename(snum);
     3084        uint32_t i;
     3085        int max_reported_jobs = lp_max_reported_print_jobs(snum);
     3086        bool ret = false;
     3087        const char* sharename = lp_servicename(talloc_tos(), snum);
    32573088        TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx);
    32583089        if (tmp_ctx == NULL) {
     
    32973128        /* Retrieve the linearised queue data. */
    32983129
    3299         for( i = 0; i < qcount; i++) {
    3300                 uint32 qjob, qsize, qpage_count, qstatus, qpriority, qtime;
     3130        for(i = 0; i < qcount; i++) {
     3131                uint32_t qjob, qsize, qpage_count, qstatus, qpriority, qtime;
    33013132                len += tdb_unpack(data.dptr + len, data.dsize - len, "ddddddff",
    33023133                                &qjob,
     
    33193150
    33203151        /* Add new jobids to the queue. */
    3321         for( i = 0; i < extra_count; i++) {
    3322                 uint32 jobid;
     3152        for (i = 0; i < extra_count; i++) {
     3153                uint32_t jobid;
    33233154                struct printjob *pjob;
    33243155
     
    33323163                }
    33333164
    3334                 queue[total_count].sysjob = jobid;
     3165                queue[total_count].sysjob = pjob->sysjob;
    33353166                queue[total_count].size = pjob->size;
    33363167                queue[total_count].page_count = pjob->page_count;
     
    33473178        for (i = 0; i < changed_count; i++) {
    33483179                uint32_t jobid = IVAL(jcdata.dptr, i * 4);
     3180                struct printjob *pjob;
    33493181                uint32_t j;
    33503182                bool found = false;
    33513183
     3184                pjob = print_job_find(tmp_ctx, sharename, jobid);
     3185                if (pjob == NULL) {
     3186                        DEBUG(5,("get_stored_queue_info: failed to find "
     3187                                 "changed job = %u\n",
     3188                                 (unsigned int)jobid));
     3189                        remove_from_jobs_changed(sharename, jobid);
     3190                        continue;
     3191                }
     3192
    33523193                for (j = 0; j < total_count; j++) {
    3353                         if (queue[j].sysjob == jobid) {
     3194                        if (queue[j].sysjob == pjob->sysjob) {
    33543195                                found = true;
    33553196                                break;
     
    33583199
    33593200                if (found) {
    3360                         struct printjob *pjob;
    3361 
    33623201                        DEBUG(5,("get_stored_queue_info: changed job: %u\n",
    3363                                  (unsigned int) jobid));
    3364 
    3365                         pjob = print_job_find(tmp_ctx, sharename, jobid);
    3366                         if (pjob == NULL) {
    3367                                 DEBUG(5,("get_stored_queue_info: failed to find "
    3368                                          "changed job = %u\n",
    3369                                          (unsigned int) jobid));
    3370                                 remove_from_jobs_changed(sharename, jobid);
    3371                                 continue;
    3372                         }
    3373 
    3374                         queue[j].sysjob = jobid;
     3202                                 (unsigned int)jobid));
     3203
     3204                        queue[j].sysjob = pjob->sysjob;
    33753205                        queue[j].size = pjob->size;
    33763206                        queue[j].page_count = pjob->page_count;
     
    33823212                        talloc_free(pjob);
    33833213
    3384                         DEBUG(5,("get_stored_queue_info: updated queue[%u], jobid: %u, jobname: %s\n",
    3385                                  (unsigned int) j, (unsigned int) jobid, pjob->jobname));
     3214                        DEBUG(5,("updated queue[%u], jobid: %u, sysjob: %u, "
     3215                                 "jobname: %s\n",
     3216                                 (unsigned int)j, (unsigned int)jobid,
     3217                                 (unsigned int)queue[j].sysjob, pjob->jobname));
    33863218                }
    33873219
     
    34023234        *pcount = total_count;
    34033235
    3404         ret = True;
     3236        ret = true;
    34053237
    34063238  out:
     
    34803312****************************************************************************/
    34813313
    3482 WERROR print_queue_pause(const struct auth_serversupplied_info *server_info,
     3314WERROR print_queue_pause(const struct auth_session_info *server_info,
    34833315                         struct messaging_context *msg_ctx, int snum)
    34843316{
     
    34863318        struct printif *current_printif = get_printer_fns( snum );
    34873319
    3488         if (!print_access_check(server_info, msg_ctx, snum,
    3489                                 PRINTER_ACCESS_ADMINISTER)) {
     3320        if (!W_ERROR_IS_OK(print_access_check(server_info, msg_ctx, snum,
     3321                                              PRINTER_ACCESS_ADMINISTER))) {
    34903322                return WERR_ACCESS_DENIED;
    34913323        }
     
    35173349****************************************************************************/
    35183350
    3519 WERROR print_queue_resume(const struct auth_serversupplied_info *server_info,
     3351WERROR print_queue_resume(const struct auth_session_info *server_info,
    35203352                          struct messaging_context *msg_ctx, int snum)
    35213353{
     
    35233355        struct printif *current_printif = get_printer_fns( snum );
    35243356
    3525         if (!print_access_check(server_info, msg_ctx, snum,
    3526                                 PRINTER_ACCESS_ADMINISTER)) {
     3357        if (!W_ERROR_IS_OK(print_access_check(server_info, msg_ctx, snum,
     3358                                              PRINTER_ACCESS_ADMINISTER))) {
    35273359                return WERR_ACCESS_DENIED;
    35283360        }
     
    35543386****************************************************************************/
    35553387
    3556 WERROR print_queue_purge(const struct auth_serversupplied_info *server_info,
     3388WERROR print_queue_purge(const struct auth_session_info *server_info,
    35573389                         struct messaging_context *msg_ctx, int snum)
    35583390{
     
    35653397        print_queue_update(msg_ctx, snum, True);
    35663398
    3567         can_job_admin = print_access_check(server_info,
    3568                                           msg_ctx,
    3569                                           snum,
    3570                                            JOB_ACCESS_ADMINISTER);
     3399        can_job_admin = W_ERROR_IS_OK(print_access_check(server_info,
     3400                                                        msg_ctx,
     3401                                                        snum,
     3402                                                        JOB_ACCESS_ADMINISTER));
    35713403        njobs = print_queue_status(msg_ctx, snum, &queue, &status);
    35723404
     
    35743406                become_root();
    35753407
    3576         for (i=0;i<njobs;i++) {
    3577                 bool owner = is_owner(server_info, lp_const_servicename(snum),
    3578                                       queue[i].sysjob);
     3408        for (i = 0; i < njobs; i++) {
     3409                struct tdb_print_db *pdb;
     3410                int jobid;
     3411                bool owner;
     3412                pdb = get_print_db_byname(lp_const_servicename(snum));
     3413                if (pdb == NULL) {
     3414                        DEBUG(1, ("failed to find printdb for %s\n",
     3415                                  lp_const_servicename(snum)));
     3416                        continue;
     3417                }
     3418                jobid = sysjob_to_jobid_pdb(pdb, queue[i].sysjob);
     3419                if (jobid == (uint32_t)-1) {
     3420                        DEBUG(2, ("jobid for system job %d not found\n",
     3421                                  queue[i].sysjob));
     3422                        continue;       /* unix job */
     3423                }
     3424                owner = is_owner(server_info, lp_const_servicename(snum),
     3425                                 jobid);
    35793426
    35803427                if (owner || can_job_admin) {
    35813428                        print_job_delete1(server_event_context(), msg_ctx,
    3582                                           snum, queue[i].sysjob);
     3429                                          snum, jobid);
    35833430                }
    35843431        }
  • vendor/current/source3/printing/printing_db.c

    r740 r988  
    2121
    2222#include "includes.h"
     23#include "system/passwd.h" /* uid_wrapper */
    2324#include "system/filesys.h"
    2425#include "printing.h"
     
    3839        char *printdb_path = NULL;
    3940        bool done_become_root = False;
     41        char *print_cache_path;
     42        int ret;
    4043
    4144        SMB_ASSERT(printername != NULL);
     
    6568                                continue;
    6669                        if (p->tdb) {
    67                                 if (tdb_close(print_db_head->tdb)) {
     70                                if (tdb_close(p->tdb)) {
    6871                                        DEBUG(0,("get_print_db: Failed to close tdb for printer %s\n",
    69                                                                 print_db_head->printer_name ));
     72                                                                p->printer_name ));
    7073                                        return NULL;
    7174                                }
     
    9396        }
    9497
    95         if (asprintf(&printdb_path, "%s%s.tdb",
    96                                 cache_path("printing/"),
    97                                 printername) < 0) {
     98        print_cache_path = cache_path("printing/");
     99        if (print_cache_path == NULL) {
     100                DLIST_REMOVE(print_db_head, p);
     101                SAFE_FREE(p);
     102                return NULL;
     103        }
     104        ret = asprintf(&printdb_path, "%s%s.tdb",
     105                       print_cache_path, printername);
     106        TALLOC_FREE(print_cache_path);
     107        if (ret < 0) {
    98108                DLIST_REMOVE(print_db_head, p);
    99109                SAFE_FREE(p);
     
    161171****************************************************************************/
    162172
    163 struct TDB_DATA get_printer_notify_pid_list(struct tdb_context *tdb, const char *printer_name, bool cleanlist)
     173TDB_DATA get_printer_notify_pid_list(struct tdb_context *tdb, const char *printer_name, bool cleanlist)
    164174{
    165175        TDB_DATA data;
     
    193203                pid_t pid = (pid_t)IVAL(data.dptr, i);
    194204
    195                 if (pid == sys_getpid())
     205                if (pid == getpid())
    196206                        continue;
    197207
  • vendor/current/source3/printing/printspoolss.c

    r746 r988  
    1919
    2020#include "includes.h"
     21#include "system/filesys.h"
    2122#include "printing.h"
    2223#include "rpc_client/rpc_client.h"
     
    2627#include "../libcli/security/security.h"
    2728
     29struct print_file_data {
     30        char *svcname;
     31        char *docname;
     32        char *filename;
     33        struct policy_handle handle;
     34        uint32_t jobid;
     35        uint16_t rap_jobid;
     36};
     37
     38uint16_t print_spool_rap_jobid(struct print_file_data *print_file)
     39{
     40        if (print_file == NULL) {
     41                return 0;
     42        }
     43
     44        return print_file->rap_jobid;
     45}
     46
    2847void print_spool_terminate(struct connection_struct *conn,
    2948                           struct print_file_data *print_file);
     
    4059NTSTATUS print_spool_open(files_struct *fsp,
    4160                          const char *fname,
    42                           uint16_t current_vuid)
     61                          uint64_t current_vuid)
    4362{
    4463        NTSTATUS status;
     
    4766        struct dcerpc_binding_handle *b = NULL;
    4867        struct spoolss_DevmodeContainer devmode_ctr;
    49         union spoolss_DocumentInfo info;
     68        struct spoolss_DocumentInfoCtr info_ctr;
     69        struct spoolss_DocumentInfo1 *info1;
    5070        int fd = -1;
    5171        WERROR werr;
     72        mode_t mask;
    5273
    5374        tmp_ctx = talloc_new(fsp);
     
    6182                goto done;
    6283        }
    63         pf->svcname = talloc_strdup(pf, lp_servicename(SNUM(fsp->conn)));
     84        pf->svcname = lp_servicename(pf, SNUM(fsp->conn));
    6485
    6586        /* the document name is derived from the file name.
     
    101122
    102123        pf->filename = talloc_asprintf(pf, "%s/%sXXXXXX",
    103                                         lp_pathname(SNUM(fsp->conn)),
     124                                        lp_path(talloc_tos(),
     125                                                SNUM(fsp->conn)),
    104126                                        PRINT_SPOOL_PREFIX);
    105127        if (!pf->filename) {
     
    108130        }
    109131        errno = 0;
     132        mask = umask(S_IRWXO | S_IRWXG);
    110133        fd = mkstemp(pf->filename);
     134        umask(mask);
    111135        if (fd == -1) {
    112136                if (errno == EACCES) {
     
    131155
    132156        status = rpc_pipe_open_interface(fsp->conn,
    133                                          &ndr_table_spoolss.syntax_id,
     157                                         &ndr_table_spoolss,
    134158                                         fsp->conn->session_info,
    135                                          &fsp->conn->sconn->client_id,
     159                                         fsp->conn->sconn->remote_address,
    136160                                         fsp->conn->sconn->msg_ctx,
    137161                                         &fsp->conn->spoolss_pipe);
     
    155179        }
    156180
    157         info.info1 = talloc(tmp_ctx, struct spoolss_DocumentInfo1);
    158         if (!info.info1) {
    159                 status = NT_STATUS_NO_MEMORY;
    160                 goto done;
    161         }
    162         info.info1->document_name = pf->docname;
    163         info.info1->output_file = pf->filename;
    164         info.info1->datatype = "RAW";
    165 
    166         status = dcerpc_spoolss_StartDocPrinter(b, tmp_ctx, &pf->handle,
    167                                                 1, info, &pf->jobid, &werr);
     181        info1 = talloc(tmp_ctx, struct spoolss_DocumentInfo1);
     182        if (info1 == NULL) {
     183                status = NT_STATUS_NO_MEMORY;
     184                goto done;
     185        }
     186        info1->document_name = pf->docname;
     187        info1->output_file = pf->filename;
     188        info1->datatype = "RAW";
     189
     190        info_ctr.level = 1;
     191        info_ctr.info.info1 = info1;
     192
     193        status = dcerpc_spoolss_StartDocPrinter(b, tmp_ctx,
     194                                                &pf->handle,
     195                                                &info_ctr,
     196                                                &pf->jobid,
     197                                                &werr);
    168198        if (!NT_STATUS_IS_OK(status)) {
    169199                goto done;
     
    183213
    184214        /* setup a full fsp */
    185         status = create_synthetic_smb_fname(fsp, pf->filename, NULL,
    186                                             NULL, &fsp->fsp_name);
    187         if (!NT_STATUS_IS_OK(status)) {
     215        fsp->fsp_name = synthetic_smb_fname(fsp, pf->filename, NULL, NULL);
     216        if (fsp->fsp_name == NULL) {
     217                status = NT_STATUS_NO_MEMORY;
    188218                goto done;
    189219        }
     
    195225
    196226        fsp->file_id = vfs_file_id_from_sbuf(fsp->conn, &fsp->fsp_name->st);
    197         fsp->mode = fsp->fsp_name->st.st_ex_mode;
    198227        fsp->fh->fd = fd;
    199228
     
    220249                }
    221250                /* We need to delete the job from spoolss too */
    222                 if (pf->jobid) {
     251                if (pf && pf->jobid) {
    223252                        print_spool_terminate(fsp->conn, pf);
    224253                }
     
    230259int print_spool_write(files_struct *fsp,
    231260                      const char *data, uint32_t size,
    232                       SMB_OFF_T offset, uint32_t *written)
     261                      off_t offset, uint32_t *written)
    233262{
    234263        SMB_STRUCT_STAT st;
     
    315344
    316345        status = rpc_pipe_open_interface(conn,
    317                                          &ndr_table_spoolss.syntax_id,
     346                                         &ndr_table_spoolss,
    318347                                         conn->session_info,
    319                                          &conn->sconn->client_id,
     348                                         conn->sconn->remote_address,
    320349                                         conn->sconn->msg_ctx,
    321350                                         &conn->spoolss_pipe);
  • vendor/current/source3/printing/spoolssd.c

    r860 r988  
    22   Unix SMB/Netbios implementation.
    33   SPOOLSS Daemon
    4    Copyright (C) Simo Sorce 2010
     4   Copyright (C) Simo Sorce <idra@samba.org> 2010-2011
    55
    66   This program is free software; you can redistribute it and/or modify
     
    2424#include "include/printing.h"
    2525#include "printing/nt_printing_migrate_internal.h"
     26#include "printing/queue_process.h"
     27#include "printing/pcap.h"
     28#include "printing/load.h"
    2629#include "ntdomain.h"
    2730#include "librpc/gen_ndr/srv_winreg.h"
    2831#include "librpc/gen_ndr/srv_spoolss.h"
    2932#include "rpc_server/rpc_server.h"
    30 #include "rpc_server/rpc_ep_setup.h"
     33#include "rpc_server/rpc_ep_register.h"
     34#include "rpc_server/rpc_config.h"
    3135#include "rpc_server/spoolss/srv_spoolss_nt.h"
     36#include "librpc/rpc/dcerpc_ep.h"
     37#include "lib/server_prefork.h"
     38#include "lib/server_prefork_util.h"
    3239
    3340#define SPOOLSS_PIPE_NAME "spoolss"
    3441#define DAEMON_NAME "spoolssd"
    3542
    36 void start_spoolssd(struct tevent_context *ev_ctx,
    37                     struct messaging_context *msg_ctx);
    38 
    39 static void spoolss_reopen_logs(void)
    40 {
    41         char *lfile = lp_logfile();
     43static struct server_id parent_id;
     44static struct prefork_pool *spoolss_pool = NULL;
     45static int spoolss_child_id = 0;
     46
     47static struct pf_daemon_config default_pf_spoolss_cfg = {
     48        .prefork_status = PFH_INIT,
     49        .min_children = 5,
     50        .max_children = 25,
     51        .spawn_rate = 5,
     52        .max_allowed_clients = 100,
     53        .child_min_life = 60 /* 1 minute minimum life time */
     54};
     55static struct pf_daemon_config pf_spoolss_cfg = { 0 };
     56
     57pid_t start_spoolssd(struct tevent_context *ev_ctx,
     58                     struct messaging_context *msg_ctx);
     59
     60static void spoolss_reopen_logs(int child_id)
     61{
     62        char *lfile = lp_logfile(talloc_tos());
     63        char *ext;
    4264        int rc;
    4365
     66        if (child_id) {
     67                rc = asprintf(&ext, "%s.%d", DAEMON_NAME, child_id);
     68        } else {
     69                rc = asprintf(&ext, "%s", DAEMON_NAME);
     70        }
     71
     72        if (rc == -1) {
     73                return;
     74        }
     75
     76        rc = 0;
    4477        if (lfile == NULL || lfile[0] == '\0') {
    45                 rc = asprintf(&lfile, "%s/log.%s", get_dyn_LOGFILEBASE(), DAEMON_NAME);
    46                 if (rc > 0) {
    47                         lp_set_logfile(lfile);
    48                         SAFE_FREE(lfile);
    49                 }
     78                rc = asprintf(&lfile, "%s/log.%s",
     79                              get_dyn_LOGFILEBASE(), ext);
    5080        } else {
    51                 if (strstr(lfile, DAEMON_NAME) == NULL) {
    52                         rc = asprintf(&lfile, "%s.%s", lp_logfile(), DAEMON_NAME);
    53                         if (rc > 0) {
    54                                 lp_set_logfile(lfile);
    55                                 SAFE_FREE(lfile);
     81                if (strstr(lfile, ext) == NULL) {
     82                        if (child_id) {
     83                                rc = asprintf(&lfile, "%s.%d",
     84                                              lp_logfile(talloc_tos()),
     85                                              child_id);
     86                        } else {
     87                                rc = asprintf(&lfile, "%s.%s",
     88                                              lp_logfile(talloc_tos()),
     89                                              ext);
    5690                        }
    5791                }
    5892        }
    5993
     94        if (rc > 0) {
     95                lp_set_logfile(lfile);
     96                SAFE_FREE(lfile);
     97        }
     98
     99        SAFE_FREE(ext);
     100
    60101        reopen_logs();
     102}
     103
     104static void update_conf(struct tevent_context *ev,
     105                        struct messaging_context *msg)
     106{
     107        change_to_root_user();
     108        lp_load_global(get_dyn_CONFIGFILE());
     109        load_printers(ev, msg);
     110
     111        spoolss_reopen_logs(spoolss_child_id);
     112        if (spoolss_child_id == 0) {
     113                pfh_daemon_config(DAEMON_NAME,
     114                                  &pf_spoolss_cfg,
     115                                  &default_pf_spoolss_cfg);
     116                pfh_manage_pool(ev, msg, &pf_spoolss_cfg, spoolss_pool);
     117        }
    61118}
    62119
     
    71128
    72129        DEBUG(10, ("Got message saying smb.conf was updated. Reloading.\n"));
    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();
    88         reload_printers(ev_ctx, msg);
     130        update_conf(ev_ctx, msg);
    89131}
    90132
     
    118160                                    int count,
    119161                                    void *siginfo,
    120                                     void *private_data)
    121 {
    122         struct messaging_context *msg_ctx = talloc_get_type_abort(private_data,
    123                                                                   struct messaging_context);
    124 
    125         change_to_root_user();
     162                                    void *pvt)
     163{
     164        struct messaging_context *msg_ctx;
     165
     166        msg_ctx = talloc_get_type_abort(pvt, struct messaging_context);
     167
    126168        DEBUG(1,("Reloading printers after SIGHUP\n"));
    127         spoolss_reopen_logs();
     169        update_conf(ev, msg_ctx);
     170
     171        /* relay to all children */
     172        if (spoolss_pool) {
     173                prefork_send_signal_to_all(spoolss_pool, SIGHUP);
     174        }
    128175}
    129176
     
    158205}
    159206
    160 void start_spoolssd(struct tevent_context *ev_ctx,
    161                     struct messaging_context *msg_ctx)
    162 {
     207/* Children */
     208
     209static void spoolss_chld_sig_hup_handler(struct tevent_context *ev,
     210                                         struct tevent_signal *se,
     211                                         int signum,
     212                                         int count,
     213                                         void *siginfo,
     214                                         void *pvt)
     215{
     216        struct messaging_context *msg_ctx;
     217
     218        msg_ctx = talloc_get_type_abort(pvt, struct messaging_context);
     219
     220        change_to_root_user();
     221        DEBUG(1,("Reloading printers after SIGHUP\n"));
     222        load_printers(ev, msg_ctx);
     223        spoolss_reopen_logs(spoolss_child_id);
     224}
     225
     226static bool spoolss_setup_chld_hup_handler(struct tevent_context *ev_ctx,
     227                                           struct messaging_context *msg_ctx,
     228                                           struct pf_worker_data *pf)
     229{
     230        struct tevent_signal *se;
     231
     232        se = tevent_add_signal(ev_ctx,
     233                               ev_ctx,
     234                               SIGHUP, 0,
     235                               spoolss_chld_sig_hup_handler,
     236                               msg_ctx);
     237        if (!se) {
     238                DEBUG(1, ("failed to setup SIGHUP handler"));
     239                return false;
     240        }
     241
     242        return true;
     243}
     244
     245static void parent_ping(struct messaging_context *msg_ctx,
     246                        void *private_data,
     247                        uint32_t msg_type,
     248                        struct server_id server_id,
     249                        DATA_BLOB *data)
     250{
     251
     252        /* The fact we received this message is enough to let make the event
     253         * loop if it was idle. spoolss_children_main will cycle through
     254         * spoolss_next_client at least once. That function will take whatever
     255         * action is necessary */
     256
     257        DEBUG(10, ("Got message that the parent changed status.\n"));
     258        return;
     259}
     260
     261static bool spoolss_child_init(struct tevent_context *ev_ctx,
     262                               int child_id, struct pf_worker_data *pf)
     263{
     264        NTSTATUS status;
    163265        struct rpc_srv_callbacks spoolss_cb;
    164         pid_t pid;
    165         NTSTATUS status;
    166         int ret;
    167 
    168         DEBUG(1, ("Forking SPOOLSS Daemon\n"));
    169 
    170         pid = sys_fork();
    171 
    172         if (pid == -1) {
    173                 DEBUG(0, ("Failed to fork SPOOLSS [%s], aborting ...\n",
    174                            strerror(errno)));
    175                 exit(1);
    176         }
    177 
    178         if (pid) {
    179                 /* parent */
    180                 return;
    181         }
    182 
    183         /* child */
    184         close_low_fds(false);
    185 
    186         status = reinit_after_fork(msg_ctx,
    187                                    ev_ctx,
    188                                    procid_self(), true);
     266        struct messaging_context *msg_ctx = server_messaging_context();
     267        bool ok;
     268
     269        status = reinit_after_fork(msg_ctx, ev_ctx, true, "spoolssd-child");
    189270        if (!NT_STATUS_IS_OK(status)) {
    190271                DEBUG(0,("reinit_after_fork() failed\n"));
     
    192273        }
    193274
    194         spoolss_reopen_logs();
    195 
    196         spoolss_setup_sig_term_handler(ev_ctx);
    197         spoolss_setup_sig_hup_handler(ev_ctx, msg_ctx);
    198 
    199         if (!serverid_register(procid_self(),
    200                                 FLAG_MSG_GENERAL|FLAG_MSG_SMBD
    201                                 |FLAG_MSG_PRINT_GENERAL)) {
    202                 exit(1);
     275        spoolss_child_id = child_id;
     276        spoolss_reopen_logs(child_id);
     277
     278        ok = spoolss_setup_chld_hup_handler(ev_ctx, msg_ctx, pf);
     279        if (!ok) {
     280                return false;
     281        }
     282
     283        if (!serverid_register(messaging_server_id(msg_ctx),
     284                                FLAG_MSG_GENERAL |
     285                                FLAG_MSG_PRINT_GENERAL)) {
     286                return false;
    203287        }
    204288
    205289        if (!locking_init()) {
    206                 exit(1);
    207         }
    208 
    209         messaging_register(msg_ctx, NULL,
    210                            MSG_PRINTER_UPDATE, print_queue_receive);
     290                return false;
     291        }
     292
    211293        messaging_register(msg_ctx, ev_ctx,
    212294                           MSG_SMB_CONF_UPDATED, smb_conf_updated);
    213295        messaging_register(msg_ctx, ev_ctx,
    214                            MSG_PRINTER_PCAP, spoolss_pcap_updated);
     296                           MSG_PREFORK_PARENT_EVENT, parent_ping);
     297
     298        /* As soon as messaging is up check if pcap has been loaded already.
     299         * If so then we probably missed a message and should load_printers()
     300         * ourselves. If pcap has not been loaded yet, then ignore, we will get
     301         * a message as soon as the bq process completes the reload. */
     302        if (pcap_cache_loaded(NULL)) {
     303                load_printers(ev_ctx, msg_ctx);
     304        }
     305
     306        /* try to reinit rpc queues */
     307        spoolss_cb.init = spoolss_init_cb;
     308        spoolss_cb.shutdown = spoolss_shutdown_cb;
     309        spoolss_cb.private_data = msg_ctx;
     310
     311        status = rpc_winreg_init(NULL);
     312        if (!NT_STATUS_IS_OK(status)) {
     313                DEBUG(0, ("Failed to register winreg rpc interface! (%s)\n",
     314                          nt_errstr(status)));
     315                return false;
     316        }
     317
     318        status = rpc_spoolss_init(&spoolss_cb);
     319        if (!NT_STATUS_IS_OK(status)) {
     320                DEBUG(0, ("Failed to register spoolss rpc interface! (%s)\n",
     321                          nt_errstr(status)));
     322                return false;
     323        }
     324
     325        return true;
     326}
     327
     328struct spoolss_children_data {
     329        struct tevent_context *ev_ctx;
     330        struct messaging_context *msg_ctx;
     331        struct pf_worker_data *pf;
     332        int listen_fd_size;
     333        int *listen_fds;
     334};
     335
     336static void spoolss_next_client(void *pvt);
     337
     338static int spoolss_children_main(struct tevent_context *ev_ctx,
     339                                 struct messaging_context *msg_ctx,
     340                                 struct pf_worker_data *pf,
     341                                 int child_id,
     342                                 int listen_fd_size,
     343                                 int *listen_fds,
     344                                 void *private_data)
     345{
     346        struct spoolss_children_data *data;
     347        bool ok;
     348        int ret = 0;
     349
     350        ok = spoolss_child_init(ev_ctx, child_id, pf);
     351        if (!ok) {
     352                return 1;
     353        }
     354
     355        data = talloc(ev_ctx, struct spoolss_children_data);
     356        if (!data) {
     357                return 1;
     358        }
     359        data->pf = pf;
     360        data->ev_ctx = ev_ctx;
     361        data->msg_ctx = msg_ctx;
     362        data->listen_fd_size = listen_fd_size;
     363        data->listen_fds = listen_fds;
     364
     365        /* loop until it is time to exit */
     366        while (pf->status != PF_WORKER_EXITING) {
     367                /* try to see if it is time to schedule the next client */
     368                spoolss_next_client(data);
     369
     370                ret = tevent_loop_once(ev_ctx);
     371                if (ret != 0) {
     372                        DEBUG(0, ("tevent_loop_once() exited with %d: %s\n",
     373                                  ret, strerror(errno)));
     374                        pf->status = PF_WORKER_EXITING;
     375                }
     376        }
     377
     378        return ret;
     379}
     380
     381static void spoolss_client_terminated(void *pvt)
     382{
     383        struct spoolss_children_data *data;
     384
     385        data = talloc_get_type_abort(pvt, struct spoolss_children_data);
     386
     387        pfh_client_terminated(data->pf);
     388
     389        spoolss_next_client(pvt);
     390}
     391
     392struct spoolss_new_client {
     393        struct spoolss_children_data *data;
     394        struct tsocket_address *srv_addr;
     395        struct tsocket_address *cli_addr;
     396};
     397
     398static void spoolss_handle_client(struct tevent_req *req);
     399
     400static void spoolss_next_client(void *pvt)
     401{
     402        struct tevent_req *req;
     403        struct spoolss_children_data *data;
     404        struct spoolss_new_client *next;
     405
     406        data = talloc_get_type_abort(pvt, struct spoolss_children_data);
     407
     408        if (!pfh_child_allowed_to_accept(data->pf)) {
     409                /* nothing to do for now we are already listening
     410                 * or we are not allowed to listen further */
     411                return;
     412        }
     413
     414        next = talloc_zero(data, struct spoolss_new_client);
     415        if (!next) {
     416                DEBUG(1, ("Out of memory!?\n"));
     417                return;
     418        }
     419        next->data = data;
     420
     421        req = prefork_listen_send(next, data->ev_ctx, data->pf,
     422                                  data->listen_fd_size,
     423                                  data->listen_fds);
     424        if (!req) {
     425                DEBUG(1, ("Failed to make listening request!?\n"));
     426                talloc_free(next);
     427                return;
     428        }
     429        tevent_req_set_callback(req, spoolss_handle_client, next);
     430}
     431
     432static void spoolss_handle_client(struct tevent_req *req)
     433{
     434        struct spoolss_children_data *data;
     435        struct spoolss_new_client *client;
     436        const DATA_BLOB ping = data_blob_null;
     437        int ret;
     438        int sd;
     439
     440        client = tevent_req_callback_data(req, struct spoolss_new_client);
     441        data = client->data;
     442
     443        ret = prefork_listen_recv(req, client, &sd,
     444                                  &client->srv_addr, &client->cli_addr);
     445
     446        /* this will free the request too */
     447        talloc_free(client);
     448
     449        if (ret != 0) {
     450                DEBUG(6, ("No client connection was available after all!\n"));
     451                return;
     452        }
     453
     454        /* Warn parent that our status changed */
     455        messaging_send(data->msg_ctx, parent_id,
     456                        MSG_PREFORK_CHILD_EVENT, &ping);
     457
     458        DEBUG(2, ("Spoolss preforked child %d got client connection!\n",
     459                  (int)(data->pf->pid)));
     460
     461        named_pipe_accept_function(data->ev_ctx, data->msg_ctx,
     462                                   SPOOLSS_PIPE_NAME, sd,
     463                                   spoolss_client_terminated, data);
     464}
     465
     466/* ==== Main Process Functions ==== */
     467
     468extern pid_t background_lpq_updater_pid;
     469static char *bq_logfile;
     470
     471static void check_updater_child(struct tevent_context *ev_ctx,
     472                                struct messaging_context *msg_ctx)
     473{
     474        int status;
     475        pid_t pid;
     476
     477        if (background_lpq_updater_pid == -1) {
     478                return;
     479        }
     480
     481        pid = sys_waitpid(background_lpq_updater_pid, &status, WNOHANG);
     482        if (pid > 0) {
     483                DEBUG(2, ("The background queue child died... Restarting!\n"));
     484                pid = start_background_queue(ev_ctx, msg_ctx, bq_logfile);
     485                background_lpq_updater_pid = pid;
     486        }
     487}
     488
     489static void child_ping(struct messaging_context *msg_ctx,
     490                        void *private_data,
     491                        uint32_t msg_type,
     492                        struct server_id server_id,
     493                        DATA_BLOB *data)
     494{
     495        struct tevent_context *ev_ctx;
     496
     497        ev_ctx = talloc_get_type_abort(private_data, struct tevent_context);
     498
     499        DEBUG(10, ("Got message that a child changed status.\n"));
     500        pfh_manage_pool(ev_ctx, msg_ctx, &pf_spoolss_cfg, spoolss_pool);
     501}
     502
     503static bool spoolssd_schedule_check(struct tevent_context *ev_ctx,
     504                                    struct messaging_context *msg_ctx,
     505                                    struct timeval current_time);
     506static void spoolssd_check_children(struct tevent_context *ev_ctx,
     507                                    struct tevent_timer *te,
     508                                    struct timeval current_time,
     509                                    void *pvt);
     510
     511static void spoolssd_sigchld_handler(struct tevent_context *ev_ctx,
     512                                     struct prefork_pool *pfp,
     513                                     void *pvt)
     514{
     515        struct messaging_context *msg_ctx;
     516
     517        msg_ctx = talloc_get_type_abort(pvt, struct messaging_context);
     518
     519        /* run pool management so we can fork/retire or increase
     520         * the allowed connections per child based on load */
     521        pfh_manage_pool(ev_ctx, msg_ctx, &pf_spoolss_cfg, spoolss_pool);
     522
     523        /* also check if the updater child is alive and well */
     524        check_updater_child(ev_ctx, msg_ctx);
     525}
     526
     527static bool spoolssd_setup_children_monitor(struct tevent_context *ev_ctx,
     528                                            struct messaging_context *msg_ctx)
     529{
     530        bool ok;
     531
     532        /* add our oun sigchld callback */
     533        prefork_set_sigchld_callback(spoolss_pool,
     534                                     spoolssd_sigchld_handler, msg_ctx);
     535
     536        ok = spoolssd_schedule_check(ev_ctx, msg_ctx,
     537                                     tevent_timeval_current());
     538        return ok;
     539}
     540
     541static bool spoolssd_schedule_check(struct tevent_context *ev_ctx,
     542                                    struct messaging_context *msg_ctx,
     543                                    struct timeval current_time)
     544{
     545        struct tevent_timer *te;
     546        struct timeval next_event;
     547
     548        /* check situation again in 10 seconds */
     549        next_event = tevent_timeval_current_ofs(10, 0);
     550
     551        /* TODO: check when the socket becomes readable, so that children
     552         * are checked only when there is some activity ? */
     553        te = tevent_add_timer(ev_ctx, spoolss_pool, next_event,
     554                                spoolssd_check_children, msg_ctx);
     555        if (!te) {
     556                DEBUG(2, ("Failed to set up children monitoring!\n"));
     557                return false;
     558        }
     559
     560        return true;
     561}
     562
     563static void spoolssd_check_children(struct tevent_context *ev_ctx,
     564                                    struct tevent_timer *te,
     565                                    struct timeval current_time,
     566                                    void *pvt)
     567{
     568        struct messaging_context *msg_ctx;
     569
     570        msg_ctx = talloc_get_type_abort(pvt, struct messaging_context);
     571
     572        pfh_manage_pool(ev_ctx, msg_ctx, &pf_spoolss_cfg, spoolss_pool);
     573
     574        spoolssd_schedule_check(ev_ctx, msg_ctx, current_time);
     575}
     576
     577static void print_queue_forward(struct messaging_context *msg,
     578                                void *private_data,
     579                                uint32_t msg_type,
     580                                struct server_id server_id,
     581                                DATA_BLOB *data)
     582{
     583        messaging_send_buf(msg, pid_to_procid(background_lpq_updater_pid),
     584                           MSG_PRINTER_UPDATE, data->data, data->length);
     585}
     586
     587static char *get_bq_logfile(void)
     588{
     589        char *lfile = lp_logfile(talloc_tos());
     590        int rc;
     591
     592        if (lfile == NULL || lfile[0] == '\0') {
     593                rc = asprintf(&lfile, "%s/log.%s.bq",
     594                                        get_dyn_LOGFILEBASE(), DAEMON_NAME);
     595        } else {
     596                rc = asprintf(&lfile, "%s.bq", lp_logfile(talloc_tos()));
     597        }
     598        if (rc == -1) {
     599                lfile = NULL;
     600        }
     601        return lfile;
     602}
     603
     604pid_t start_spoolssd(struct tevent_context *ev_ctx,
     605                    struct messaging_context *msg_ctx)
     606{
     607        enum rpc_service_mode_e epm_mode = rpc_epmapper_mode();
     608        struct rpc_srv_callbacks spoolss_cb;
     609        struct dcerpc_binding_vector *v;
     610        TALLOC_CTX *mem_ctx;
     611        pid_t pid;
     612        NTSTATUS status;
     613        int listen_fd;
     614        int ret;
     615        bool ok;
     616
     617        DEBUG(1, ("Forking SPOOLSS Daemon\n"));
     618
     619        /*
     620         * Block signals before forking child as it will have to
     621         * set its own handlers. Child will re-enable SIGHUP as
     622         * soon as the handlers are set up.
     623         */
     624        BlockSignals(true, SIGTERM);
     625        BlockSignals(true, SIGHUP);
     626
     627        pid = fork();
     628
     629        if (pid == -1) {
     630                DEBUG(0, ("Failed to fork SPOOLSS [%s]\n",
     631                           strerror(errno)));
     632        }
     633
     634        /* parent or error */
     635        if (pid != 0) {
     636
     637                /* Re-enable SIGHUP before returnig */
     638                BlockSignals(false, SIGTERM);
     639                BlockSignals(false, SIGHUP);
     640                return pid;
     641        }
     642
     643        status = smbd_reinit_after_fork(msg_ctx, ev_ctx, true,
     644                                        "spoolssd-master");
     645        if (!NT_STATUS_IS_OK(status)) {
     646                DEBUG(0,("reinit_after_fork() failed\n"));
     647                smb_panic("reinit_after_fork() failed");
     648        }
     649
     650        /* save the parent process id so the children can use it later */
     651        parent_id = messaging_server_id(msg_ctx);
     652
     653        spoolss_reopen_logs(0);
     654        pfh_daemon_config(DAEMON_NAME,
     655                          &pf_spoolss_cfg,
     656                          &default_pf_spoolss_cfg);
     657
     658        spoolss_setup_sig_term_handler(ev_ctx);
     659        spoolss_setup_sig_hup_handler(ev_ctx, msg_ctx);
     660
     661        BlockSignals(false, SIGTERM);
     662        BlockSignals(false, SIGHUP);
     663
     664        /* always start the backgroundqueue listner in spoolssd */
     665        bq_logfile = get_bq_logfile();
     666        pid = start_background_queue(ev_ctx, msg_ctx, bq_logfile);
     667        if (pid > 0) {
     668                background_lpq_updater_pid = pid;
     669        }
     670
     671        /* the listening fd must be created before the children are actually
     672         * forked out. */
     673        listen_fd = create_named_pipe_socket(SPOOLSS_PIPE_NAME);
     674        if (listen_fd == -1) {
     675                exit(1);
     676        }
     677
     678        ret = listen(listen_fd, pf_spoolss_cfg.max_allowed_clients);
     679        if (ret == -1) {
     680                DEBUG(0, ("Failed to listen on spoolss pipe - %s\n",
     681                          strerror(errno)));
     682                exit(1);
     683        }
     684
     685        /* start children before any more initialization is done */
     686        ok = prefork_create_pool(ev_ctx, /* mem_ctx */
     687                                 ev_ctx, msg_ctx,
     688                                 1, &listen_fd,
     689                                 pf_spoolss_cfg.min_children,
     690                                 pf_spoolss_cfg.max_children,
     691                                 &spoolss_children_main, NULL,
     692                                 &spoolss_pool);
     693        if (!ok) {
     694                exit(1);
     695        }
     696
     697        if (!serverid_register(messaging_server_id(msg_ctx),
     698                                FLAG_MSG_GENERAL |
     699                                FLAG_MSG_PRINT_GENERAL)) {
     700                exit(1);
     701        }
     702
     703        if (!locking_init()) {
     704                exit(1);
     705        }
     706
     707        messaging_register(msg_ctx, ev_ctx,
     708                           MSG_SMB_CONF_UPDATED, smb_conf_updated);
     709        messaging_register(msg_ctx, NULL, MSG_PRINTER_UPDATE,
     710                           print_queue_forward);
     711        messaging_register(msg_ctx, ev_ctx,
     712                           MSG_PREFORK_CHILD_EVENT, child_ping);
     713
     714        /*
     715         * As soon as messaging is up check if pcap has been loaded already.
     716         * If pcap has not been loaded yet, then ignore, as we will reload on
     717         * client enumeration anyway.
     718         */
     719        if (pcap_cache_loaded(NULL)) {
     720                load_printers(ev_ctx, msg_ctx);
     721        }
     722
     723        mem_ctx = talloc_new(NULL);
     724        if (mem_ctx == NULL) {
     725                exit(1);
     726        }
    215727
    216728        /*
     
    225737        status = rpc_winreg_init(NULL);
    226738        if (!NT_STATUS_IS_OK(status)) {
    227                 DEBUG(0, ("Failed to register winreg rpc inteface! (%s)\n",
     739                DEBUG(0, ("Failed to register winreg rpc interface! (%s)\n",
    228740                          nt_errstr(status)));
    229741                exit(1);
     
    232744        status = rpc_spoolss_init(&spoolss_cb);
    233745        if (!NT_STATUS_IS_OK(status)) {
    234                 DEBUG(0, ("Failed to register spoolss rpc inteface! (%s)\n",
     746                DEBUG(0, ("Failed to register spoolss rpc interface! (%s)\n",
    235747                          nt_errstr(status)));
    236748                exit(1);
    237749        }
    238750
    239         if (!setup_named_pipe_socket(SPOOLSS_PIPE_NAME, ev_ctx)) {
    240                 exit(1);
    241         }
    242 
    243         status = rpc_ep_setup_register(ev_ctx, msg_ctx, &ndr_table_spoolss, NULL, 0);
    244         if (!NT_STATUS_IS_OK(status)) {
    245                 DEBUG(0, ("Failed to register spoolss endpoint! (%s)\n",
    246                           nt_errstr(status)));
    247                 exit(1);
    248         }
    249 
    250         DEBUG(1, ("SPOOLSS Daemon Started (%d)\n", getpid()));
     751        if (epm_mode != RPC_SERVICE_MODE_DISABLED &&
     752            (lp_parm_bool(-1, "rpc_server", "register_embedded_np", false))) {
     753                status = dcerpc_binding_vector_new(mem_ctx, &v);
     754                if (!NT_STATUS_IS_OK(status)) {
     755                        DEBUG(0, ("Failed to create binding vector (%s)\n",
     756                                  nt_errstr(status)));
     757                        exit(1);
     758                }
     759
     760                status = dcerpc_binding_vector_add_np_default(&ndr_table_spoolss, v);
     761                if (!NT_STATUS_IS_OK(status)) {
     762                        DEBUG(0, ("Failed to add np to binding vector (%s)\n",
     763                                  nt_errstr(status)));
     764                        exit(1);
     765                }
     766
     767                status = rpc_ep_register(ev_ctx, msg_ctx, &ndr_table_spoolss, v);
     768                if (!NT_STATUS_IS_OK(status)) {
     769                        DEBUG(0, ("Failed to register spoolss endpoint! (%s)\n",
     770                                  nt_errstr(status)));
     771                        exit(1);
     772                }
     773        }
     774
     775        talloc_free(mem_ctx);
     776
     777        ok = spoolssd_setup_children_monitor(ev_ctx, msg_ctx);
     778        if (!ok) {
     779                DEBUG(0, ("Failed to setup children monitoring!\n"));
     780                exit(1);
     781        }
     782
     783        DEBUG(1, ("SPOOLSS Daemon Started (%u)\n", (unsigned int)getpid()));
     784
     785        pfh_manage_pool(ev_ctx, msg_ctx, &pf_spoolss_cfg, spoolss_pool);
    251786
    252787        /* loop forever */
     
    254789
    255790        /* should not be reached */
    256         DEBUG(0,("background_queue: tevent_loop_wait() exited with %d - %s\n",
     791        DEBUG(0,("spoolssd tevent_loop_wait() exited with %d - %s\n",
    257792                 ret, (ret == 0) ? "out of events" : strerror(errno)));
    258793        exit(1);
  • vendor/current/source3/printing/tests/vlp.c

    r746 r988  
    112112{
    113113        fstring keystr;
    114         int result;
    115114
    116115        slprintf(keystr, sizeof(keystr) - 1, "STATUS/%s", printer);
    117         result = tdb_store_int32(tdb, keystr, status);
     116        tdb_store_int32(tdb, keystr, status);
    118117}
    119118
     
    395394        }
    396395
     396        /* FIXME: We should *never* open a tdb without logging! */
    397397        if (!(tdb = tdb_open(printdb_path, 0, 0, O_RDWR | O_CREAT,
    398398                             0666))) {
Note: See TracChangeset for help on using the changeset viewer.