~ubuntu-branches/debian/sid/ntfs-3g/sid

« back to all changes in this revision

Viewing changes to src/secaudit.c

  • Committer: Package Import Robot
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2014-10-05 09:34:12 UTC
  • mfrom: (1.2.6)
  • Revision ID: package-import@ubuntu.com-20141005093412-4ohtygxt9pm9v5u9
Tags: 1:2014.2.15AR.2-1
* New upstream release.
* Remove 0001-type-inconsistencies.patch and 0002-exit-values.patch , this
  release contains those.
* Update Standards-Version to 3.9.6 .

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 *               Display and audit security attributes in an NTFS volume
3
3
 *
4
 
 * Copyright (c) 2007-2013 Jean-Pierre Andre
 
4
 * Copyright (c) 2007-2014 Jean-Pierre Andre
5
5
 * 
6
6
 *      Options :
7
7
 *              -a auditing security data
206
206
 *
207
207
 *  Sep 2013, version 1.4.1
208
208
 *     - silenced an aliasing warning by gcc >= 4.8
 
209
 *
 
210
 *  May 2014, version 1.4.2
 
211
 *     - decoded GENERIC_ALL permissions
 
212
 *     - decoded more "well-known" and generic SIDs
 
213
 *     - showed Windows ownership in verbose situations
 
214
 *     - fixed apparent const violations
209
215
 */
210
216
 
211
217
/*
229
235
 *              General parameters which may have to be adapted to needs
230
236
 */
231
237
 
232
 
#define AUDT_VERSION "1.4.1"
 
238
#define AUDT_VERSION "1.4.2"
233
239
 
234
240
#define GET_FILE_SECURITY "ntfs_get_file_security"
235
241
#define SET_FILE_SECURITY "ntfs_set_file_security"
422
428
#endif /* USESTUBS | defined(STSC) */
423
429
#endif /* WIN32 */
424
430
 
 
431
#define ACCOUNTSIZE 256  /* maximum size of an account name */
 
432
 
425
433
/*
426
434
 *              Prototypes for local functions
427
435
 */
452
460
void showsid(const char*, int, const char*, int);
453
461
void showusid(const char*, int);
454
462
void showgsid(const char*, int);
 
463
void showownership(const char*);
455
464
void showheader(const char*, int);
456
465
void showace(const char*, int, int, int);
457
466
void showacl(const char*, int, int, int);
1447
1456
                                break;
1448
1457
                        case 5 :
