~zulcss/samba/server-dailies-3.4

« back to all changes in this revision

Viewing changes to examples/libsmbclient/testchmod.c

  • Committer: Chuck Short
  • Date: 2010-09-28 20:38:39 UTC
  • Revision ID: zulcss@ubuntu.com-20100928203839-pgjulytsi9ue63x1
Initial version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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"
 
7
 
 
8
 
 
9
int main(int argc, char * argv[]) 
 
10
 
11
    int             ret;
 
12
    int             debug = 0;
 
13
    int             mode = 0666;
 
14
    char            buffer[16384]; 
 
15
    char *          pSmbPath = NULL;
 
16
    struct stat     st; 
 
17
    
 
18
    if (argc == 1)
 
19
    {
 
20
        pSmbPath = "smb://RANDOM/Public/small";
 
21
    }
 
22
    else if (argc == 2)
 
23
    {
 
24
        pSmbPath = argv[1];
 
25
    }
 
26
    else if (argc == 3)
 
27
    {
 
28
        pSmbPath = argv[1];
 
29
        mode = (int) strtol(argv[2], NULL, 8);
 
30
    }
 
31
    else
 
32
    {
 
33
        printf("usage: "
 
34
               "%s [ smb://path/to/file [ octal_mode ] ]\n",
 
35
               argv[0]);
 
36
        return 1;
 
37
    }
 
38
 
 
39
    smbc_init(get_auth_data_fn, debug); 
 
40
    
 
41
    if (smbc_stat(pSmbPath, &st) < 0)
 
42
    {
 
43
        perror("smbc_stat");
 
44
        return 1;
 
45
    }
 
46
    
 
47
    printf("\nBefore chmod: mode = %04o\n", st.st_mode);
 
48
    
 
49
    if (smbc_chmod(pSmbPath, mode) < 0)
 
50
    {
 
51
        perror("smbc_chmod");
 
52
        return 1;
 
53
    }
 
54
 
 
55
    if (smbc_stat(pSmbPath, &st) < 0)
 
56
    {
 
57
        perror("smbc_stat");
 
58
        return 1;
 
59
    }
 
60
    
 
61
    printf("After chmod: mode = %04o\n", st.st_mode);
 
62
    
 
63
    return 0; 
 
64
}