s3: libsmbclient: Re-resolving targetcli on every read/write/lseek/ftruncate/close...
[Samba.git] / examples / libsmbclient / testchmod.c
blobb285a81a1907be60344b9e0b84c877fdb72c508b
1 #include <stdio.h>
2 #include <unistd.h>
3 #include <string.h>
4 #include <time.h>
5 #include <libsmbclient.h>
6 #include "get_auth_data_fn.h"
9 int main(int argc, char * argv[])
11 int debug = 0;
12 int mode = 0666;
13 const char * pSmbPath = NULL;
14 struct stat st;
16 if (argc == 1)
18 pSmbPath = "smb://RANDOM/Public/small";
20 else if (argc == 2)
22 pSmbPath = argv[1];
24 else if (argc == 3)
26 pSmbPath = argv[1];
27 mode = (int) strtol(argv[2], NULL, 8);
29 else
31 printf("usage: "
32 "%s [ smb://path/to/file [ octal_mode ] ]\n",
33 argv[0]);
34 return 1;
37 smbc_init(get_auth_data_fn, debug);
39 if (smbc_stat(pSmbPath, &st) < 0)
41 perror("smbc_stat");
42 return 1;
45 printf("\nBefore chmod: mode = %04o\n", (unsigned int)st.st_mode);
47 if (smbc_chmod(pSmbPath, mode) < 0)
49 perror("smbc_chmod");
50 return 1;
53 if (smbc_stat(pSmbPath, &st) < 0)
55 perror("smbc_stat");
56 return 1;
59 printf("After chmod: mode = %04o\n", (unsigned int)st.st_mode);
61 return 0;