1449
1458
                                switch (first) {
 
1459
                                case 1 :
 
1460
                                        known = TRUE;
 
1461
                                        printf("%*cDialup SID\n",-level,marker);
 
1462
                                        break;
 
1463
                                case 2 :
 
1464
                                        known = TRUE;
 
1465
                                        printf("%*cNetwork SID\n",-level,marker);
 
1466
                                        break;
 
1467
                                case 3 :
 
1468
                                        known = TRUE;
 
1469
                                        printf("%*cBatch SID\n",-level,marker);
 
1470
                                        break;
 
1471
                                case 4 :
 
1472
                                        known = TRUE;
 
1473
                                        printf("%*cInteractive SID\n",-level,marker);
 
1474
                                        break;
 
1475
                                case 6 :
 
1476
                                        known = TRUE;
 
1477
                                        printf("%*cService SID\n",-level,marker);
 
1478
                                        break;
1450
1479
                                case 7 :
1451
1480
                                        known = TRUE;
1452
1481
                                        printf("%*cAnonymous logon SID\n",-level,marker);
1501
1530
                        case 5 :
1502
1531
                                if (first == 21) {
1503
1532
                                        known = TRUE;
1504
 
                                        switch (last)
1505
 
                                                {
 
1533
                                        switch (last) {
 
1534
                                                case 500 :
 
1535
                                                        printf("%*cSystem admin SID\n",-level,marker);
 
1536
                                                        break;
 
1537
                                                case 501 :
 
1538
                                                        printf("%*cGuest SID\n",-level,marker);
 
1539
                                                        break;
1506
1540
                                                case 512 :
1507
1541
                                                        printf("%*cLocal admins SID\n",-level,marker);
1508
1542
                                                        break;
1566
1600
        showsid(attr,off,"G:",level+4);
1567
1601
}
1568
1602
 
 
1603
void showownership(const char *attr)
 
1604
{
 
1605
#ifdef WIN32
 
1606
        char account[ACCOUNTSIZE];
 
1607
        BIGSID sidcopy;
 
1608
        SID_NAME_USE use;
 
1609
        unsigned long accountsz;
 
1610
        unsigned long domainsz;
 
1611
#endif
 
1612
        enum { SHOWOWN, SHOWGRP, SHOWINT } shown;
 
1613
        const char *sid;
 
1614
        const char *prefix;
 
1615
        u64 auth;
 
1616
        int cnt;
 
1617
        int off;
 
1618
        int i;
 
1619
 
 
1620
        for (shown=SHOWOWN; shown<=SHOWINT; shown++) {
 
1621
                switch (shown) {
 
1622
                case SHOWOWN :
 
1623
                        off = get4l(attr,4);
 
1624
                        sid = &attr[off];
 
1625
                        prefix = "Windows owner";
 
1626
                        break;
 
1627
                case SHOWGRP :
 
1628
                        off = get4l(attr,8);
 
1629
                        sid = &attr[off];
 
1630
                        prefix = "Windows group";
 
1631
                        break;
 
1632
#if OWNERFROMACL
 
1633
                case SHOWINT :
 
1634
                        off = get4l(attr,4);
 
1635
                        prefix = "Interpreted owner";
 
1636
                        sid = (const char*)ntfs_acl_owner((const char*)attr);
 
1637
                        if (ntfs_same_sid((const SID*)sid,
 
1638
                                                (const SID*)&attr[off]))
 
1639
                                sid = (const char*)NULL;
 
1640
                        break;
 
1641
#endif
 
1642
                default :
 
1643
                        sid = (const char*)NULL;
 
1644
                        prefix = (const char*)NULL;
 
1645
                        break;
 
1646
                }
 
1647
                if (sid) {
 
1648
                        cnt = sid[1] & 255;
 
1649
                        auth = get6h(sid,2);
 
1650
                        if (opt_b)
 
1651
                                printf("# %s S-%d-",prefix,sid[0] & 255);
 
1652
                        else
 
1653
                                printf("%s S-%d-",prefix,sid[0] & 255);
 
1654
                        printf("%llu",auth);
 
1655
                        for (i=0; i<cnt; i++)
 
1656
                                printf("-%lu",get4l(sid,8+4*i));
 
1657
#ifdef WIN32
 
1658
                        memcpy(sidcopy,sid,ntfs_sid_size((const SID*)sid));
 
1659
                        accountsz = ACCOUNTSIZE;
 
1660
                        domainsz = ACCOUNTSIZE;
 
1661
                        if (LookupAccountSidA((const char*)NULL, sidcopy,
 
1662
                                        account, &accountsz,
 
1663
                                        (char*)NULL, &domainsz, &use))
 
1664
                                printf(" (%s)", account);
 
1665
#endif
 
1666
                        printf("\n");
 
1667
                }
 
1668
        }
 
1669
}
 
1670
 
1569
1671
void showheader(const char *attr, int level)
1570
1672
{
1571
1673
        int flags;
2297
2399
#ifdef WIN32
2298
2400
/* TODO : check whether the device can store acls */
2299
2401
                strcpy(mapfile,"x:\\" MAPDIR "\\" MAPFILE);
2300
 
                if (((le16*)usermap_path)[1] == ':')
 
2402
                if (((const le16*)usermap_path)[1] == ':')
2301
2403
                        mapfile[0] = usermap_path[0];
2302
2404
                else {
2303
2405
                        GetModuleFileName(NULL, currpath, 261);
2520
2622
                        showgsid(attr,4);
2521
2623
                        showdacl(attr,isdir,4);
2522
2624
                        showsacl(attr,isdir,4);
 
2625
                        showownership(attr);
2523
2626
                        mode = linux_permissions(attr,isdir);
2524
2627
                        printf("Interpreted Unix mode 0%03o\n",mode);
2525
2628
#if POSIXACLS
2644
2747
                                }
2645
2748
                        }
2646
2749
                }
 
2750
                /* const missing from stupid prototype */
2647
2751
                bad = !SetFileSecurityW((LPCWSTR)fullname,
2648
 
                        selection, (char*)curattr);
 
2752
                        selection, (PSECURITY_DESCRIPTOR)(LONG_PTR)curattr);
2649
2753
                if (bad)
2650
2754
                        switch (GetLastError()) {
2651
2755
                        case 1307 :
2654
2758
                                printname(stdout,fullname);
2655
2759
                                printf(", retrying with no owner or SACL setting\n");
2656
2760
                                warnings++;
 
2761
                                /* const missing from stupid prototype */
2657
2762
                                bad = !SetFileSecurityW((LPCWSTR)fullname,
2658
2763
                                        selection & ~OWNER_SECURITY_INFORMATION
2659
 
                                        & ~SACL_SECURITY_INFORMATION, (char*)curattr);
 
2764
                                        & ~SACL_SECURITY_INFORMATION,
 
2765
                                        (PSECURITY_DESCRIPTOR)
 
2766
                                                        (LONG_PTR)curattr);
2660
2767
                                break;
2661
2768
                        default :
2662
2769
                                break;
2770
2877
                                showdacl(attr,isdir,4);
2771
2878
                                showsacl(attr,isdir,4);
2772
2879
                                mode = linux_permissions(attr,isdir);
 
2880
                                showownership(attr);
2773
2881
                                printf("Interpreted Unix mode 0%03o\n",mode);
2774
2882
                        }
