~ubuntu-branches/ubuntu/gutsy/samba/gutsy-updates

« back to all changes in this revision

Viewing changes to source/printing/printing.c

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Mitchell
  • Date: 2006-11-28 20:14:37 UTC
  • mfrom: (0.10.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061128201437-a6x4lzlhempazocp
Tags: 3.0.23d-1ubuntu1
* Merge from debian unstable.
* Drop python2.4-samba, replace with python-samba. Added Conflicts/Replaces
  on python2.4-samba
* Drop track-connection-dos.patch, ubuntu-winbind-panic.patch, 
  ubuntu-fix-ldap.patch, ubuntu-setlocale.patch, ubuntu-setlocale-fixes.patch
* Remaining Ubuntu changes:
  - Revert Debian's installation of mount.cifs and umount.cifs as suid
  - Comment out the default [homes] shares and add more verbose comments to
    explain what they do and how they work (closes: launchpad.net/27608)
  - Add a "valid users = %S" stanza to the commented-out [homes] section, to
    show users how to restrict access to \\server\username to only username.
  - Change the (commented-out) "printer admin" example to use "@lpadmin"
    instead of "@ntadmin", since the lpadmin group is used for spool admin.
  - Alter the panic-action script to encourage users to report their
    bugs in Ubuntu packages to Ubuntu, rather than reporting to Debian.
    Modify text to more closely match the Debian script
  - Munge our init script to deal with the fact that our implementation
    (or lack thereof) of log_daemon_msg and log_progress_msg differs
    from Debian's implementation of the same (Ubuntu #19691)
  - Kept ubuntu-auxsrc.patch: some auxilliary sources (undocumented in 
    previous changelogs)
  - Set default workgroup to MSHOME

Show diffs side-by-side

added added

removed removed

Lines of Context:
197
197
                pdb = get_print_db_byname(lp_const_servicename(snum));
198
198
                if (!pdb)
199
199
                        continue;
200
 
                if (tdb_lock_bystring(pdb->tdb, sversion, 0) == -1) {
 
200
                if (tdb_lock_bystring(pdb->tdb, sversion) == -1) {
201
201
                        DEBUG(0,("print_backend_init: Failed to open printer %s database\n", lp_const_servicename(snum) ));
202
202
                        release_print_db(pdb);
203
203
                        return False;
234
234
 when asked for (and only when supported)
235
235
****************************************************************************/
236
236
 
237
 
static struct printif *get_printer_fns_from_type( int type )
 
237
static struct printif *get_printer_fns_from_type( enum printing_types type )
238
238
{
239
239
        struct printif *printer_fns = &generic_printif;
240
240
 
257
257
 
258
258
static struct printif *get_printer_fns( int snum )
259
259
{
260
 
        return get_printer_fns_from_type( lp_printing(snum) );
 
260
        return get_printer_fns_from_type( (enum printing_types)lp_printing(snum) );
261
261
}
262
262
 
263
263
 
337
337
        TDB_DATA                ret;
338
338
        struct tdb_print_db     *pdb = get_print_db_byname(sharename);
339
339
        
 
340
        DEBUG(10,("print_job_find: looking up job %u for share %s\n",
 
341
                        (unsigned int)jobid, sharename ));
340
342
 
341
 
        if (!pdb)
 
343
        if (!pdb) {
342
344
                return NULL;
 
345
        }
343
346
 
344
347
        ret = tdb_fetch(pdb->tdb, print_key(jobid));
345
348
        release_print_db(pdb);
346
349
 
347
 
        if (!ret.dptr)
 
350
        if (!ret.dptr) {
 
351
                DEBUG(10,("print_job_find: failed to find jobid %u.\n", (unsigned int)jobid ));
348
352
                return NULL;
 
353
        }
349
354
        
350
 
        if ( pjob.nt_devmode )
 
355
        if ( pjob.nt_devmode ) {
351
356
                free_nt_devicemode( &pjob.nt_devmode );
 
357
        }
352
358
                
353
359
        ZERO_STRUCT( pjob );
354
360
        
355
361
        if ( unpack_pjob( ret.dptr, ret.dsize, &pjob ) == -1 ) {
 
362
                DEBUG(10,("print_job_find: failed to unpack jobid %u.\n", (unsigned int)jobid ));
356
363
                SAFE_FREE(ret.dptr);
357
364
                return NULL;
358
365
        }
359
366
        
360
 
        SAFE_FREE(ret.dptr);    
 
367
        SAFE_FREE(ret.dptr);
 
368
 
 
369
        DEBUG(10,("print_job_find: returning system job %d for jobid %u.\n",
 
370
                        (int)pjob.sysjob, (unsigned int)jobid ));
 
371
 
361
372
        return &pjob;
362
373
}
363
374
 
541
552
                len += pack_devicemode(pjob->nt_devmode, buf+len, buflen-len);
542
553
        
543
554
                if (buflen != len) {
544
 
                        char *tb;
545
 
 
546
 
                        tb = (char *)SMB_REALLOC(buf, len);
547
 
                        if (!tb) {
 
555
                        buf = (char *)SMB_REALLOC(buf, len);
 
556
                        if (!buf) {
548
557
                                DEBUG(0,("pjob_store: failed to enlarge buffer!\n"));
549
558
                                goto done;
550
559
                        }
551
 
                        else 
552
 
                                buf = tb;
553
560
                        newlen = len;
554
561
                }
555
562
        } while ( buflen != len );
1295
1302
 
1296
1303
        slprintf(keystr, sizeof(keystr) - 1, "LOCK/%s", sharename);
1297
1304
        /* Only wait 10 seconds for this. */
1298
 
        if (tdb_lock_bystring(pdb->tdb, keystr, 10) == -1) {
 
1305
        if (tdb_lock_bystring_with_timeout(pdb->tdb, keystr, 10) == -1) {
1299
1306
                DEBUG(0,("print_queue_update_with_lock: Failed to lock printer %s database\n", sharename));
1300
1307
                release_print_db(pdb);
1301
1308
                return;
1363
1370
        }
1364
1371
 
1365
1372
        print_queue_update_with_lock(sharename, 
1366
 
                get_printer_fns_from_type(printing_type),
 
1373
                get_printer_fns_from_type((enum printing_types)printing_type),
1367
1374
                lpqcommand, lprmcommand );
1368
1375
 
1369
1376
        return;
1404
1411
                        /* check for some essential signals first */
1405
1412
                        
1406
1413
                        if (got_sig_term) {
1407
 
                                exit_server("Caught TERM signal");
 
1414
                                exit_server_cleanly(NULL);
1408
1415
                        }
1409
1416
 
1410
1417
                        if (reload_after_sighup) {
1447
1454
        /* don't strip out characters like '$' from the printername */
1448
1455
        
1449
1456
        pstrcpy( lpqcommand, lp_lpqcommand(snum));
1450
 
        string_sub2( lpqcommand, "%p", PRINTERNAME(snum), sizeof(lpqcommand), False, False );
 
1457
        string_sub2( lpqcommand, "%p", PRINTERNAME(snum), sizeof(lpqcommand), 
 
1458
                     False, False, False );
1451
1459
        standard_sub_snum( snum, lpqcommand, sizeof(lpqcommand) );
1452
1460
        
1453
1461
        pstrcpy( lprmcommand, lp_lprmcommand(snum));
1454
 
        string_sub2( lprmcommand, "%p", PRINTERNAME(snum), sizeof(lprmcommand), False, False );
 
1462
        string_sub2( lprmcommand, "%p", PRINTERNAME(snum), sizeof(lprmcommand), 
 
1463
                     False, False, False );
1455
1464
        standard_sub_snum( snum, lprmcommand, sizeof(lprmcommand) );
1456
1465
        
1457
1466
        /* 
1471
1480
        
1472
1481
        /* get the length */
1473
1482
 
1474
 
        len = tdb_pack( buffer, len, "fdPP",
 
1483
        len = tdb_pack( NULL, 0, "fdPP",
1475
1484
                sharename,
1476
1485
                type,
1477
1486
                lpqcommand, 
1565
1574
                tdb = pdb->tdb;
1566
1575
        }
1567
1576
 
1568
 
        if (tdb_lock_bystring(tdb, NOTIFY_PID_LIST_KEY, 10) == -1) {
 
1577
        if (tdb_lock_bystring_with_timeout(tdb, NOTIFY_PID_LIST_KEY, 10) == -1) {
1569
1578
                DEBUG(0,("print_notify_register_pid: Failed to lock printer %s\n",
1570
1579
                                        printername));
1571
1580
                if (pdb)
1655
1664
                tdb = pdb->tdb;
1656
1665
        }
1657
1666
 
1658
 
        if (tdb_lock_bystring(tdb, NOTIFY_PID_LIST_KEY, 10) == -1) {
 
1667
        if (tdb_lock_bystring_with_timeout(tdb, NOTIFY_PID_LIST_KEY, 10) == -1) {
1659
1668
                DEBUG(0,("print_notify_register_pid: Failed to lock \
1660
1669
printer %s database\n", printername));
1661
1670
                if (pdb)
1932
1941
        if ((vuser = get_valid_user_struct(user->vuid)) != NULL) {
1933
1942
                return strequal(pjob->user, vuser->user.smb_name);
1934
1943
        } else {
1935
 
                return strequal(pjob->user, uidtoname(user->uid));
 
1944
                return strequal(pjob->user, uidtoname(user->ut.uid));
1936
1945
        }
1937
1946
}
1938
1947
 
1963
1972
                sys_adminlog( LOG_ERR, 
1964
1973
                              "Permission denied-- user not allowed to delete, \
1965
1974
pause, or resume print job. User name: %s. Printer name: %s.",
1966
 
                              uidtoname(user->uid), PRINTERNAME(snum) );
 
1975
                              uidtoname(user->ut.uid), PRINTERNAME(snum) );
1967
1976
                /* END_ADMIN_LOG */
1968
1977
 
1969
1978
                return False;
2016
2025
 
2017
2026
        pjob = print_job_find(sharename, jobid);
2018
2027
        
2019
 
        if (!pjob || !user) 
 
2028
        if (!pjob || !user) {
 
2029
                DEBUG(10, ("print_job_pause: no pjob or user for jobid %u\n",
 
2030
                        (unsigned int)jobid ));
2020
2031
                return False;
 
2032
        }
2021
2033
 
2022
 
        if (!pjob->spooled || pjob->sysjob == -1) 
 
2034
        if (!pjob->spooled || pjob->sysjob == -1) {
 
2035
                DEBUG(10, ("print_job_pause: not spooled or bad sysjob = %d for jobid %u\n",
 
2036
                        (int)pjob->sysjob, (unsigned int)jobid ));
2023
2037
                return False;
 
2038
        }
2024
2039
 
2025
2040
        if (!is_owner(user, snum, jobid) &&
2026
2041
            !print_access_check(user, snum, JOB_ACCESS_ADMINISTER)) {
2030
2045
                sys_adminlog( LOG_ERR, 
2031
2046
                        "Permission denied-- user not allowed to delete, \
2032
2047
pause, or resume print job. User name: %s. Printer name: %s.",
2033
 
                                uidtoname(user->uid), PRINTERNAME(snum) );
 
2048
                                uidtoname(user->ut.uid), PRINTERNAME(snum) );
2034
2049
                /* END_ADMIN_LOG */
2035
2050
 
2036
2051
                *errcode = WERR_ACCESS_DENIED;
2070
2085
 
2071
2086
        pjob = print_job_find(sharename, jobid);
2072
2087
        
2073
 
        if (!pjob || !user)
 
2088
        if (!pjob || !user) {
 
2089
                DEBUG(10, ("print_job_resume: no pjob or user for jobid %u\n",
 
2090
                        (unsigned int)jobid ));
2074
2091
                return False;
 
2092
        }
2075
2093
 
2076
 
        if (!pjob->spooled || pjob->sysjob == -1)
 
2094
        if (!pjob->spooled || pjob->sysjob == -1) {
 
2095
                DEBUG(10, ("print_job_resume: not spooled or bad sysjob = %d for jobid %u\n",
 
2096
                        (int)pjob->sysjob, (unsigned int)jobid ));
2077
2097
                return False;
 
2098
        }
2078
2099
 
2079
2100
        if (!is_owner(user, snum, jobid) &&
2080
2101
            !print_access_check(user, snum, JOB_ACCESS_ADMINISTER)) {
2085
2106
                sys_adminlog( LOG_ERR, 
2086
2107
                         "Permission denied-- user not allowed to delete, \
2087
2108
pause, or resume print job. User name: %s. Printer name: %s.",
2088
 
                        uidtoname(user->uid), PRINTERNAME(snum) );
 
2109
                        uidtoname(user->ut.uid), PRINTERNAME(snum) );
2089
2110
                /* END_ADMIN_LOG */
2090
2111
                return False;
2091
2112
        }
2207
2228
 
2208
2229
        for (i = 0; i < 3; i++) {
2209
2230
                /* Lock the database - only wait 20 seconds. */
2210
 
                if (tdb_lock_bystring(pdb->tdb, "INFO/nextjob", 20) == -1) {
 
2231
                if (tdb_lock_bystring_with_timeout(pdb->tdb, "INFO/nextjob", 20) == -1) {
2211
2232
                        DEBUG(0,("allocate_print_jobid: failed to lock printing database %s\n", sharename));
2212
2233
                        return False;
2213
2234
                }
2366
2387
        if ((vuser = get_valid_user_struct(user->vuid)) != NULL) {
2367
2388
                fstrcpy(pjob.user, vuser->user.smb_name);
2368
2389
        } else {
2369
 
                fstrcpy(pjob.user, uidtoname(user->uid));
 
2390
                fstrcpy(pjob.user, uidtoname(user->ut.uid));
2370
2391
        }
2371
2392
 
2372
2393
        fstrcpy(pjob.queuename, lp_const_servicename(snum));
2437
2458
 error.
2438
2459
****************************************************************************/
2439
2460
 
2440
 
BOOL print_job_end(int snum, uint32 jobid, BOOL normal_close)
 
2461
BOOL print_job_end(int snum, uint32 jobid, enum file_close_type close_type)
2441
2462
{
2442
2463
        const char* sharename = lp_const_servicename(snum);
2443
2464
        struct printjob *pjob;
2453
2474
        if (pjob->spooled || pjob->pid != sys_getpid())
2454
2475
                return False;
2455
2476
 
2456
 
        if (normal_close && (sys_fstat(pjob->fd, &sbuf) == 0)) {
 
2477
        if ((close_type == NORMAL_CLOSE || close_type == SHUTDOWN_CLOSE) &&
 
2478
                                (sys_fstat(pjob->fd, &sbuf) == 0)) {
2457
2479
                pjob->size = sbuf.st_size;
2458
2480
                close(pjob->fd);
2459
2481
                pjob->fd = -1;