summaryrefslogtreecommitdiffstats
path: root/examples/libsmbclient/testacl2.c
blob: d2a97cf2d21acf6be89a5e7b3b8e43374b489518 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <popt.h>
#include "libsmbclient.h"
#include "get_auth_data_fn.h"

enum acl_mode
{
    SMB_ACL_GET,
    SMB_ACL_SET,
    SMB_ACL_DELETE,
    SMB_ACL_MODIFY,
    SMB_ACL_ADD,
    SMB_ACL_CHOWN,
    SMB_ACL_CHGRP
};


int main(int argc, const char *argv[])
{
    int i;
    int opt;
    int flags;
    int debug = 0;
    int numeric = 0;
    int full_time_names = 0;
    enum acl_mode mode = SMB_ACL_GET;
    static char *the_acl = NULL;
    int ret;
    char *p;
    char *debugstr;
    char value[1024];

    if (smbc_init(get_auth_data_fn, debug) != 0)
    {
        printf("Could not initialize smbc_ library\n");
        return 1;
    }

    SMBCCTX *context = smbc_set_context(NULL);
    smbc_setOptionFullTimeNames(context, 1);
    
    the_acl = strdup("system.nt_sec_desc.*");
    ret = smbc_getxattr(argv[1], the_acl, value, sizeof(value));
    if (ret < 0)
    {
        printf("Could not get attributes for [%s] %d: %s\n",
               argv[1], errno, strerror(errno));
        return 1;
    }
    
    printf("Attributes for [%s] are:\n%s\n", argv[1], value);

    flags = 0;
    debugstr = "set attributes (1st time)";
        
    ret = smbc_setxattr(argv[1], the_acl, value, strlen(value), flags);
    if (ret < 0)
    {
        printf("Could not %s for [%s] %d: %s\n",
               debugstr, argv[1], errno, strerror(errno));
        return 1;
    }
    
    flags = 0;
    debugstr = "set attributes (2nd time)";
        
    ret = smbc_setxattr(argv[1], the_acl, value, strlen(value), flags);
    if (ret < 0)
    {
        printf("Could not %s for [%s] %d: %s\n",
               debugstr, argv[1], errno, strerror(errno));
        return 1;
    }
    
    return 0;
}