This is an example of a application level directory list using the ConnectSMB Libraries
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <wchar.h>
#include <unistd.h>
#include <ofc/config.h>
#include <ofc/fstype.h>
#include "smbinit.h"
static wchar_t *MakeFilename(const wchar_t *device, const wchar_t *name)
{
size_t namelen;
wchar_t *filename;
namelen = (wcslen(device) + 1 + wcslen(name) + 1);
filename = malloc(namelen * sizeof(wchar_t));
swprintf(filename, namelen, L"%ls:%ls", device, name);
return (filename);
}
static char *Attr2Str[17] =
{
"RO",
"HID",
"SYS",
"",
"DIR",
"ARV",
"",
"NRM",
"TMP",
"SPR",
"",
"CMP",
"OFF",
"",
"ENC",
""
"VIRT",
};
{
printf("File: %ls\n", find_data->cFileName);
printf("Alternate Name: %.14ls\n", find_data->cAlternateFileName);
printf("Attributes: 0x%08x\n", find_data->dwFileAttributes);
mask = 0x0001;
str[0] = '\0';
p = str;
for (i = 0; i < 16; i++, mask <<= 1)
{
if (find_data->dwFileAttributes & mask)
{
if (first)
else
{
strcpy(p, ", ");
p += 2;
}
strcpy(p, Attr2Str[i]);
p += strlen(Attr2Str[i]);
}
}
*p = '\0';
printf(" %s\n", str);
&fat_date, &fat_time);
&month, &day, &year, &hour, &min, &sec);
printf("Create Time: %02d/%02d/%04d %02d:%02d:%02d GMT\n",
month, day, year, hour, min, sec);
&fat_date, &fat_time);
&month, &day, &year, &hour, &min, &sec);
printf("Last Access Time: %02d/%02d/%04d %02d:%02d:%02d GMT\n",
month, day, year, hour, min, sec);
&fat_date, &fat_time);
&month, &day, &year, &hour, &min, &sec);
printf("Last Write Time: %02d/%02d/%04d %02d:%02d:%02d GMT\n",
month, day, year, hour, min, sec);
printf("File Size High: 0x%08x, Low: 0x%08x\n",
find_data->nFileSizeHigh, find_data->nFileSizeLow);
printf("\n");
}
wchar_t *CreateMap(const wchar_t *dirname)
{
char *uuid;
size_t len;
wchar_t *device;
len = strlen(uuid) + 1;
device = malloc(len * sizeof(wchar_t));
mbstowcs(device, uuid, len);
{
free(device);
device = NULL;
}
return (device);
}
static void DeleteMap(wchar_t *device)
{
free(device);
}
{
wchar_t *device;
wchar_t *filename;
{
}
else
{
device = CreateMap(dirname);
if (device == NULL)
{
}
else
{
count = 0;
filename = MakeFilename(device, L"*");
{
}
free(filename);
DeleteMap(device);
}
{
if (wcscmp(find_data.cFileName, L".") != 0 &&
wcscmp(find_data.cFileName, L"..") != 0)
{
count++;
OfcFSPrintFindData(&find_data);
}
{
&find_data,
&more);
{
if (wcscmp(find_data.cFileName, L".") != 0 &&
wcscmp(find_data.cFileName, L"..") != 0)
{
count++;
OfcFSPrintFindData(&find_data);
}
}
else
{
}
}
}
}
printf("Total Number of Files in Directory %d\n", count);
return (last_error);
}
int main (int argc, char **argp)
{
size_t len;
mbstate_t ps;
const char *cursor;
smbcp_init();
if (argc < 2)
{
printf ("Usage: smbls <dir>\n");
domain =
TSTR(
"FILE%3A/var/tmp/kerberos/ccache");
uncInput =
TSTR(
"15.6.28.121/snf/folder");
rem = 0;
&rem,
username,
password,
domain,
uncInput);
rem = len + 1;
orig_filename = malloc(rem *
sizeof(
OFC_TCHAR));
filename = orig_filename;
&rem,
username,
password,
domain,
uncInput);
printf("File is %ls\n", orig_filename);
free(orig_filename);
exit (1);
}
memset(&ps, 0, sizeof(ps));
len = strlen(argp[1]) + 1;
wfilename = malloc(sizeof(wchar_t) * len);
cursor = argp[1];
mbsrtowcs(wfilename, &cursor, len, &ps);
printf("Listing %s\n: ", argp[1]);
fflush(stdout);
ret = ls(wfilename);
free(wfilename);
int status;
{
printf("[ok]\n");
status = 0;
}
else
{
printf("[failed]\n");
status = 1;
}
printf("Deactivating Stack\n");
smbcp_deactivate();
exit(status);
}
@ OFC_ERROR_SUCCESS
Definition: file.h:1508
@ OFC_ERROR_NO_MORE_FILES
Definition: file.h:1521
OFC_CORE_LIB OFC_VOID OfcFileThreadDeinit(OFC_VOID)
#define OfcDismount
Definition: file.h:2635
#define OfcFindNextFile
Definition: file.h:2628
OFC_CORE_LIB const OFC_CHAR * ofc_get_error_string(OFC_DWORD dwerr)
#define OfcGetVolumeInformation
Definition: file.h:2634
OFC_CORE_LIB OFC_DWORD OfcGetLastError(OFC_VOID)
#define OFC_WIN32_FIND_DATA
Definition: file.h:2639
#define OfcFindFirstFile
Definition: file.h:2627
OFC_CORE_LIB OFC_BOOL OfcFindClose(OFC_HANDLE hFindFile)
OFC_CORE_LIB OFC_VOID OfcFileThreadInit(OFC_VOID)
OFC_DWORD_PTR OFC_HANDLE
Definition: handle.h:43
#define OFC_INVALID_HANDLE_VALUE
Definition: handle.h:52
OFC_CHAR * ofc_framework_get_uuid(OFC_VOID)
OFC_CORE_LIB OFC_VOID ofc_framework_free_uuid(OFC_LPSTR str)
OFC_CORE_LIB OFC_SIZET ofc_path_make_urlW(OFC_LPTSTR *filename, OFC_SIZET *rem, OFC_LPCTSTR username, OFC_LPCTSTR password, OFC_LPCTSTR domain, OFC_LPCTSTR server, OFC_LPCTSTR share, OFC_LPCTSTR path, OFC_LPCTSTR file)
#define ofc_path_create
Definition: path.h:800
#define ofc_path_delete_map
Definition: path.h:828
#define ofc_path_add_map
Definition: path.h:795
OFC_VOID OFC_PATH
Definition: path.h:122
OFC_CORE_LIB OFC_VOID ofc_dos_date_time_to_elements(OFC_WORD FatDate, OFC_WORD FatTime, OFC_UINT16 *month, OFC_UINT16 *day, OFC_UINT16 *year, OFC_UINT16 *hour, OFC_UINT16 *min, OFC_UINT16 *sec)
OFC_CORE_LIB OFC_BOOL ofc_file_time_to_dos_date_time(const OFC_FILETIME *lpFileTime, OFC_WORD *lpFatDate, OFC_WORD *lpFatTime)
@ OFC_FALSE
Definition: types.h:632
@ OFC_TRUE
Definition: types.h:636
void OFC_VOID
Definition: types.h:159
const OFC_TCHAR * OFC_LPCTSTR
Definition: types.h:498
OFC_UINT8 OFC_BOOL
Definition: types.h:624
OFC_TCHAR * OFC_LPTSTR
Definition: types.h:490
OFC_UINT32 OFC_DWORD
Definition: types.h:430
OFC_WCHAR OFC_TCHAR
Definition: types.h:463
OFC_UINT16 OFC_WORD
Definition: types.h:426
#define OFC_NULL
Definition: types.h:656
char OFC_CHAR
Definition: types.h:143
const OFC_WCHAR OFC_CTCHAR
Definition: types.h:467
#define TSTR(x)
Definition: types.h:534
int OFC_INT
Definition: types.h:119
long int OFC_SIZET
Definition: types.h:115
unsigned short int OFC_UINT16
Definition: types.h:183