Main Page | Modules | Class List | Directories | File List | Class Members | File Members | Related Pages

testchmod.c

Go to the documentation of this file.
00001 #include <stdio.h> 
00002 #include <unistd.h>
00003 #include <string.h> 
00004 #include <time.h> 
00005 #include <libsmbclient.h> 
00006 #include "get_auth_data_fn.h"
00007 
00008 
00009 int main(int argc, char * argv[]) 
00010 { 
00011     int             ret;
00012     int             debug = 0;
00013     int             mode = 0666;
00014     char            buffer[16384]; 
00015     char *          pSmbPath = NULL;
00016     struct stat     st; 
00017     
00018     if (argc == 1)
00019     {
00020         pSmbPath = "smb://RANDOM/Public/small";
00021     }
00022     else if (argc == 2)
00023     {
00024         pSmbPath = argv[1];
00025     }
00026     else if (argc == 3)
00027     {
00028         pSmbPath = argv[1];
00029         mode = (int) strtol(argv[2], NULL, 8);
00030     }
00031     else
00032     {
00033         printf("usage: "
00034                "%s [ smb://path/to/file [ octal_mode ] ]\n",
00035                argv[0]);
00036         return 1;
00037     }
00038 
00039     smbc_init(get_auth_data_fn, debug); 
00040     
00041     if (smbc_stat(pSmbPath, &st) < 0)
00042     {
00043         perror("smbc_stat");
00044         return 1;
00045     }
00046     
00047     printf("\nBefore chmod: mode = %04o\n", st.st_mode);
00048     
00049     if (smbc_chmod(pSmbPath, mode) < 0)
00050     {
00051         perror("smbc_chmod");
00052         return 1;
00053     }
00054 
00055     if (smbc_stat(pSmbPath, &st) < 0)
00056     {
00057         perror("smbc_stat");
00058         return 1;
00059     }
00060     
00061     printf("After chmod: mode = %04o\n", st.st_mode);
00062     
00063     return 0; 
00064 }

© sourcejam.com 2005-2008