Fix a boatload of warnings in the examples.
[rusty/samba.git] / examples / libsmbclient / testacl2.c
1 #include <stdlib.h>
2 #include <string.h>
3 #include <errno.h>
4 #include <popt.h>
5 #include "libsmbclient.h"
6 #include "get_auth_data_fn.h"
7
8 enum acl_mode
9 {
10     SMB_ACL_GET,
11     SMB_ACL_SET,
12     SMB_ACL_DELETE,
13     SMB_ACL_MODIFY,
14     SMB_ACL_ADD,
15     SMB_ACL_CHOWN,
16     SMB_ACL_CHGRP
17 };
18
19
20 int main(int argc, const char *argv[])
21 {
22     int flags;
23     int debug = 0;
24     static char *the_acl = NULL;
25     int ret;
26     const char *debugstr;
27     char value[1024];
28
29     if (smbc_init(get_auth_data_fn, debug) != 0)
30     {
31         printf("Could not initialize smbc_ library\n");
32         return 1;
33     }
34
35     SMBCCTX *context = smbc_set_context(NULL);
36     smbc_setOptionFullTimeNames(context, 1);
37     
38     the_acl = strdup("system.nt_sec_desc.*");
39     ret = smbc_getxattr(argv[1], the_acl, value, sizeof(value));
40     if (ret < 0)
41     {
42         printf("Could not get attributes for [%s] %d: %s\n",
43                argv[1], errno, strerror(errno));
44         return 1;
45     }
46     
47     printf("Attributes for [%s] are:\n%s\n", argv[1], value);
48
49     flags = 0;
50     debugstr = "set attributes (1st time)";
51         
52     ret = smbc_setxattr(argv[1], the_acl, value, strlen(value), flags);
53     if (ret < 0)
54     {
55         printf("Could not %s for [%s] %d: %s\n",
56                debugstr, argv[1], errno, strerror(errno));
57         return 1;
58     }
59     
60     flags = 0;
61     debugstr = "set attributes (2nd time)";
62         
63     ret = smbc_setxattr(argv[1], the_acl, value, strlen(value), flags);
64     if (ret < 0)
65     {
66         printf("Could not %s for [%s] %d: %s\n",
67                debugstr, argv[1], errno, strerror(errno));
68         return 1;
69     }
70     
71     return 0;
72 }