Ignore:
Timestamp:
Nov 29, 2012, 1:59:04 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.9

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/server/source3/printing/printing.c

    r745 r751  
    378378***********************************************************************/
    379379
    380 static int unpack_pjob( uint8 *buf, int buflen, struct printjob *pjob )
     380static int unpack_pjob(TALLOC_CTX *mem_ctx, uint8 *buf, int buflen,
     381                       struct printjob *pjob)
    381382{
    382383        int     len = 0;
    383384        int     used;
    384         uint32 pjpid, pjsysjob, pjfd, pjstarttime, pjstatus;
     385        uint32 pjpid, pjjobid, pjsysjob, pjfd, pjstarttime, pjstatus;
    385386        uint32 pjsize, pjpage_count, pjspooled, pjsmbjob;
    386387
    387         if ( !buf || !pjob )
     388        if (!buf || !pjob) {
    388389                return -1;
    389 
    390         len += tdb_unpack(buf+len, buflen-len, "dddddddddfffff",
     390        }
     391
     392        len += tdb_unpack(buf+len, buflen-len, "ddddddddddfffff",
    391393                                &pjpid,
     394                                &pjjobid,
    392395                                &pjsysjob,
    393396                                &pjfd,
     
    404407                                pjob->queuename);
    405408
    406         if ( len == -1 )
     409        if (len == -1) {
    407410                return -1;
    408 
    409         used = unpack_devicemode(NULL, buf+len, buflen-len, &pjob->devmode);
     411        }
     412
     413        used = unpack_devicemode(mem_ctx, buf+len, buflen-len, &pjob->devmode);
    410414        if (used == -1) {
    411415                return -1;
     
    415419
    416420        pjob->pid = pjpid;
     421        pjob->jobid = pjjobid;
    417422        pjob->sysjob = pjsysjob;
    418423        pjob->fd = pjfd;
     
    432437****************************************************************************/
    433438
    434 static struct printjob *print_job_find(const char *sharename, uint32 jobid)
    435 {
    436         static struct printjob  pjob;
     439static struct printjob *print_job_find(TALLOC_CTX *mem_ctx,
     440                                       const char *sharename,
     441                                       uint32 jobid)
     442{
     443        struct printjob         *pjob;
    437444        uint32_t tmp;
    438445        TDB_DATA                ret;
     
    450457
    451458        if (!ret.dptr) {
    452                 DEBUG(10,("print_job_find: failed to find jobid %u.\n", (unsigned int)jobid ));
     459                DEBUG(10, ("print_job_find: failed to find jobid %u.\n",
     460                           jobid));
    453461                return NULL;
    454462        }
    455463
    456         talloc_free(pjob.devmode);
    457 
    458         ZERO_STRUCT( pjob );
    459 
    460         if ( unpack_pjob( ret.dptr, ret.dsize, &pjob ) == -1 ) {
    461                 DEBUG(10,("print_job_find: failed to unpack jobid %u.\n", (unsigned int)jobid ));
    462                 SAFE_FREE(ret.dptr);
    463                 return NULL;
    464         }
    465 
     464        pjob = talloc_zero(mem_ctx, struct printjob);
     465        if (pjob == NULL) {
     466                goto err_out;
     467        }
     468
     469        if (unpack_pjob(mem_ctx, ret.dptr, ret.dsize, pjob) == -1) {
     470                DEBUG(10, ("failed to unpack jobid %u.\n", jobid));
     471                talloc_free(pjob);
     472                pjob = NULL;
     473                goto err_out;
     474        }
     475
     476        DEBUG(10,("print_job_find: returning system job %d for jobid %u.\n",
     477                  pjob->sysjob, jobid));
     478        SMB_ASSERT(pjob->jobid == jobid);
     479
     480err_out:
    466481        SAFE_FREE(ret.dptr);
    467 
    468         DEBUG(10,("print_job_find: returning system job %d for jobid %u.\n",
    469                         (int)pjob.sysjob, (unsigned int)jobid ));
    470 
    471         return &pjob;
     482        return pjob;
    472483}
    473484
     
    494505
    495506        if (state->sysjob == pjob->sysjob) {
    496                 uint32 jobid = IVAL(key.dptr,0);
    497 
    498                 state->sysjob_to_jobid_value = jobid;
     507                state->sysjob_to_jobid_value = pjob->jobid;
    499508                return 1;
    500509        }
    501510
    502511        return 0;
     512}
     513
     514static uint32 sysjob_to_jobid_pdb(struct tdb_print_db *pdb, int sysjob)
     515{
     516        struct unixjob_traverse_state state;
     517
     518        state.sysjob = sysjob;
     519        state.sysjob_to_jobid_value = (uint32)-1;
     520
     521        tdb_traverse(pdb->tdb, unixjob_traverse_fn, &state);
     522
     523        return state.sysjob_to_jobid_value;
    503524}
    504525
     
    742763                len = 0;
    743764                buflen = newlen;
    744                 len += tdb_pack(buf+len, buflen-len, "dddddddddfffff",
     765                len += tdb_pack(buf+len, buflen-len, "ddddddddddfffff",
    745766                                (uint32)pjob->pid,
     767                                (uint32)pjob->jobid,
    746768                                (uint32)pjob->sysjob,
    747769                                (uint32)pjob->fd,
     
    780802        /* Send notify updates for what has changed */
    781803
    782         if ( ret ) {
     804        if (ret) {
    783805                bool changed = false;
    784806                struct printjob old_pjob;
    785807
    786                 if ( old_data.dsize )
    787                 {
    788                         if ( unpack_pjob( old_data.dptr, old_data.dsize, &old_pjob ) != -1 )
    789                         {
    790                                 pjob_store_notify(server_event_context(),
     808                if (old_data.dsize) {
     809                        TALLOC_CTX *tmp_ctx = talloc_new(ev);
     810                        if (tmp_ctx == NULL)
     811                                goto done;
     812
     813                        len = unpack_pjob(tmp_ctx, old_data.dptr,
     814                                          old_data.dsize, &old_pjob);
     815                        if (len != -1 ) {
     816                                pjob_store_notify(ev,
    791817                                                  msg_ctx,
    792818                                                  sharename, jobid, &old_pjob,
    793819                                                  pjob,
    794820                                                  &changed);
    795                                 talloc_free(old_pjob.devmode);
    796 
    797821                                if (changed) {
    798822                                        add_to_jobs_changed(pdb, jobid);
    799823                                }
    800824                        }
    801 
    802                 }
    803                 else {
     825                        talloc_free(tmp_ctx);
     826
     827                } else {
    804828                        /* new job */
    805                         pjob_store_notify(server_event_context(), msg_ctx,
     829                        pjob_store_notify(ev, msg_ctx,
    806830                                          sharename, jobid, NULL, pjob,
    807831                                          &changed);
     
    809833        }
    810834
     835done:
    811836        release_print_db(pdb);
    812 done:
    813837        SAFE_FREE( old_data.dptr );
    814838        SAFE_FREE( buf );
     
    829853        uint32 job_status = 0;
    830854        struct tdb_print_db *pdb;
    831 
    832         pdb = get_print_db_byname( sharename );
    833 
    834         if (!pdb)
     855        TALLOC_CTX *tmp_ctx = talloc_new(ev);
     856        if (tmp_ctx == NULL) {
    835857                return;
    836 
    837         pjob = print_job_find( sharename, jobid );
    838 
     858        }
     859
     860        pdb = get_print_db_byname(sharename);
     861        if (!pdb) {
     862                goto err_out;
     863        }
     864
     865        pjob = print_job_find(tmp_ctx, sharename, jobid);
    839866        if (!pjob) {
    840                 DEBUG(5, ("pjob_delete: we were asked to delete nonexistent job %u\n",
    841                                         (unsigned int)jobid));
    842                 release_print_db(pdb);
    843                 return;
     867                DEBUG(5, ("we were asked to delete nonexistent job %u\n",
     868                          jobid));
     869                goto err_release;
    844870        }
    845871
     
    855881        tdb_delete(pdb->tdb, print_key(jobid, &tmp));
    856882        remove_from_jobs_added(sharename, jobid);
    857         release_print_db( pdb );
    858883        rap_jobid_delete(sharename, jobid);
     884err_release:
     885        release_print_db(pdb);
     886err_out:
     887        talloc_free(tmp_ctx);
    859888}
    860889
     
    869898{
    870899        struct printjob pj, *old_pj;
    871 
    872         if (jobid == (uint32)-1)
    873                 jobid = q->job + UNIX_JOB_START;
     900        TALLOC_CTX *tmp_ctx = talloc_new(ev);
     901        if (tmp_ctx == NULL) {
     902                return;
     903        }
     904
     905        if (jobid == (uint32)-1) {
     906                jobid = q->sysjob + UNIX_JOB_START;
     907        }
    874908
    875909        /* Preserve the timestamp on an existing unix print job */
    876910
    877         old_pj = print_job_find(sharename, jobid);
     911        old_pj = print_job_find(tmp_ctx, sharename, jobid);
    878912
    879913        ZERO_STRUCT(pj);
    880914
    881915        pj.pid = (pid_t)-1;
    882         pj.sysjob = q->job;
     916        pj.jobid = jobid;
     917        pj.sysjob = q->sysjob;
    883918        pj.fd = -1;
    884919        pj.starttime = old_pj ? old_pj->starttime : q->time;
     
    898933
    899934        pjob_store(ev, msg_ctx, sharename, jobid, &pj);
     935        talloc_free(tmp_ctx);
    900936}
    901937
     
    910946        struct tevent_context *ev;
    911947        struct messaging_context *msg_ctx;
     948        TALLOC_CTX *mem_ctx;
    912949};
    913950
     
    926963                return 0;
    927964
    928         jobid = IVAL(key.dptr, 0);
    929         if ( unpack_pjob( data.dptr, data.dsize, &pjob ) == -1 )
     965        if (unpack_pjob(ts->mem_ctx, data.dptr, data.dsize, &pjob) == -1)
    930966                return 0;
    931967        talloc_free(pjob.devmode);
    932 
     968        jobid = pjob.jobid;
    933969
    934970        if (!pjob.smbjob) {
    935971                /* remove a unix job if it isn't in the system queue any more */
    936 
    937972                for (i=0;i<ts->qcount;i++) {
    938                         uint32 u_jobid = (ts->queue[i].job + UNIX_JOB_START);
    939                         if (jobid == u_jobid)
     973                        if (ts->queue[i].sysjob == pjob.sysjob) {
    940974                                break;
     975                        }
    941976                }
    942977                if (i == ts->qcount) {
     
    9691004        /* this check only makes sense for jobs submitted from Windows clients */
    9701005
    971         if ( pjob.smbjob ) {
     1006        if (pjob.smbjob) {
    9721007                for (i=0;i<ts->qcount;i++) {
    973                         uint32 curr_jobid;
    974 
    9751008                        if ( pjob.status == LPQ_DELETED )
    9761009                                continue;
    9771010
    978                         curr_jobid = print_parse_jobid(ts->queue[i].fs_file);
    979 
    980                         if (jobid == curr_jobid) {
     1011                        if (ts->queue[i].sysjob == pjob.sysjob) {
    9811012
    9821013                                /* try to clean up any jobs that need to be deleted */
     
    10331064        }
    10341065
    1035         /* Save the pjob attributes we will store.
    1036            FIXME!!! This is the only place where queue->job
    1037            represents the SMB jobid      --jerry */
    1038 
    1039         ts->queue[i].job = jobid;
     1066        /* Save the pjob attributes we will store. */
     1067        ts->queue[i].sysjob = pjob.sysjob;
    10401068        ts->queue[i].size = pjob.size;
    10411069        ts->queue[i].page_count = pjob.page_count;
     
    11881216                qcount++;
    11891217                data.dsize += tdb_pack(NULL, 0, "ddddddff",
    1190                                 (uint32)queue[i].job,
     1218                                (uint32)queue[i].sysjob,
    11911219                                (uint32)queue[i].size,
    11921220                                (uint32)queue[i].page_count,
     
    12081236
    12091237                len += tdb_pack(data.dptr + len, data.dsize - len, "ddddddff",
    1210                                 (uint32)queue[i].job,
     1238                                (uint32)queue[i].sysjob,
    12111239                                (uint32)queue[i].size,
    12121240                                (uint32)queue[i].page_count,
     
    13221350****************************************************************************/
    13231351
    1324 static void print_queue_update_internal( struct tevent_context *ev,
    1325                                          struct messaging_context *msg_ctx,
    1326                                          const char *sharename,
    1327                                          struct printif *current_printif,
    1328                                          char *lpq_command, char *lprm_command )
     1352static void print_queue_update_internal(struct tevent_context *ev,
     1353                                        struct messaging_context *msg_ctx,
     1354                                        const char *sharename,
     1355                                        struct printif *current_printif,
     1356                                        char *lpq_command, char *lprm_command)
    13291357{
    13301358        int i, qcount;
     
    13381366        fstring keystr, cachestr;
    13391367        struct tdb_print_db *pdb = get_print_db_byname(sharename);
    1340 
    1341         if (!pdb) {
     1368        TALLOC_CTX *tmp_ctx = talloc_new(ev);
     1369
     1370        if ((pdb == NULL) || (tmp_ctx == NULL)) {
    13421371                return;
    13431372        }
     
    13801409          fill in any system job numbers as we go
    13811410        */
    1382 
    13831411        jcdata = get_jobs_added_data(pdb);
    13841412
    13851413        for (i=0; i<qcount; i++) {
    1386                 uint32 jobid = print_parse_jobid(queue[i].fs_file);
    1387 
     1414                uint32 jobid = sysjob_to_jobid_pdb(pdb, queue[i].sysjob);
    13881415                if (jobid == (uint32)-1) {
    13891416                        /* assume its a unix print job */
     
    13941421
    13951422                /* we have an active SMB print job - update its status */
    1396                 pjob = print_job_find(sharename, jobid);
     1423                pjob = print_job_find(tmp_ctx, sharename, jobid);
    13971424                if (!pjob) {
    13981425                        /* err, somethings wrong. Probably smbd was restarted
    13991426                           with jobs in the queue. All we can do is treat them
    14001427                           like unix jobs. Pity. */
     1428                        DEBUG(1, ("queued print job %d not found in jobs list, "
     1429                                  "assuming unix job\n", jobid));
    14011430                        print_unix_job(ev, msg_ctx,
    14021431                                       sharename, &queue[i], jobid);
    14031432                        continue;
    14041433                }
    1405 
    1406                 pjob->sysjob = queue[i].job;
    14071434
    14081435                /* don't reset the status on jobs to be deleted */
     
    14301457        tstruct.ev = ev;
    14311458        tstruct.msg_ctx = msg_ctx;
     1459        tstruct.mem_ctx = tmp_ctx;
    14321460
    14331461        tdb_traverse(pdb->tdb, traverse_fn_delete, (void *)&tstruct);
     
    14371465
    14381466        SAFE_FREE(tstruct.queue);
     1467        talloc_free(tmp_ctx);
    14391468
    14401469        DEBUG(10,("print_queue_update_internal: printer %s INFO/total_jobs = %d\n",
     
    16321661}
    16331662
     1663static bool printer_housekeeping_fn(const struct timeval *now,
     1664                                    void *private_data)
     1665{
     1666        static time_t last_pcap_reload_time = 0;
     1667        time_t printcap_cache_time = (time_t)lp_printcap_cache_time();
     1668        time_t t = time_mono(NULL);
     1669
     1670        DEBUG(5, ("printer housekeeping\n"));
     1671
     1672        /* if periodic printcap rescan is enabled, see if it's time to reload */
     1673        if ((printcap_cache_time != 0)
     1674         && (t >= (last_pcap_reload_time + printcap_cache_time))) {
     1675                DEBUG( 3,( "Printcap cache time expired.\n"));
     1676                pcap_cache_reload(server_event_context(),
     1677                                  smbd_messaging_context(),
     1678                                  &reload_pcap_change_notify);
     1679                last_pcap_reload_time = t;
     1680        }
     1681
     1682        return true;
     1683}
     1684
    16341685static pid_t background_lpq_updater_pid = -1;
    16351686
     
    17031754                        DEBUG(0,("tevent_add_fd() failed for pause_pipe\n"));
    17041755                        smb_panic("tevent_add_fd() failed for pause_pipe");
     1756                }
     1757
     1758                if (!(event_add_idle(ev, NULL,
     1759                                     timeval_set(SMBD_HOUSEKEEPING_INTERVAL, 0),
     1760                                     "printer_housekeeping",
     1761                                     printer_housekeeping_fn,
     1762                                     NULL))) {
     1763                        DEBUG(0, ("Could not add printing housekeeping event\n"));
     1764                        exit(1);
    17051765                }
    17061766
     
    20492109
    20502110/****************************************************************************
    2051  Give the filename used for a jobid.
     2111 Return the device mode asigned to a specific print job.
    20522112 Only valid for the process doing the spooling and when the job
    20532113 has not been spooled.
    20542114****************************************************************************/
    20552115
    2056 char *print_job_fname(const char* sharename, uint32 jobid)
    2057 {
    2058         struct printjob *pjob = print_job_find(sharename, jobid);
    2059         if (!pjob || pjob->spooled || pjob->pid != sys_getpid())
     2116struct spoolss_DeviceMode *print_job_devmode(TALLOC_CTX *mem_ctx,
     2117                                             const char *sharename,
     2118                                             uint32 jobid)
     2119{
     2120        struct printjob *pjob = print_job_find(mem_ctx, sharename, jobid);
     2121        if (pjob == NULL) {
    20602122                return NULL;
    2061         return pjob->filename;
    2062 }
    2063 
    2064 
    2065 /****************************************************************************
    2066  Give the filename used for a jobid.
    2067  Only valid for the process doing the spooling and when the job
    2068  has not been spooled.
    2069 ****************************************************************************/
    2070 
    2071 struct spoolss_DeviceMode *print_job_devmode(const char* sharename, uint32 jobid)
    2072 {
    2073         struct printjob *pjob = print_job_find(sharename, jobid);
    2074 
    2075         if ( !pjob )
    2076                 return NULL;
     2123        }
    20772124
    20782125        return pjob->devmode;
     
    20882135{
    20892136        struct printjob *pjob;
    2090 
    2091         pjob = print_job_find(sharename, jobid);
    2092         if (!pjob || pjob->pid != sys_getpid())
    2093                 return False;
     2137        bool ret;
     2138        TALLOC_CTX *tmp_ctx = talloc_new(ev);
     2139        if (tmp_ctx == NULL) {
     2140                return false;
     2141        }
     2142
     2143        pjob = print_job_find(tmp_ctx, sharename, jobid);
     2144        if (!pjob || pjob->pid != sys_getpid()) {
     2145                ret = false;
     2146                goto err_out;
     2147        }
    20942148
    20952149        fstrcpy(pjob->jobname, name);
    2096         return pjob_store(ev, msg_ctx, sharename, jobid, pjob);
     2150        ret = pjob_store(ev, msg_ctx, sharename, jobid, pjob);
     2151err_out:
     2152        talloc_free(tmp_ctx);
     2153        return ret;
    20972154}
    20982155
     
    21052162        struct printjob *pjob;
    21062163
    2107         pjob = print_job_find(sharename, jobid);
     2164        pjob = print_job_find(mem_ctx, sharename, jobid);
    21082165        if (!pjob || pjob->pid != sys_getpid()) {
    21092166                return false;
    21102167        }
    21112168
    2112         *name = talloc_strdup(mem_ctx, pjob->jobname);
    2113         if (!*name) {
    2114                 return false;
    2115         }
    2116 
     2169        *name = pjob->jobname;
    21172170        return true;
    21182171}
     
    21872240{
    21882241        const char* sharename = lp_const_servicename(snum);
    2189         struct printjob *pjob = print_job_find(sharename, jobid);
     2242        struct printjob *pjob;
    21902243        int result = 0;
    21912244        struct printif *current_printif = get_printer_fns( snum );
    2192 
    2193         if (!pjob)
    2194                 return False;
     2245        bool ret;
     2246        TALLOC_CTX *tmp_ctx = talloc_new(ev);
     2247        if (tmp_ctx == NULL) {
     2248                return false;
     2249        }
     2250
     2251        pjob = print_job_find(tmp_ctx, sharename, jobid);
     2252        if (!pjob) {
     2253                ret = false;
     2254                goto err_out;
     2255        }
    21952256
    21962257        /*
     
    21982259         */
    21992260
    2200         if (pjob->status == LPQ_DELETING)
    2201                 return True;
     2261        if (pjob->status == LPQ_DELETING) {
     2262                ret = true;
     2263                goto err_out;
     2264        }
    22022265
    22032266        /* Hrm - we need to be able to cope with deleting a job before it
     
    22292292                        int njobs = 1;
    22302293
    2231                         if (!pdb)
    2232                                 return False;
     2294                        if (!pdb) {
     2295                                ret = false;
     2296                                goto err_out;
     2297                        }
    22332298                        pjob_delete(ev, msg_ctx, sharename, jobid);
    22342299                        /* Ensure we keep a rough count of the number of total jobs... */
     
    22402305        remove_from_jobs_added( sharename, jobid );
    22412306
    2242         return (result == 0);
     2307        ret = (result == 0);
     2308err_out:
     2309        talloc_free(tmp_ctx);
     2310        return ret;
    22432311}
    22442312
     
    22512319                     uint32 jobid)
    22522320{
    2253         struct printjob *pjob = print_job_find(servicename, jobid);
    2254 
    2255         if (!pjob || !server_info)
    2256                 return False;
    2257 
    2258         return strequal(pjob->user, server_info->sanitized_username);
     2321        struct printjob *pjob;
     2322        bool ret;
     2323        TALLOC_CTX *tmp_ctx = talloc_new(server_info);
     2324        if (tmp_ctx == NULL) {
     2325                return false;
     2326        }
     2327
     2328        pjob = print_job_find(tmp_ctx, servicename, jobid);
     2329        if (!pjob || !server_info) {
     2330                ret = false;
     2331                goto err_out;
     2332        }
     2333
     2334        ret = strequal(pjob->user, server_info->sanitized_username);
     2335err_out:
     2336        talloc_free(tmp_ctx);
     2337        return ret;
    22592338}
    22602339
     
    22702349        struct printjob *pjob;
    22712350        bool    owner;
    2272         char    *fname;
     2351        WERROR werr;
     2352        TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx);
     2353        if (tmp_ctx == NULL) {
     2354                return WERR_NOT_ENOUGH_MEMORY;
     2355        }
    22732356
    22742357        owner = is_owner(server_info, lp_const_servicename(snum), jobid);
     
    22902373                /* END_ADMIN_LOG */
    22912374
    2292                 return WERR_ACCESS_DENIED;
     2375                werr = WERR_ACCESS_DENIED;
     2376                goto err_out;
    22932377        }
    22942378
     
    23002384         */
    23012385
    2302         fname = print_job_fname(sharename, jobid);
    2303         if (fname != NULL) {
    2304                 /* remove the spool file */
    2305                 DEBUG(10, ("print_job_delete: "
    2306                            "Removing spool file [%s]\n", fname));
    2307                 if (unlink(fname) == -1) {
    2308                         return map_werror_from_unix(errno);
     2386        pjob = print_job_find(tmp_ctx, sharename, jobid);
     2387        if (!pjob || pjob->spooled || pjob->pid != getpid()) {
     2388                DEBUG(10, ("Skipping spool file removal for job %u\n", jobid));
     2389        } else {
     2390                DEBUG(10, ("Removing spool file [%s]\n", pjob->filename));
     2391                if (unlink(pjob->filename) == -1) {
     2392                        werr = map_werror_from_unix(errno);
     2393                        goto err_out;
    23092394                }
    23102395        }
    23112396
    23122397        if (!print_job_delete1(server_event_context(), msg_ctx, snum, jobid)) {
    2313                 return WERR_ACCESS_DENIED;
     2398                werr = WERR_ACCESS_DENIED;
     2399                goto err_out;
    23142400        }
    23152401
     
    23192405        print_queue_update(msg_ctx, snum, True);
    23202406
    2321         pjob = print_job_find(sharename, jobid);
     2407        pjob = print_job_find(tmp_ctx, sharename, jobid);
    23222408        if (pjob && (pjob->status != LPQ_DELETING)) {
    2323                 return WERR_ACCESS_DENIED;
    2324         }
    2325 
    2326         return WERR_PRINTER_HAS_JOBS_QUEUED;
     2409                werr = WERR_ACCESS_DENIED;
     2410                goto err_out;
     2411        }
     2412        werr = WERR_PRINTER_HAS_JOBS_QUEUED;
     2413
     2414err_out:
     2415        talloc_free(tmp_ctx);
     2416        return werr;
    23272417}
    23282418
     
    23312421****************************************************************************/
    23322422
    2333 bool print_job_pause(const struct auth_serversupplied_info *server_info,
     2423WERROR print_job_pause(const struct auth_serversupplied_info *server_info,
    23342424                     struct messaging_context *msg_ctx,
    2335                      int snum, uint32 jobid, WERROR *errcode)
     2425                     int snum, uint32 jobid)
    23362426{
    23372427        const char* sharename = lp_const_servicename(snum);
     
    23392429        int ret = -1;
    23402430        struct printif *current_printif = get_printer_fns( snum );
    2341 
    2342         pjob = print_job_find(sharename, jobid);
    2343 
     2431        WERROR werr;
     2432        TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx);
     2433        if (tmp_ctx == NULL) {
     2434                return WERR_NOT_ENOUGH_MEMORY;
     2435        }
     2436
     2437        pjob = print_job_find(tmp_ctx, sharename, jobid);
    23442438        if (!pjob || !server_info) {
    23452439                DEBUG(10, ("print_job_pause: no pjob or user for jobid %u\n",
    23462440                        (unsigned int)jobid ));
    2347                 return False;
     2441                werr = WERR_INVALID_PARAM;
     2442                goto err_out;
    23482443        }
    23492444
     
    23512446                DEBUG(10, ("print_job_pause: not spooled or bad sysjob = %d for jobid %u\n",
    23522447                        (int)pjob->sysjob, (unsigned int)jobid ));
    2353                 return False;
     2448                werr = WERR_INVALID_PARAM;
     2449                goto err_out;
    23542450        }
    23552451
     
    23672463                /* END_ADMIN_LOG */
    23682464
    2369                 *errcode = WERR_ACCESS_DENIED;
    2370                 return False;
     2465                werr = WERR_ACCESS_DENIED;
     2466                goto err_out;
    23712467        }
    23722468
     
    23752471
    23762472        if (ret != 0) {
    2377                 *errcode = WERR_INVALID_PARAM;
    2378                 return False;
     2473                werr = WERR_INVALID_PARAM;
     2474                goto err_out;
    23792475        }
    23802476
     
    23882484
    23892485        /* how do we tell if this succeeded? */
    2390 
    2391         return True;
     2486        werr = WERR_OK;
     2487err_out:
     2488        talloc_free(tmp_ctx);
     2489        return werr;
    23922490}
    23932491
     
    23962494****************************************************************************/
    23972495
    2398 bool print_job_resume(const struct auth_serversupplied_info *server_info,
     2496WERROR print_job_resume(const struct auth_serversupplied_info *server_info,
    23992497                      struct messaging_context *msg_ctx,
    2400                       int snum, uint32 jobid, WERROR *errcode)
     2498                      int snum, uint32 jobid)
    24012499{
    24022500        const char *sharename = lp_const_servicename(snum);
     
    24042502        int ret;
    24052503        struct printif *current_printif = get_printer_fns( snum );
    2406 
    2407         pjob = print_job_find(sharename, jobid);
    2408 
     2504        WERROR werr;
     2505        TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx);
     2506        if (tmp_ctx == NULL)
     2507                return WERR_NOT_ENOUGH_MEMORY;
     2508
     2509        pjob = print_job_find(tmp_ctx, sharename, jobid);
    24092510        if (!pjob || !server_info) {
    24102511                DEBUG(10, ("print_job_resume: no pjob or user for jobid %u\n",
    24112512                        (unsigned int)jobid ));
    2412                 return False;
     2513                werr = WERR_INVALID_PARAM;
     2514                goto err_out;
    24132515        }
    24142516
     
    24162518                DEBUG(10, ("print_job_resume: not spooled or bad sysjob = %d for jobid %u\n",
    24172519                        (int)pjob->sysjob, (unsigned int)jobid ));
    2418                 return False;
     2520                werr = WERR_INVALID_PARAM;
     2521                goto err_out;
    24192522        }
    24202523
     
    24232526                                JOB_ACCESS_ADMINISTER)) {
    24242527                DEBUG(3, ("resume denied by security descriptor\n"));
    2425                 *errcode = WERR_ACCESS_DENIED;
    24262528
    24272529                /* BEGIN_ADMIN_LOG */
     
    24322534                              lp_printername(snum) );
    24332535                /* END_ADMIN_LOG */
    2434                 return False;
     2536                werr = WERR_ACCESS_DENIED;
     2537                goto err_out;
    24352538        }
    24362539
     
    24382541
    24392542        if (ret != 0) {
    2440                 *errcode = WERR_INVALID_PARAM;
    2441                 return False;
     2543                werr = WERR_INVALID_PARAM;
     2544                goto err_out;
    24422545        }
    24432546
     
    24502553                          JOB_STATUS_QUEUED);
    24512554
    2452         return True;
     2555        werr = WERR_OK;
     2556err_out:
     2557        talloc_free(tmp_ctx);
     2558        return werr;
    24532559}
    24542560
     
    24642570        ssize_t return_code;
    24652571        struct printjob *pjob;
    2466 
    2467         pjob = print_job_find(sharename, jobid);
    2468 
    2469         if (!pjob)
     2572        TALLOC_CTX *tmp_ctx = talloc_new(ev);
     2573        if (tmp_ctx == NULL) {
    24702574                return -1;
     2575        }
     2576
     2577        pjob = print_job_find(tmp_ctx, sharename, jobid);
     2578        if (!pjob) {
     2579                return_code = -1;
     2580                goto err_out;
     2581        }
     2582
    24712583        /* don't allow another process to get this info - it is meaningless */
    2472         if (pjob->pid != sys_getpid())
    2473                 return -1;
     2584        if (pjob->pid != sys_getpid()) {
     2585                return_code = -1;
     2586                goto err_out;
     2587        }
    24742588
    24752589        /* if SMBD is spooling this can't be allowed */
    24762590        if (pjob->status == PJOB_SMBD_SPOOLING) {
    2477                 return -1;
     2591                return_code = -1;
     2592                goto err_out;
    24782593        }
    24792594
    24802595        return_code = write_data(pjob->fd, buf, size);
    2481 
    2482         if (return_code>0) {
     2596        if (return_code > 0) {
    24832597                pjob->size += size;
    24842598                pjob_store(ev, msg_ctx, sharename, jobid, pjob);
    24852599        }
     2600err_out:
     2601        talloc_free(tmp_ctx);
    24862602        return return_code;
    24872603}
     
    27632879
    27642880        slprintf(pjob->filename, sizeof(pjob->filename)-1,
    2765                  "%s/%s%.8u.XXXXXX", lp_pathname(snum),
    2766                  PRINT_SPOOL_PREFIX, (unsigned int)jobid);
     2881                 "%s/%sXXXXXX", lp_pathname(snum), PRINT_SPOOL_PREFIX);
    27672882        pjob->fd = mkstemp(pjob->filename);
    27682883
     
    28302945
    28312946        pjob.pid = sys_getpid();
     2947        pjob.jobid = jobid;
    28322948        pjob.sysjob = -1;
    28332949        pjob.fd = -1;
     
    28943010        const char* sharename = lp_const_servicename(snum);
    28953011        struct printjob *pjob;
    2896 
    2897         pjob = print_job_find(sharename, jobid);
    2898         if (!pjob)
     3012        TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx);
     3013        if (tmp_ctx == NULL) {
    28993014                return;
     3015        }
     3016
     3017        pjob = print_job_find(tmp_ctx, sharename, jobid);
     3018        if (!pjob) {
     3019                goto err_out;
     3020        }
    29003021        /* don't allow another process to get this info - it is meaningless */
    2901         if (pjob->pid != sys_getpid())
    2902                 return;
     3022        if (pjob->pid != sys_getpid()) {
     3023                goto err_out;
     3024        }
    29033025
    29043026        pjob->page_count++;
    29053027        pjob_store(server_event_context(), msg_ctx, sharename, jobid, pjob);
     3028err_out:
     3029        talloc_free(tmp_ctx);
    29063030}
    29073031
     
    29193043        int ret;
    29203044        SMB_STRUCT_STAT sbuf;
    2921         struct printif *current_printif = get_printer_fns( snum );
     3045        struct printif *current_printif = get_printer_fns(snum);
    29223046        NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
    2923 
    2924         pjob = print_job_find(sharename, jobid);
    2925 
     3047        char *lpq_cmd;
     3048        TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx);
     3049        if (tmp_ctx == NULL) {
     3050                return NT_STATUS_NO_MEMORY;
     3051        }
     3052
     3053        pjob = print_job_find(tmp_ctx, sharename, jobid);
    29263054        if (!pjob) {
    2927                 return NT_STATUS_PRINT_CANCELLED;
     3055                status = NT_STATUS_PRINT_CANCELLED;
     3056                goto err_out;
    29283057        }
    29293058
    29303059        if (pjob->spooled || pjob->pid != sys_getpid()) {
    2931                 return NT_STATUS_ACCESS_DENIED;
     3060                status = NT_STATUS_ACCESS_DENIED;
     3061                goto err_out;
    29323062        }
    29333063
     
    29833113        }
    29843114
    2985         ret = (*(current_printif->job_submit))(snum, pjob);
    2986 
     3115        /* don't strip out characters like '$' from the printername */
     3116        lpq_cmd = talloc_string_sub2(tmp_ctx,
     3117                                     lp_lpqcommand(snum),
     3118                                     "%p",
     3119                                     lp_printername(snum),
     3120                                     false, false, false);
     3121        if (lpq_cmd == NULL) {
     3122                status = NT_STATUS_PRINT_CANCELLED;
     3123                goto fail;
     3124        }
     3125        lpq_cmd = talloc_sub_advanced(tmp_ctx,
     3126                                      lp_servicename(snum),
     3127                                      current_user_info.unix_name,
     3128                                      "",
     3129                                      current_user.ut.gid,
     3130                                      get_current_username(),
     3131                                      current_user_info.domain,
     3132                                      lpq_cmd);
     3133        if (lpq_cmd == NULL) {
     3134                status = NT_STATUS_PRINT_CANCELLED;
     3135                goto fail;
     3136        }
     3137
     3138        ret = (*(current_printif->job_submit))(snum, pjob,
     3139                                               current_printif->type, lpq_cmd);
    29873140        if (ret) {
    29883141                status = NT_STATUS_PRINT_CANCELLED;
     
    30093162        unlink(pjob->filename);
    30103163        pjob_delete(server_event_context(), msg_ctx, sharename, jobid);
     3164err_out:
     3165        talloc_free(tmp_ctx);
    30113166        return status;
    30123167}
     
    30313186        bool ret = False;
    30323187        const char* sharename = lp_servicename(snum);
     3188        TALLOC_CTX *tmp_ctx = talloc_new(msg_ctx);
     3189        if (tmp_ctx == NULL) {
     3190                return false;
     3191        }
    30333192
    30343193        /* make sure the database is up to date */
     
    30803239                                queue[i].fs_user,
    30813240                                queue[i].fs_file);
    3082                 queue[i].job = qjob;
     3241                queue[i].sysjob = qjob;
    30833242                queue[i].size = qsize;
    30843243                queue[i].page_count = qpage_count;
     
    30973256                jobid = IVAL(cgdata.dptr, i*4);
    30983257                DEBUG(5,("get_stored_queue_info: added job = %u\n", (unsigned int)jobid));
    3099                 pjob = print_job_find(lp_const_servicename(snum), jobid);
     3258                pjob = print_job_find(tmp_ctx, lp_const_servicename(snum), jobid);
    31003259                if (!pjob) {
    31013260                        DEBUG(5,("get_stored_queue_info: failed to find added job = %u\n", (unsigned int)jobid));
     
    31043263                }
    31053264
    3106                 queue[total_count].job = jobid;
     3265                queue[total_count].sysjob = jobid;
    31073266                queue[total_count].size = pjob->size;
    31083267                queue[total_count].page_count = pjob->page_count;
     
    31133272                fstrcpy(queue[total_count].fs_file, pjob->jobname);
    31143273                total_count++;
     3274                talloc_free(pjob);
    31153275        }
    31163276
     
    31223282
    31233283                for (j = 0; j < total_count; j++) {
    3124                         if (queue[j].job == jobid) {
     3284                        if (queue[j].sysjob == jobid) {
    31253285                                found = true;
    31263286                                break;
     
    31343294                                 (unsigned int) jobid));
    31353295
    3136                         pjob = print_job_find(sharename, jobid);
     3296                        pjob = print_job_find(tmp_ctx, sharename, jobid);
    31373297                        if (pjob == NULL) {
    31383298                                DEBUG(5,("get_stored_queue_info: failed to find "
     
    31433303                        }
    31443304
    3145                         queue[j].job = jobid;
     3305                        queue[j].sysjob = jobid;
    31463306                        queue[j].size = pjob->size;
    31473307                        queue[j].page_count = pjob->page_count;
     
    31513311                        fstrcpy(queue[j].fs_user, pjob->user);
    31523312                        fstrcpy(queue[j].fs_file, pjob->jobname);
     3313                        talloc_free(pjob);
    31533314
    31543315                        DEBUG(5,("get_stored_queue_info: updated queue[%u], jobid: %u, jobname: %s\n",
     
    31783339        SAFE_FREE(data.dptr);
    31793340        SAFE_FREE(cgdata.dptr);
     3341        talloc_free(tmp_ctx);
    31803342        return ret;
    31813343}
     
    33453507        for (i=0;i<njobs;i++) {
    33463508                bool owner = is_owner(server_info, lp_const_servicename(snum),
    3347                                       queue[i].job);
     3509                                      queue[i].sysjob);
    33483510
    33493511                if (owner || can_job_admin) {
    33503512                        print_job_delete1(server_event_context(), msg_ctx,
    3351                                           snum, queue[i].job);
     3513                                          snum, queue[i].sysjob);
    33523514                }
    33533515        }
Note: See TracChangeset for help on using the changeset viewer.