2022-08-17 11:51:06 +03:00
# include <stdio.h>
2005-03-30 06:39:22 +04:00
# include <unistd.h>
2022-08-17 11:51:06 +03:00
# include <string.h>
# include <time.h>
# include <libsmbclient.h>
2023-09-14 14:45:04 +03:00
# include <stdbool.h>
2005-03-31 09:06:04 +04:00
# include "get_auth_data_fn.h"
2005-03-30 06:39:22 +04:00
2023-08-14 18:30:24 +03:00
static const char * filetypestr ( mode_t mode )
{
if ( S_ISREG ( mode ) ) {
return " regular file " ;
}
if ( S_ISDIR ( mode ) ) {
return " directory " ;
}
if ( S_ISFIFO ( mode ) ) {
return " fifo " ;
}
if ( S_ISLNK ( mode ) ) {
return " symbolic link " ;
}
if ( S_ISSOCK ( mode ) ) {
return " socket " ;
}
if ( S_ISCHR ( mode ) ) {
return " character special file " ;
}
if ( S_ISBLK ( mode ) ) {
return " block special file " ;
}
return " unknown file type " ;
}
2005-03-30 06:39:22 +04:00
2022-08-17 11:51:06 +03:00
int main ( int argc , char * argv [ ] )
{
2023-08-23 17:46:56 +03:00
SMBCCTX * ctx = NULL ;
2022-08-17 11:51:06 +03:00
int debug = 0 ;
char m_time [ 32 ] ;
char c_time [ 32 ] ;
char a_time [ 32 ] ;
const char * pSmbPath = NULL ;
const char * pLocalPath = NULL ;
struct stat st ;
2022-08-17 12:40:11 +03:00
int ret ;
2005-03-30 06:39:22 +04:00
2022-08-17 12:40:11 +03:00
if ( argc = = 1 ) {
2022-08-17 11:51:06 +03:00
pSmbPath = " smb://RANDOM/Public/small " ;
pLocalPath = " /random/home/samba/small " ;
}
2022-08-17 12:40:11 +03:00
else if ( argc = = 2 ) {
2022-08-17 11:51:06 +03:00
pSmbPath = argv [ 1 ] ;
pLocalPath = NULL ;
}
2022-08-17 12:40:11 +03:00
else if ( argc = = 3 ) {
2022-08-17 11:51:06 +03:00
pSmbPath = argv [ 1 ] ;
pLocalPath = argv [ 2 ] ;
2022-08-17 12:40:11 +03:00
} else {
printf ( " usage: %s [ smb://path/to/file "
" [ /nfs/or/local/path/to/file ] ] \n " ,
2022-08-17 11:51:06 +03:00
argv [ 0 ] ) ;
return 1 ;
}
2005-03-30 06:39:22 +04:00
2023-08-23 17:46:56 +03:00
ctx = smbc_new_context ( ) ;
if ( ctx = = NULL ) {
perror ( " smbc_new_context failed " ) ;
return 1 ;
}
smbc_setOptionDebugToStderr ( ctx , 1 ) ;
smbc_setDebug ( ctx , debug ) ;
smbc_init_context ( ctx ) ;
smbc_setFunctionAuthData ( ctx , get_auth_data_fn ) ;
2023-09-14 14:45:04 +03:00
smbc_setOptionPosixExtensions ( ctx , true ) ;
2022-08-17 11:51:06 +03:00
2023-08-23 17:46:56 +03:00
ret = smbc_getFunctionStat ( ctx ) ( ctx , pSmbPath , & st ) ;
2022-08-17 12:40:11 +03:00
if ( ret < 0 ) {
2022-08-17 11:51:06 +03:00
perror ( " smbc_stat " ) ;
return 1 ;
}
2023-08-14 18:30:24 +03:00
printf ( " \n SAMBA \n mtime:%jd/%s ctime:%jd/%s atime:%jd/%s %s \n " ,
2023-08-14 18:28:28 +03:00
( intmax_t ) st . st_mtime ,
ctime_r ( & st . st_mtime , m_time ) ,
( intmax_t ) st . st_ctime ,
ctime_r ( & st . st_ctime , c_time ) ,
( intmax_t ) st . st_atime ,
2023-08-14 18:30:24 +03:00
ctime_r ( & st . st_atime , a_time ) ,
filetypestr ( st . st_mode ) ) ;
2022-08-17 11:51:06 +03:00
2022-08-17 12:40:11 +03:00
if ( pLocalPath ! = NULL ) {
ret = stat ( pLocalPath , & st ) ;
if ( ret < 0 ) {
2022-08-17 11:51:06 +03:00
perror ( " stat " ) ;
return 1 ;
}
2023-08-14 18:30:24 +03:00
printf ( " LOCAL \n mtime:%jd/%s ctime:%jd/%s atime:%jd/%s %s \n " ,
2023-08-14 18:28:28 +03:00
( intmax_t ) st . st_mtime ,
ctime_r ( & st . st_mtime , m_time ) ,
( intmax_t ) st . st_ctime ,
ctime_r ( & st . st_ctime , c_time ) ,
( intmax_t ) st . st_atime ,
2023-08-14 18:30:24 +03:00
ctime_r ( & st . st_atime , a_time ) ,
filetypestr ( st . st_mode ) ) ;
2022-08-17 11:51:06 +03:00
}
return 0 ;
2005-03-30 06:39:22 +04:00
}