Ignore:
Timestamp:
Nov 27, 2012, 4:56:06 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated vendor to 3.6.9

File:
1 edited

Legend:

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

    r740 r746  
    374374***********************************************************************/
    375375
    376 static int unpack_pjob( uint8 *buf, int buflen, struct printjob *pjob )
     376static int unpack_pjob(TALLOC_CTX *mem_ctx, uint8 *buf, int buflen,
     377                       struct printjob *pjob)
    377378{
    378379        int     len = 0;
    379380        int     used;
    380         uint32 pjpid, pjsysjob, pjfd, pjstarttime, pjstatus;
     381        uint32 pjpid, pjjobid, pjsysjob, pjfd, pjstarttime, pjstatus;
    381382        uint32 pjsize, pjpage_count, pjspooled, pjsmbjob;
    382383
    383         if ( !buf || !pjob )
     384        if (!buf || !pjob) {
    384385                return -1;
    385 
    386         len += tdb_unpack(buf+len, buflen-len, "dddddddddfffff",
     386        }
     387
     388        len += tdb_unpack(buf+len, buflen-len, "ddddddddddfffff",
    387389                                &pjpid,
     390                                &pjjobid,
    388391                                &pjsysjob,
    389392                                &pjfd,
     
    400403                                pjob->queuename);
    401404
    402         if ( len == -1 )
     405        if (len == -1) {
    403406                return -1;
    404 
    405         used = unpack_devicemode(NULL, buf+len, buflen-len, &pjob->devmode);
     407        }
     408
     409        used = unpack_devicemode(mem_ctx, buf+len, buflen-len, &pjob->devmode);
    406410        if (used == -1) {
    407411                return -1;
     
    411415
    412416        pjob->pid = pjpid;
     417        pjob->jobid = pjjobid;
    413418        pjob->sysjob = pjsysjob;
    414419        pjob->fd = pjfd;
     
    428433****************************************************************************/
    429434
    430 static struct printjob *print_job_find(const char *sharename, uint32 jobid)
    431 {
    432         static struct printjob  pjob;
     435static struct printjob *print_job_find(TALLOC_CTX *mem_ctx,
     436                                       const char *sharename,
     437                                       uint32 jobid)
     438{
     439        struct printjob         *pjob;
    433440        uint32_t tmp;
    434441        TDB_DATA                ret;
     
    446453
    447454        if (!ret.dptr) {
    448                 DEBUG(10,("print_job_find: failed to find jobid %u.\n", (unsigned int)jobid ));
     455                DEBUG(10, ("print_job_find: failed to find jobid %u.\n",
     456                           jobid));
    449457                return NULL;
    450458        }
    451459
    452         talloc_free(pjob.devmode);
    453 
    454         ZERO_STRUCT( pjob );
    455 
    456         if ( unpack_pjob( ret.dptr, ret.dsize, &pjob ) == -1 ) {
    457                 DEBUG(10,("print_job_find: failed to unpack jobid %u.\n", (unsigned int)jobid ));
    458                 SAFE_FREE(ret.dptr);
    459                 return NULL;
    460         }
    461 
     460        pjob = talloc_zero(mem_ctx, struct printjob);
     461        if (pjob == NULL) {
     462                goto err_out;
     463        }
     464
     465        if (unpack_pjob(mem_ctx, ret.dptr, ret.dsize, pjob) == -1) {
     466                DEBUG(10, ("failed to unpack jobid %u.\n", jobid));
     467                talloc_free(pjob);
     468                pjob = NULL;
     469                goto err_out;
     470        }
     471
     472        DEBUG(10,("print_job_find: returning system job %d for jobid %u.\n",
     473                  pjob->sysjob, jobid));
     474        SMB_ASSERT(pjob->jobid == jobid);
     475
     476err_out:
    462477        SAFE_FREE(ret.dptr);
    463 
    464         DEBUG(10,("print_job_find: returning system job %d for jobid %u.\n",
    465                         (int)pjob.sysjob, (unsigned int)jobid ));
    466 
    467         return &pjob;
     478        return pjob;
    468479}
    469480
     
    490501
    491502        if (state->sysjob == pjob->sysjob) {
    492                 uint32 jobid = IVAL(key.dptr,0);
    493 
    494                 state->sysjob_to_jobid_value = jobid;
     503                state->sysjob_to_jobid_value = pjob->jobid;
    495504                return 1;
    496505        }
    497506
    498507        return 0;
     508}
     509
     510static uint32 sysjob_to_jobid_pdb(struct tdb_print_db *pdb, int sysjob)
     511{
     512        struct unixjob_traverse_state state;
     513
     514        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;
    499520}
    500521
     
    738759                len = 0;
    739760                buflen = newlen;
    740                 len += tdb_pack(buf+len, buflen-len, "dddddddddfffff",
     761                len += tdb_pack(buf+len, buflen-len, "ddddddddddfffff",
    741762                                (uint32)pjob->pid,
     763                                (uint32)pjob->jobid,
    742764                                (uint32)pjob->sysjob,
    743765                                (uint32)pjob->fd,
     
    776798        /* Send notify updates for what has changed */
    777799
    778         if ( ret ) {
     800        if (ret) {
    779801                bool changed = false;
    780802                struct printjob old_pjob;
    781803
    782                 if ( old_data.dsize )
    783                 {
    784                         if ( unpack_pjob( old_data.dptr, old_data.dsize, &old_pjob ) != -1 )
    785                         {
    786                                 pjob_store_notify(server_event_context(),
     804                if (old_data.dsize) {
     805                        TALLOC_CTX *tmp_ctx = talloc_new(ev);
     806                        if (tmp_ctx == NULL)
     807                                goto done;
     808
     809                        len = unpack_pjob(tmp_ctx, old_data.dptr,
     810                                          old_data.dsize, &old_pjob);
     811                        if (len != -1 ) {
     812                                pjob_store_notify(ev,
    787813                                                  msg_ctx,
    788814                                                  sharename, jobid, &old_pjob,
    789815                                                  pjob,
    790816                                                  &changed);
    791                                 talloc_free(old_pjob.devmode);
    792 
    793817                                if (changed) {
    794818                                        add_to_jobs_changed(pdb, jobid);
    795819                                }
    796820                        }
    797 
    798                 }
    799                 else {
     821                        talloc_free(tmp_ctx);
     822
     823                } else {
    800824                        /* new job */
    801                         pjob_store_notify(server_event_context(), msg_ctx,
     825                        pjob_store_notify(ev, msg_ctx,
    802826                                          sharename, jobid, NULL, pjob,
    803827                                          &changed);
     
    805829        }
    806830
     831done:
    807832        release_print_db(pdb);
    808 done:
    809833        SAFE_FREE( old_data.dptr );
    810834        SAFE_FREE( buf );
     
    825849        uint32 job_status = 0;
    826850        struct tdb_print_db *pdb;
    827 
    828         pdb = get_print_db_byname( sharename );
    829 
    830         if (!pdb)
     851        TALLOC_CTX *tmp_ctx = talloc_new(ev);
     852        if (tmp_ctx == NULL) {
    831853                return;
    832 
    833         pjob = print_job_find( sharename, jobid );
    834 
     854        }
     855
     856        pdb = get_print_db_byname(sharename);
     857        if (!pdb) {
     858                goto err_out;
     859        }
     860
     861        pjob = print_job_find(tmp_ctx, sharename, jobid);
    835862        if (!pjob) {
    836                 DEBUG(5, ("pjob_delete: we were asked to delete nonexistent job %u\n",
    837                                         (unsigned int)jobid));
    838                 release_print_db(pdb);
    839                 return;
     863                DEBUG(5, ("we were asked to delete nonexistent job %u\n",
     864                          jobid));
     865                goto err_release;
    840866        }
    841867
     
    851877        tdb_delete(pdb->tdb, print_key(jobid, &tmp));
    852878        remove_from_jobs_added(sharename, jobid);
    853         release_print_db( pdb );
    854879        rap_jobid_delete(sharename, jobid);
     880err_release:
     881        release_print_db(pdb);
     882err_out:
     883        talloc_free(tmp_ctx);
    855884}
    856885
     
    865894{
    866895        struct printjob pj, *old_pj;
    867 
    868         if (jobid == (uint32)-1)
    869                 jobid = q->job + UNIX_JOB_START;
     896        TALLOC_CTX *tmp_ctx = talloc_new(ev);
     897        if (tmp_ctx == NULL) {
     898                return;
     899        }
     900
     901        if (jobid == (uint32)-1) {
     902                jobid = q->sysjob + UNIX_JOB_START;
     903        }
    870904
    871905        /* Preserve the timestamp on an existing unix print job */
    872906
    873         old_pj = print_job_find(sharename, jobid);
     907        old_pj = print_job_find(tmp_ctx, sharename, jobid);
    874908
    875909        ZERO_STRUCT(pj);
    876910
    877911        pj.pid = (pid_t)-1;
    878         pj.sysjob = q->job;
     912        pj.jobid = jobid;
     913        pj.sysjob = q->sysjob;
    879914        pj.fd = -1;
    880915        pj.starttime = old_pj ? old_pj->starttime : q->time;
     
    894929
    895930        pjob_store(ev, msg_ctx, sharename, jobid, &pj);
     931        talloc_free(tmp_ctx);
    896932}
    897933
     
    906942        struct tevent_context *ev;
    907943        struct messaging_context *msg_ctx;
     944        TALLOC_CTX *mem_ctx;
    908945};
    909946
     
    922959                return 0;
    923960
    924         jobid = IVAL(key.dptr, 0);
    925         if ( unpack_pjob( data.dptr, data.dsize, &pjob ) == -1 )
     961        if (unpack_pjob(ts->mem_ctx, data.dptr, data.dsize, &pjob) == -1)
    926962                return 0;
    927963        talloc_free(pjob.devmode);
    928 
     964        jobid = pjob.jobid;
    929965
    930966        if (!pjob.smbjob) {
    931967                /* remove a unix job if it isn't in the system queue any more */
    932 
    933968                for (i=0;i<ts->qcount;i++) {
    934                         uint32 u_jobid = (ts->queue[i].job + UNIX_JOB_START);
    935                         if (jobid == u_jobid)
     969                        if (ts->queue[i].sysjob == pjob.sysjob) {
    936970                                break;
     971                        }
    937972                }
    938973                if (i == ts->qcount) {
     
    9651000        /* this check only makes sense for jobs submitted from Windows clients */
    9661001
    967         if ( pjob.smbjob ) {
     1002        if (pjob.smbjob) {
    9681003                for (i=0;i<ts->qcount;i++) {
    969                         uint32 curr_jobid;
    970 
    9711004                        if ( pjob.status == LPQ_DELETED )
    9721005                                continue;
    9731006
    974                         curr_jobid = print_parse_jobid(ts->queue[i].fs_file);
    975 
    976                         if (jobid == curr_jobid) {
     1007                        if (ts->queue[i].sysjob == pjob.sysjob) {
    9771008
    9781009                                /* try to clean up any jobs that need to be deleted */
     
    10291060        }
    10301061
    1031         /* Save the pjob attributes we will store.
    1032            FIXME!!! This is the only place where queue->job
    1033            represents the SMB jobid      --jerry */
    1034 
    1035         ts->queue[i].job = jobid;
     1062        /* Save the pjob attributes we will store. */
     1063        ts->queue[i].sysjob = pjob.sysjob;
    10361064        ts->queue[i].size = pjob.size;
    10371065        ts->queue[i].page_count = pjob.page_count;
     
    11841212                qcount++;
    11851213                data.dsize += tdb_pack(NULL, 0, "ddddddff",
    1186                                 (uint32)queue[i].job,
     1214                                (uint32)queue[i].sysjob,
    11871215                                (uint32)queue[i].size,
    11881216                                (uint32)queue[i].page_count,
     
    12041232
    12051233                len += tdb_pack(data.dptr + len, data.dsize - len, "ddddddff",
    1206                                 (uint32)queue[i].job,
     1234                                (uint32)queue[i].sysjob,
    12071235                                (uint32)queue[i].size,
    12081236                                (uint32)queue[i].page_count,
     
    13181346****************************************************************************/
    13191347
    1320 static void print_queue_update_internal( struct tevent_context *ev,
    1321                                          struct messaging_context *msg_ctx,
    1322                                          const char *sharename,
    1323                                          struct printif *current_printif,
    1324                                          char *lpq_command, char *lprm_command )
     1348static void print_queue_update_internal(struct tevent_context *ev,
     1349                                        struct messaging_context *msg_ctx,
     1350                                        const char *sharename,
     1351                                        struct printif *current_printif,
     1352                                        char *lpq_command, char *lprm_command)
    13251353{
    13261354        int i, qcount;
     
    13341362        fstring keystr, cachestr;
    13351363        struct tdb_print_db *pdb = get_print_db_byname(sharename);
    1336 
    1337         if (!pdb) {
     1364        TALLOC_CTX *tmp_ctx = talloc_new(ev);
     1365
     1366        if ((pdb == NULL) || (tmp_ctx == NULL)) {
    13381367                return;
    13391368        }
     
    13761405          fill in any system job numbers as we go
    13771406        */
    1378 
    13791407        jcdata = get_jobs_added_data(pdb);
    13801408
    13811409        for (i=0; i<qcount; i++) {
    1382                 uint32 jobid = print_parse_jobid(queue[i].fs_file);
    1383 
     1410                uint32 jobid = sysjob_to_jobid_pdb(pdb, queue[i].sysjob);
    13841411                if (jobid == (uint32)-1) {
    13851412                        /* assume its a unix print job */
     
    13901417
    13911418                /* we have an active SMB print job - update its status */
    1392                 pjob = print_job_find(sharename, jobid);
     1419                pjob = print_job_find(tmp_ctx, sharename, jobid);
    13931420                if (!pjob) {
    13941421                        /* err, somethings wrong. Probably smbd was restarted
    13951422                           with jobs in the queue. All we can do is treat them
    13961423                           like unix jobs. Pity. */
     1424                        DEBUG(1, ("queued print job %d not found in jobs list, "
     1425                                  "assuming unix job\n", jobid));
    13971426                        print_unix_job(ev, msg_ctx,
    13981427                                       sharename, &queue[i], jobid);
    13991428                        continue;
    14001429                }
    1401 
    1402                 pjob->sysjob = queue[i].job;
    14031430
    14041431                /* don't reset the status on jobs to be deleted */
     
    14261453        tstruct.ev = ev;
    14271454        tstruct.msg_ctx = msg_ctx;
     1455        tstruct.mem_ctx = tmp_ctx;
    14281456
    14291457        tdb_traverse(pdb->tdb, traverse_fn_delete, (void *)&tstruct);
     
    14331461
    14341462        SAFE_FREE(tstruct.queue);
     1463        talloc_free(tmp_ctx);
    14351464
    14361465        DEBUG(10,("print_queue_update_internal: printer %s INFO/total_jobs = %d\n",
     
    16281657}
    16291658
     1659static bool printer_housekeeping_fn(const struct timeval *now,
     1660                                    void *private_data)
     1661{
     1662        static time_t last_pcap_reload_time = 0;
     1663        time_t printcap_cache_time = (time_t)lp_printcap_cache_time();
     1664        time_t t = time_mono(NULL);
     1665
     1666        DEBUG(5, ("printer housekeeping\n"));
     1667
     1668        /* if periodic printcap rescan is enabled, see if it's time to reload */
     1669        if ((printcap_cache_time != 0)
     1670         && (t >= (last_pcap_reload_time + printcap_cache_time))) {
     1671                DEBUG( 3,( "Printcap cache time expired.\n"));
     1672                pcap_cache_reload(server_event_context(),
     1673                                  smbd_messaging_context(),
     1674                                  &reload_pcap_change_notify);
     1675                last_pcap_reload_time = t;
     1676        }
     1677
     1678        return true;
     1679}
     1680
    16301681static pid_t background_lpq_updater_pid = -1;
    16311682
     
    16991750                        DEBUG(0,("tevent_add_fd() failed for pause_pipe\n"));
    17001751                        smb_panic("tevent_add_fd() failed for pause_pipe");
     1752                }
     1753
     1754                if (!(event_add_idle(ev, NULL,
     1755                                     timeval_set(SMBD_HOUSEKEEPING_INTERVAL, 0),
     1756                                     "printer_housekeeping",
     1757                                     printer_housekeeping_fn,
     1758                                     NULL))) {
     1759                        DEBUG(0, ("Could not add printing housekeeping event\n"));
     1760                        exit(1);
    17011761                }
    17021762
     
    20452105
    20462106/****************************************************************************
    2047  Give the filename used for a jobid.
     2107 Return the device mode asigned to a specific print job.
    20482108 Only valid for the process doing the spooling and when the job
    20492109 has not been spooled.
    20502110****************************************************************************/
    20512111
    2052 char *print_job_fname(const char* sharename, uint32 jobid)
    2053 {
    2054         struct printjob *pjob = print_job_find(sharename, jobid);
    2055         if (!pjob || pjob->spooled || pjob->pid != sys_getpid())
     2112struct spoolss_DeviceMode *print_job_devmode(TALLOC_CTX *mem_ctx,
     2113                                             const char *sharename,
     2114                                             uint32 jobid)
     2115{
     2116        struct printjob *pjob = print_job_find(mem_ctx, sharename, jobid);
     2117        if (pjob == NULL) {
    20562118                return NULL;
    2057         return pjob->filename;
    2058 }
    2059 
    2060 
    2061 /****************************************************************************
    2062  Give the filename used for a jobid.
    2063  Only valid for the process doing the spooling and when the job
    2064  has not been spooled.
    2065 ****************************************************************************/
    2066 
    2067 struct spoolss_DeviceMode *print_job_devmode(const char* sharename, uint32 jobid)
    2068 {
    2069         struct printjob *pjob = print_job_find(sharename, jobid);
    2070 
    2071         if ( !pjob )
    2072                 return NULL;
     2119        }
    20732120
    20742121        return pjob->devmode;
     
    20842131{
    20852132        struct printjob *pjob;
    2086 
    2087         pjob = print_job_find(sharename, jobid);
    2088         if (!pjob || pjob->pid != sys_getpid())
    2089                 return False;
     2133        bool ret;
     2134        TALLOC_CTX *tmp_ctx = talloc_new(ev);
     2135        if (tmp_ctx == NULL) {
     2136                return false;
     2137        }
     2138
     2139        pjob = print_job_find(tmp_ctx, sharename, jobid);
     2140        if (!pjob || pjob->pid != sys_getpid()) {
     2141                ret = false;
     2142                goto err_out;
     2143        }
    20902144
    20912145        fstrcpy(pjob->jobname, name);
    2092         return pjob_store(ev, msg_ctx, sharename, jobid, pjob);
     2146        ret = pjob_store(ev, msg_ctx, sharename, jobid, pjob);
     2147err_out:
     2148        talloc_free(tmp_ctx);
     2149        return ret;
    20932150}
    20942151
     
    21012158        struct printjob *pjob;
    21022159
    2103         pjob = print_job_find(sharename, jobid);
     2160        pjob = print_job_find(mem_ctx, sharename, jobid);
    21042161        if (!pjob || pjob->pid != sys_getpid()) {
    21052162                return false;
    21062163        }
    21072164
    2108         *name = talloc_strdup(mem_ctx, pjob->jobname);
    2109         if (!*name) {
    2110                 return false;
    2111         }
    2112 
     2165        *name = pjob->jobname;
    21132166        return true;
    21142167}
     
    21832236{
    21842237        const char* sharename = lp_const_servicename(snum);
    2185         struct printjob *pjob = print_job_find(sharename, jobid);
     2238        struct printjob *pjob;
    21862239        int result = 0;
    21872240        struct printif *current_printif = get_printer_fns( snum );
    2188 
    2189         if (!pjob)
    2190                 return False;
     2241        bool ret;
     2242        TALLOC_CTX *tmp_ctx = talloc_new(ev);
     2243        if (tmp_ctx == NULL) {
     2244                return false;
     2245        }
     2246
     2247        pjob = print_job_find(tmp_ctx, sharename, jobid);
     2248        if (!pjob) {
     2249                ret = false;
     2250                goto err_out;
     2251        }
    21912252
    21922253        /*
     
    21942255         */
    21952256
    2196         if (pjob->status == LPQ_DELETING)
    2197                 return True;
     2257        if (pjob->status == LPQ_DELETING) {
     2258                ret = true;
     2259                goto err_out;
     2260        }
    21982261
    21992262        /* Hrm - we need to be able to cope with deleting a job before it
     
    22252288                        int njobs = 1;
    22262289
    2227                         if (!pdb)
    2228                                 return False;
     2290                        if (!pdb) {
     2291                                ret = false;
     2292                                goto err_out;
     2293                        }
    22292294                        pjob_delete(ev, msg_ctx, sharename, jobid);
    22302295                        /* Ensure we keep a rough count of the number of total jobs... */
     
    22362301        remove_from_jobs_added( sharename, jobid );
    22372302
    2238         return (result == 0);
     2303        ret = (result == 0);
     2304err_out:
     2305        talloc_free(tmp_ctx);
     2306        return ret;
    22392307}
    22402308
     
    22472315                     uint32 jobid)
    22482316{
    2249         struct printjob *pjob = print_job_find(servicename, jobid);
    2250 
    2251         if (!pjob || !server_info)
    2252                 return False;
    2253 
    2254         return strequal(pjob->user, server_info->sanitized_username);
     2317        struct printjob *pjob;
     2318        bool ret;
     2319        TALLOC_CTX *tmp_ctx = talloc_new(server_info);
     2320        if (tmp_ctx == NULL) {
     2321                return false;
     2322        }
     2323
     2324        pjob = print_job_find(tmp_ctx, servicename, jobid);
     2325        if (!pjob || !server_info) {
     2326                ret = false;
     2327                goto err_out;
     2328        }
     2329
     2330        ret = strequal(pjob->user, server_info->sanitized_username);
     2331err_out:
     2332        talloc_free(tmp_ctx);
     2333        return ret;
    22552334}
    22562335
     
    22662345        struct printjob *pjob;
    22672346        bool    owner;
    2268         char    *fname;
     2347        WERROR werr;
     2348        TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx);
     2349        if (tmp_ctx == NULL) {
     2350                return WERR_NOT_ENOUGH_MEMORY;
     2351        }
    22692352
    22702353        owner = is_owner(server_info, lp_const_servicename(snum), jobid);
     
    22862369                /* END_ADMIN_LOG */
    22872370
    2288                 return WERR_ACCESS_DENIED;
     2371                werr = WERR_ACCESS_DENIED;
     2372                goto err_out;
    22892373        }
    22902374
     
    22962380         */
    22972381
    2298         fname = print_job_fname(sharename, jobid);
    2299         if (fname != NULL) {
    2300                 /* remove the spool file */
    2301                 DEBUG(10, ("print_job_delete: "
    2302                            "Removing spool file [%s]\n", fname));
    2303                 if (unlink(fname) == -1) {
    2304                         return map_werror_from_unix(errno);
     2382        pjob = print_job_find(tmp_ctx, sharename, jobid);
     2383        if (!pjob || pjob->spooled || pjob->pid != getpid()) {
     2384                DEBUG(10, ("Skipping spool file removal for job %u\n", jobid));
     2385        } else {
     2386                DEBUG(10, ("Removing spool file [%s]\n", pjob->filename));
     2387                if (unlink(pjob->filename) == -1) {
     2388                        werr = map_werror_from_unix(errno);
     2389                        goto err_out;
    23052390                }
    23062391        }
    23072392
    23082393        if (!print_job_delete1(server_event_context(), msg_ctx, snum, jobid)) {
    2309                 return WERR_ACCESS_DENIED;
     2394                werr = WERR_ACCESS_DENIED;
     2395                goto err_out;
    23102396        }
    23112397
     
    23152401        print_queue_update(msg_ctx, snum, True);
    23162402
    2317         pjob = print_job_find(sharename, jobid);
     2403        pjob = print_job_find(tmp_ctx, sharename, jobid);
    23182404        if (pjob && (pjob->status != LPQ_DELETING)) {
    2319                 return WERR_ACCESS_DENIED;
    2320         }
    2321 
    2322         return WERR_PRINTER_HAS_JOBS_QUEUED;
     2405                werr = WERR_ACCESS_DENIED;
     2406                goto err_out;
     2407        }
     2408        werr = WERR_PRINTER_HAS_JOBS_QUEUED;
     2409
     2410err_out:
     2411        talloc_free(tmp_ctx);
     2412        return werr;
    23232413}
    23242414
     
    23272417****************************************************************************/
    23282418
    2329 bool print_job_pause(const struct auth_serversupplied_info *server_info,
     2419WERROR print_job_pause(const struct auth_serversupplied_info *server_info,
    23302420                     struct messaging_context *msg_ctx,
    2331                      int snum, uint32 jobid, WERROR *errcode)
     2421                     int snum, uint32 jobid)
    23322422{
    23332423        const char* sharename = lp_const_servicename(snum);
     
    23352425        int ret = -1;
    23362426        struct printif *current_printif = get_printer_fns( snum );
    2337 
    2338         pjob = print_job_find(sharename, jobid);
    2339 
     2427        WERROR werr;
     2428        TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx);
     2429        if (tmp_ctx == NULL) {
     2430                return WERR_NOT_ENOUGH_MEMORY;
     2431        }
     2432
     2433        pjob = print_job_find(tmp_ctx, sharename, jobid);
    23402434        if (!pjob || !server_info) {
    23412435                DEBUG(10, ("print_job_pause: no pjob or user for jobid %u\n",
    23422436                        (unsigned int)jobid ));
    2343                 return False;
     2437                werr = WERR_INVALID_PARAM;
     2438                goto err_out;
    23442439        }
    23452440
     
    23472442                DEBUG(10, ("print_job_pause: not spooled or bad sysjob = %d for jobid %u\n",
    23482443                        (int)pjob->sysjob, (unsigned int)jobid ));
    2349                 return False;
     2444                werr = WERR_INVALID_PARAM;
     2445                goto err_out;
    23502446        }
    23512447
     
    23632459                /* END_ADMIN_LOG */
    23642460
    2365                 *errcode = WERR_ACCESS_DENIED;
    2366                 return False;
     2461                werr = WERR_ACCESS_DENIED;
     2462                goto err_out;
    23672463        }
    23682464
     
    23712467
    23722468        if (ret != 0) {
    2373                 *errcode = WERR_INVALID_PARAM;
    2374                 return False;
     2469                werr = WERR_INVALID_PARAM;
     2470                goto err_out;
    23752471        }
    23762472
     
    23842480
    23852481        /* how do we tell if this succeeded? */
    2386 
    2387         return True;
     2482        werr = WERR_OK;
     2483err_out:
     2484        talloc_free(tmp_ctx);
     2485        return werr;
    23882486}
    23892487
     
    23922490****************************************************************************/
    23932491
    2394 bool print_job_resume(const struct auth_serversupplied_info *server_info,
     2492WERROR print_job_resume(const struct auth_serversupplied_info *server_info,
    23952493                      struct messaging_context *msg_ctx,
    2396                       int snum, uint32 jobid, WERROR *errcode)
     2494                      int snum, uint32 jobid)
    23972495{
    23982496        const char *sharename = lp_const_servicename(snum);
     
    24002498        int ret;
    24012499        struct printif *current_printif = get_printer_fns( snum );
    2402 
    2403         pjob = print_job_find(sharename, jobid);
    2404 
     2500        WERROR werr;
     2501        TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx);
     2502        if (tmp_ctx == NULL)
     2503                return WERR_NOT_ENOUGH_MEMORY;
     2504
     2505        pjob = print_job_find(tmp_ctx, sharename, jobid);
    24052506        if (!pjob || !server_info) {
    24062507                DEBUG(10, ("print_job_resume: no pjob or user for jobid %u\n",
    24072508                        (unsigned int)jobid ));
    2408                 return False;
     2509                werr = WERR_INVALID_PARAM;
     2510                goto err_out;
    24092511        }
    24102512
     
    24122514                DEBUG(10, ("print_job_resume: not spooled or bad sysjob = %d for jobid %u\n",
    24132515                        (int)pjob->sysjob, (unsigned int)jobid ));
    2414                 return False;
     2516                werr = WERR_INVALID_PARAM;
     2517                goto err_out;
    24152518        }
    24162519
     
    24192522                                JOB_ACCESS_ADMINISTER)) {
    24202523                DEBUG(3, ("resume denied by security descriptor\n"));
    2421                 *errcode = WERR_ACCESS_DENIED;
    24222524
    24232525                /* BEGIN_ADMIN_LOG */
     
    24282530                              lp_printername(snum) );
    24292531                /* END_ADMIN_LOG */
    2430                 return False;
     2532                werr = WERR_ACCESS_DENIED;
     2533                goto err_out;
    24312534        }
    24322535
     
    24342537
    24352538        if (ret != 0) {
    2436                 *errcode = WERR_INVALID_PARAM;
    2437                 return False;
     2539                werr = WERR_INVALID_PARAM;
     2540                goto err_out;
    24382541        }
    24392542
     
    24462549                          JOB_STATUS_QUEUED);
    24472550
    2448         return True;
     2551        werr = WERR_OK;
     2552err_out:
     2553        talloc_free(tmp_ctx);
     2554        return werr;
    24492555}
    24502556
     
    24602566        ssize_t return_code;
    24612567        struct printjob *pjob;
    2462 
    2463         pjob = print_job_find(sharename, jobid);
    2464 
    2465         if (!pjob)
     2568        TALLOC_CTX *tmp_ctx = talloc_new(ev);
     2569        if (tmp_ctx == NULL) {
    24662570                return -1;
     2571        }
     2572
     2573        pjob = print_job_find(tmp_ctx, sharename, jobid);
     2574        if (!pjob) {
     2575                return_code = -1;
     2576                goto err_out;
     2577        }
     2578
    24672579        /* don't allow another process to get this info - it is meaningless */
    2468         if (pjob->pid != sys_getpid())
    2469                 return -1;
     2580        if (pjob->pid != sys_getpid()) {
     2581                return_code = -1;
     2582                goto err_out;
     2583        }
    24702584
    24712585        /* if SMBD is spooling this can't be allowed */
    24722586        if (pjob->status == PJOB_SMBD_SPOOLING) {
    2473                 return -1;
     2587                return_code = -1;
     2588                goto err_out;
    24742589        }
    24752590
    24762591        return_code = write_data(pjob->fd, buf, size);
    2477 
    2478         if (return_code>0) {
     2592        if (return_code > 0) {
    24792593                pjob->size += size;
    24802594                pjob_store(ev, msg_ctx, sharename, jobid, pjob);
    24812595        }
     2596err_out:
     2597        talloc_free(tmp_ctx);
    24822598        return return_code;
    24832599}
     
    27592875
    27602876        slprintf(pjob->filename, sizeof(pjob->filename)-1,
    2761                  "%s/%s%.8u.XXXXXX", lp_pathname(snum),
    2762                  PRINT_SPOOL_PREFIX, (unsigned int)jobid);
     2877                 "%s/%sXXXXXX", lp_pathname(snum), PRINT_SPOOL_PREFIX);
    27632878        pjob->fd = mkstemp(pjob->filename);
    27642879
     
    28262941
    28272942        pjob.pid = sys_getpid();
     2943        pjob.jobid = jobid;
    28282944        pjob.sysjob = -1;
    28292945        pjob.fd = -1;
     
    28903006        const char* sharename = lp_const_servicename(snum);
    28913007        struct printjob *pjob;
    2892 
    2893         pjob = print_job_find(sharename, jobid);
    2894         if (!pjob)
     3008        TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx);
     3009        if (tmp_ctx == NULL) {
    28953010                return;
     3011        }
     3012
     3013        pjob = print_job_find(tmp_ctx, sharename, jobid);
     3014        if (!pjob) {
     3015                goto err_out;
     3016        }
    28963017        /* don't allow another process to get this info - it is meaningless */
    2897         if (pjob->pid != sys_getpid())
    2898                 return;
     3018        if (pjob->pid != sys_getpid()) {
     3019                goto err_out;
     3020        }
    28993021
    29003022        pjob->page_count++;
    29013023        pjob_store(server_event_context(), msg_ctx, sharename, jobid, pjob);
     3024err_out:
     3025        talloc_free(tmp_ctx);
    29023026}
    29033027
     
    29153039        int ret;
    29163040        SMB_STRUCT_STAT sbuf;
    2917         struct printif *current_printif = get_printer_fns( snum );
     3041        struct printif *current_printif = get_printer_fns(snum);
    29183042        NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
    2919 
    2920         pjob = print_job_find(sharename, jobid);
    2921 
     3043        char *lpq_cmd;
     3044        TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx);
     3045        if (tmp_ctx == NULL) {
     3046                return NT_STATUS_NO_MEMORY;
     3047        }
     3048
     3049        pjob = print_job_find(tmp_ctx, sharename, jobid);
    29223050        if (!pjob) {
    2923                 return NT_STATUS_PRINT_CANCELLED;
     3051                status = NT_STATUS_PRINT_CANCELLED;
     3052                goto err_out;
    29243053        }
    29253054
    29263055        if (pjob->spooled || pjob->pid != sys_getpid()) {
    2927                 return NT_STATUS_ACCESS_DENIED;
     3056                status = NT_STATUS_ACCESS_DENIED;
     3057                goto err_out;
    29283058        }
    29293059
     
    29793109        }
    29803110
    2981         ret = (*(current_printif->job_submit))(snum, pjob);
    2982 
     3111        /* don't strip out characters like '$' from the printername */
     3112        lpq_cmd = talloc_string_sub2(tmp_ctx,
     3113                                     lp_lpqcommand(snum),
     3114                                     "%p",
     3115                                     lp_printername(snum),
     3116                                     false, false, false);
     3117        if (lpq_cmd == NULL) {
     3118                status = NT_STATUS_PRINT_CANCELLED;
     3119                goto fail;
     3120        }
     3121        lpq_cmd = talloc_sub_advanced(tmp_ctx,
     3122                                      lp_servicename(snum),
     3123                                      current_user_info.unix_name,
     3124                                      "",
     3125                                      current_user.ut.gid,
     3126                                      get_current_username(),
     3127                                      current_user_info.domain,
     3128                                      lpq_cmd);
     3129        if (lpq_cmd == NULL) {
     3130                status = NT_STATUS_PRINT_CANCELLED;
     3131                goto fail;
     3132        }
     3133
     3134        ret = (*(current_printif->job_submit))(snum, pjob,
     3135                                               current_printif->type, lpq_cmd);
    29833136        if (ret) {
    29843137                status = NT_STATUS_PRINT_CANCELLED;
     
    30053158        unlink(pjob->filename);
    30063159        pjob_delete(server_event_context(), msg_ctx, sharename, jobid);
     3160err_out:
     3161        talloc_free(tmp_ctx);
    30073162        return status;
    30083163}
     
    30273182        bool ret = False;
    30283183        const char* sharename = lp_servicename(snum);
     3184        TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx);
     3185        if (tmp_ctx == NULL) {
     3186                return false;
     3187        }
    30293188
    30303189        /* make sure the database is up to date */
     
    30763235                                queue[i].fs_user,
    30773236                                queue[i].fs_file);
    3078                 queue[i].job = qjob;
     3237                queue[i].sysjob = qjob;
    30793238                queue[i].size = qsize;
    30803239                queue[i].page_count = qpage_count;
     
    30933252                jobid = IVAL(cgdata.dptr, i*4);
    30943253                DEBUG(5,("get_stored_queue_info: added job = %u\n", (unsigned int)jobid));
    3095                 pjob = print_job_find(lp_const_servicename(snum), jobid);
     3254                pjob = print_job_find(tmp_ctx, lp_const_servicename(snum), jobid);
    30963255                if (!pjob) {
    30973256                        DEBUG(5,("get_stored_queue_info: failed to find added job = %u\n", (unsigned int)jobid));
     
    31003259                }
    31013260
    3102                 queue[total_count].job = jobid;
     3261                queue[total_count].sysjob = jobid;
    31033262                queue[total_count].size = pjob->size;
    31043263                queue[total_count].page_count = pjob->page_count;
     
    31093268                fstrcpy(queue[total_count].fs_file, pjob->jobname);
    31103269                total_count++;
     3270                talloc_free(pjob);
    31113271        }
    31123272
     
    31183278
    31193279                for (j = 0; j < total_count; j++) {
    3120                         if (queue[j].job == jobid) {
     3280                        if (queue[j].sysjob == jobid) {
    31213281                                found = true;
    31223282                                break;
     
    31303290                                 (unsigned int) jobid));
    31313291
    3132                         pjob = print_job_find(sharename, jobid);
     3292                        pjob = print_job_find(tmp_ctx, sharename, jobid);
    31333293                        if (pjob == NULL) {
    31343294                                DEBUG(5,("get_stored_queue_info: failed to find "
     
    31393299                        }
    31403300
    3141                         queue[j].job = jobid;
     3301                        queue[j].sysjob = jobid;
    31423302                        queue[j].size = pjob->size;
    31433303                        queue[j].page_count = pjob->page_count;
     
    31473307                        fstrcpy(queue[j].fs_user, pjob->user);
    31483308                        fstrcpy(queue[j].fs_file, pjob->jobname);
     3309                        talloc_free(pjob);
    31493310
    31503311                        DEBUG(5,("get_stored_queue_info: updated queue[%u], jobid: %u, jobname: %s\n",
     
    31743335        SAFE_FREE(data.dptr);
    31753336        SAFE_FREE(cgdata.dptr);
     3337        talloc_free(tmp_ctx);
    31763338        return ret;
    31773339}
     
    33413503        for (i=0;i<njobs;i++) {
    33423504                bool owner = is_owner(server_info, lp_const_servicename(snum),
    3343                                       queue[i].job);
     3505                                      queue[i].sysjob);
    33443506
    33453507                if (owner || can_job_admin) {
    33463508                        print_job_delete1(server_event_context(), msg_ctx,
    3347                                           snum, queue[i].job);
     3509                                          snum, queue[i].sysjob);
    33483510                }
    33493511        }
Note: See TracChangeset for help on using the changeset viewer.