46eeb13985a7b0d58103957fe6b922f6531a6b95
[tprouty/samba.git] / examples / libsmbclient / teststat.c
1 #include <stdio.h> 
2 #include <unistd.h>
3 #include <string.h> 
4 #include <time.h> 
5 #include <libsmbclient.h> 
6
7 static void
8 get_auth_data_fn(const char * pServer,
9                  const char * pShare,
10                  char * pWorkgroup,
11                  int maxLenWorkgroup,
12                  char * pUsername,
13                  int maxLenUsername,
14                  char * pPassword,
15                  int maxLenPassword)
16     
17 {
18     char temp[128];
19     
20     printf("Entered get_auth_data_fn\n");
21
22     fprintf(stdout, "Need password for //%s/%s\n", pServer, pShare);
23     
24     fprintf(stdout, "Username: [%s] ", pUsername);
25     fgets(temp, sizeof(temp), stdin);
26     
27     if (temp[strlen(temp) - 1] == '\n') /* A new line? */
28     {
29         temp[strlen(temp) - 1] = '\0';
30     }
31     
32     if (temp[0] != '\0')
33     {
34         strncpy(pUsername, temp, maxLenUsername - 1);
35     }
36     
37     strcpy(temp, getpass("Password: "));
38     
39     if (temp[strlen(temp) - 1] == '\n') /* A new line? */
40     {
41         temp[strlen(temp) - 1] = '\0';
42     }
43     
44     if (temp[0] != '\0')
45     {
46         strncpy(pPassword, temp, maxLenPassword - 1);
47     }
48
49     fprintf(stdout, "Workgroup: ");
50     fgets(temp, sizeof(temp), stdin);
51     
52     if (temp[strlen(temp) - 1] == '\n') /* A new line? */
53     {
54         temp[strlen(temp) - 1] = '\0';
55     }
56     
57     if (temp[0] != '\0')
58     {
59         strncpy(pWorkgroup, temp, maxLenWorkgroup - 1);
60     }
61
62     putchar('\n');
63 }
64
65
66
67 int main(int argc, char * argv[]) 
68
69     char            buffer[16384]; 
70     char *          pSmbPath = NULL;
71     char *          pLocalPath = NULL;
72     struct stat     st; 
73     
74     if (argc == 1)
75     {
76         pSmbPath = "smb://RANDOM/Public/small";
77         pLocalPath = "/random/home/samba/small";
78     }
79     else if (argc == 2)
80     {
81         pSmbPath = argv[1];
82         pLocalPath = NULL;
83     }
84     else if (argc == 3)
85     {
86         pSmbPath = argv[1];
87         pLocalPath = argv[2];
88     }
89     else
90     {
91         printf("usage: "
92                "%s [ smb://path/to/file [ /nfs/or/local/path/to/file ] ]\n",
93                argv[0]);
94         return 1;
95     }
96
97     smbc_init(get_auth_data_fn, 0); 
98     
99     int ret = smbc_stat(pSmbPath, &st); 
100     
101     printf("SAMBA\nret=%d,\n mtime:%lu/%s ctime:%lu/%s atime:%lu/%s\n", ret, 
102            st.st_mtime, ctime(&st.st_mtime),
103            st.st_ctime, ctime(&st.st_ctime),
104            st.st_atime, ctime(&st.st_atime)); 
105     
106     if (pLocalPath != NULL)
107     {
108         ret = stat(pLocalPath, &st); 
109         
110         printf("LOCAL\nret=%d,\n mtime:%lu/%s ctime:%lu/%s atime:%lu/%s\n", ret, 
111                st.st_mtime, ctime(&st.st_mtime),
112                st.st_ctime, ctime(&st.st_ctime),
113                st.st_atime, ctime(&st.st_atime));
114     }
115
116     return 0; 
117 }