2775
2883
                        pos = 0;
4942
5050
                                uid = linux_owner(attr);
4943
5051
                                gid = linux_group(attr);
4944
5052
                                if (opt_b) {
 
5053
                                        showownership(attr);
4945
5054
                                        printf("# Interpreted Unix owner %d, group %d, mode 0%03o\n",
4946
5055
                                                (int)uid,(int)gid,mode);
4947
5056
                                } else {
 
5057
                                        showownership(attr);
4948
5058
                                        printf("Interpreted Unix owner %d, group %d, mode 0%03o\n",
4949
5059
                                                (int)uid,(int)gid,mode);
4950
5060
                                }
5288
5398
                                uid = linux_owner(attr);
5289
5399
                                gid = linux_group(attr);
5290
5400
                                if (opt_b) {
 
5401
                                        showownership(attr);
5291
5402
                                        printf("# Interpreted Unix owner %d, group %d, mode 0%03o\n",
5292
5403
                                                (int)uid,(int)gid,mode);
5293
5404
                                } else {
 
5405
                                        showownership(attr);
5294
5406
                                        printf("Interpreted Unix owner %d, group %d, mode 0%03o\n",
5295
5407
                                                (int)uid,(int)gid,mode);
5296
5408
                                }
5498
5610
                                        showdacl(attr,isdir,level);
5499
5611
                                        showsacl(attr,isdir,level);
5500
5612
                                }
 
5613
                                showownership(attr);
5501
5614
                                if (mapped) {
5502
5615
                                        uid = linux_owner(attr);
5503
5616
                                        gid = linux_group(attr);
6164
6277
                                                showgsid(&attr[20],0);
6165
6278
                                                showdacl(&attr[20],isdir,0);
6166
6279
                                                showsacl(&attr[20],isdir,0);
 
6280
                                                showownership(&attr[20]);
6167
6281
                                                mode = linux_permissions(
6168
6282
                                                    &attr[20],isdir);
6169
6283
                                                printf("Interpreted Unix mode 0%03o\n",mode);