s3:idmap_ad: add support for ADS_AUTH_SASL_{STARTTLS,LDAPS}
[Samba.git] / examples / libsmbclient / teststat.c
blob079ac8974ad87e092264da559a9c781e361f3d88
1 #include <stdio.h>
2 #include <unistd.h>
3 #include <string.h>
4 #include <time.h>
5 #include <libsmbclient.h>
6 #include <stdbool.h>
7 #include "get_auth_data_fn.h"
9 static const char *filetypestr(mode_t mode)
11 if (S_ISREG(mode)) {
12 return "regular file";
14 if (S_ISDIR(mode)) {
15 return "directory";
17 if (S_ISFIFO(mode)) {
18 return "fifo";
20 if (S_ISLNK(mode)) {
21 return "symbolic link";
23 if (S_ISSOCK(mode)) {
24 return "socket";
26 if (S_ISCHR(mode)) {
27 return "character special file";
29 if (S_ISBLK(mode)) {
30 return "block special file";
32 return "unknown file type";
35 int main(int argc, char * argv[])
37 SMBCCTX *ctx = NULL;
38 int debug = 0;
39 char m_time[32];
40 char c_time[32];
41 char a_time[32];
42 const char * pSmbPath = NULL;
43 const char * pLocalPath = NULL;
44 struct stat st;
45 int ret;
47 if (argc == 1) {
48 pSmbPath = "smb://RANDOM/Public/small";
49 pLocalPath = "/random/home/samba/small";
51 else if (argc == 2) {
52 pSmbPath = argv[1];
53 pLocalPath = NULL;
55 else if (argc == 3) {
56 pSmbPath = argv[1];
57 pLocalPath = argv[2];
58 } else {
59 printf("usage: %s [ smb://path/to/file "
60 "[ /nfs/or/local/path/to/file ] ]\n",
61 argv[0]);
62 return 1;
65 ctx = smbc_new_context();
66 if (ctx == NULL) {
67 perror("smbc_new_context failed");
68 return 1;
71 smbc_setOptionDebugToStderr(ctx, 1);
72 smbc_setDebug(ctx, debug);
73 smbc_init_context(ctx);
74 smbc_setFunctionAuthData(ctx, get_auth_data_fn);
75 smbc_setOptionPosixExtensions(ctx, true);
77 ret = smbc_getFunctionStat(ctx)(ctx, pSmbPath, &st);
78 if (ret < 0) {
79 perror("smbc_stat");
80 return 1;
83 printf("\nSAMBA\n mtime:%jd/%s ctime:%jd/%s atime:%jd/%s %s\n",
84 (intmax_t)st.st_mtime,
85 ctime_r(&st.st_mtime, m_time),
86 (intmax_t)st.st_ctime,
87 ctime_r(&st.st_ctime, c_time),
88 (intmax_t)st.st_atime,
89 ctime_r(&st.st_atime, a_time),
90 filetypestr(st.st_mode));
92 if (pLocalPath != NULL) {
93 ret = stat(pLocalPath, &st);
94 if (ret < 0) {
95 perror("stat");
96 return 1;
99 printf("LOCAL\n mtime:%jd/%s ctime:%jd/%s atime:%jd/%s %s\n",
100 (intmax_t)st.st_mtime,
101 ctime_r(&st.st_mtime, m_time),
102 (intmax_t)st.st_ctime,
103 ctime_r(&st.st_ctime, c_time),
104 (intmax_t)st.st_atime,
105 ctime_r(&st.st_atime, a_time),
106 filetypestr(st.st_mode));
109 return 0;