1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-27 22:50:26 +03:00

examples: Make libsmbclient samples look a *bit* less ugly

Remove trailing whitespace, indent to tabs. Yes, this introduces long
lines, but makes review with "git show -w" trivial.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
Volker Lendecke 2022-08-17 10:51:06 +02:00 committed by Jeremy Allison
parent df4c3f0f28
commit 556e1a5ee4
19 changed files with 1900 additions and 1905 deletions

View File

@ -10,83 +10,83 @@ get_auth_data_fn(const char * pServer,
char * pPassword,
int maxLenPassword)
{
char temp[128];
char server[256] = { '\0' };
char share[256] = { '\0' };
char workgroup[256] = { '\0' };
char username[256] = { '\0' };
char password[256] = { '\0' };
char *ret;
char temp[128];
char server[256] = { '\0' };
char share[256] = { '\0' };
char workgroup[256] = { '\0' };
char username[256] = { '\0' };
char password[256] = { '\0' };
char *ret;
static int krb5_set = 1;
static int krb5_set = 1;
if (strcmp(server, pServer) == 0 &&
strcmp(share, pShare) == 0 &&
*workgroup != '\0' &&
*username != '\0')
{
strncpy(pWorkgroup, workgroup, maxLenWorkgroup - 1);
strncpy(pUsername, username, maxLenUsername - 1);
strncpy(pPassword, password, maxLenPassword - 1);
return;
}
if (strcmp(server, pServer) == 0 &&
strcmp(share, pShare) == 0 &&
*workgroup != '\0' &&
*username != '\0')
{
strncpy(pWorkgroup, workgroup, maxLenWorkgroup - 1);
strncpy(pUsername, username, maxLenUsername - 1);
strncpy(pPassword, password, maxLenPassword - 1);
return;
}
if (krb5_set && getenv("KRB5CCNAME")) {
krb5_set = 0;
return;
}
if (krb5_set && getenv("KRB5CCNAME")) {
krb5_set = 0;
return;
}
fprintf(stdout, "Workgroup: [%s] ", pWorkgroup);
ret = fgets(temp, sizeof(temp), stdin);
if (ret == NULL) {
return;
}
if (temp[strlen(temp) - 1] == '\n') /* A new line? */
{
temp[strlen(temp) - 1] = '\0';
}
if (temp[0] != '\0')
{
strncpy(pWorkgroup, temp, maxLenWorkgroup - 1);
}
fprintf(stdout, "Username: [%s] ", pUsername);
ret = fgets(temp, sizeof(temp), stdin);
if (ret == NULL) {
return;
}
if (temp[strlen(temp) - 1] == '\n') /* A new line? */
{
temp[strlen(temp) - 1] = '\0';
}
if (temp[0] != '\0')
{
strncpy(pUsername, temp, maxLenUsername - 1);
}
fprintf(stdout, "Password: ");
ret = fgets(temp, sizeof(temp), stdin);
if (ret == NULL) {
return;
}
if (temp[strlen(temp) - 1] == '\n') /* A new line? */
{
temp[strlen(temp) - 1] = '\0';
}
if (temp[0] != '\0')
{
strncpy(pPassword, temp, maxLenPassword - 1);
}
fprintf(stdout, "Workgroup: [%s] ", pWorkgroup);
ret = fgets(temp, sizeof(temp), stdin);
if (ret == NULL) {
return;
}
strncpy(workgroup, pWorkgroup, sizeof(workgroup) - 1);
strncpy(username, pUsername, sizeof(username) - 1);
strncpy(password, pPassword, sizeof(password) - 1);
if (temp[strlen(temp) - 1] == '\n') /* A new line? */
{
temp[strlen(temp) - 1] = '\0';
}
krb5_set = 1;
if (temp[0] != '\0')
{
strncpy(pWorkgroup, temp, maxLenWorkgroup - 1);
}
fprintf(stdout, "Username: [%s] ", pUsername);
ret = fgets(temp, sizeof(temp), stdin);
if (ret == NULL) {
return;
}
if (temp[strlen(temp) - 1] == '\n') /* A new line? */
{
temp[strlen(temp) - 1] = '\0';
}
if (temp[0] != '\0')
{
strncpy(pUsername, temp, maxLenUsername - 1);
}
fprintf(stdout, "Password: ");
ret = fgets(temp, sizeof(temp), stdin);
if (ret == NULL) {
return;
}
if (temp[strlen(temp) - 1] == '\n') /* A new line? */
{
temp[strlen(temp) - 1] = '\0';
}
if (temp[0] != '\0')
{
strncpy(pPassword, temp, maxLenPassword - 1);
}
strncpy(workgroup, pWorkgroup, sizeof(workgroup) - 1);
strncpy(username, pUsername, sizeof(username) - 1);
strncpy(password, pPassword, sizeof(password) - 1);
krb5_set = 1;
}

View File

@ -36,105 +36,105 @@ int main(int argc, const char *argv[])
poptContext pc;
struct stat st;
struct poptOption long_options[] =
{
POPT_AUTOHELP
{
.longName = "numeric",
.shortName = 'n',
.argInfo = POPT_ARG_NONE,
.arg = &numeric,
.val = 1,
.descrip = "Don't resolve sids or masks to names"
},
{
.longName = "debug",
.shortName = 'd',
.argInfo = POPT_ARG_INT,
.arg = &debug,
.val = 0,
.descrip = "Set debug level (0-100)"
},
{
.longName = "full_time_names",
.shortName = 'f',
.argInfo = POPT_ARG_NONE,
.arg = &full_time_names,
.val = 1,
.descrip = "Use new style xattr names, which include CREATE_TIME"
},
{
.longName = "delete",
.shortName = 'D',
.argInfo = POPT_ARG_STRING,
.arg = NULL,
.val = 'D',
.descrip = "Delete an acl",
.argDescrip = "ACL"
},
{
.longName = "modify",
.shortName = 'M',
.argInfo = POPT_ARG_STRING,
.arg = NULL,
.val = 'M',
.descrip = "Modify an acl",
.argDescrip = "ACL"
},
{
.longName = "add",
.shortName = 'a',
.argInfo = POPT_ARG_STRING,
.arg = NULL,
.val = 'a',
.descrip = "Add an acl",
.argDescrip = "ACL"
},
{
.longName = "set",
.shortName = 'S',
.argInfo = POPT_ARG_STRING,
.arg = NULL,
.val = 'S',
.descrip = "Set acls",
.argDescrip = "ACLS"
},
{
.longName = "chown",
.shortName = 'C',
.argInfo = POPT_ARG_STRING,
.arg = NULL,
.val = 'C',
.descrip = "Change ownership of a file",
.argDescrip = "USERNAME"
},
{
.longName = "chgrp",
.shortName = 'G',
.argInfo = POPT_ARG_STRING,
.arg = NULL,
.val = 'G',
.descrip = "Change group ownership of a file",
.argDescrip = "GROUPNAME"
},
{
.longName = "get",
.shortName = 'g',
.argInfo = POPT_ARG_STRING,
.arg = NULL,
.val = 'g',
.descrip = "Get a specific acl attribute",
.argDescrip = "ACL"
},
{
.longName = "stat_and_retry",
.shortName = 'R',
.argInfo = POPT_ARG_NONE,
.arg = &stat_and_retry,
.val = 1,
.descrip = "After 'get' do 'stat' and another 'get'"
},
POPT_TABLEEND
};
POPT_AUTOHELP
{
.longName = "numeric",
.shortName = 'n',
.argInfo = POPT_ARG_NONE,
.arg = &numeric,
.val = 1,
.descrip = "Don't resolve sids or masks to names"
},
{
.longName = "debug",
.shortName = 'd',
.argInfo = POPT_ARG_INT,
.arg = &debug,
.val = 0,
.descrip = "Set debug level (0-100)"
},
{
.longName = "full_time_names",
.shortName = 'f',
.argInfo = POPT_ARG_NONE,
.arg = &full_time_names,
.val = 1,
.descrip = "Use new style xattr names, which include CREATE_TIME"
},
{
.longName = "delete",
.shortName = 'D',
.argInfo = POPT_ARG_STRING,
.arg = NULL,
.val = 'D',
.descrip = "Delete an acl",
.argDescrip = "ACL"
},
{
.longName = "modify",
.shortName = 'M',
.argInfo = POPT_ARG_STRING,
.arg = NULL,
.val = 'M',
.descrip = "Modify an acl",
.argDescrip = "ACL"
},
{
.longName = "add",
.shortName = 'a',
.argInfo = POPT_ARG_STRING,
.arg = NULL,
.val = 'a',
.descrip = "Add an acl",
.argDescrip = "ACL"
},
{
.longName = "set",
.shortName = 'S',
.argInfo = POPT_ARG_STRING,
.arg = NULL,
.val = 'S',
.descrip = "Set acls",
.argDescrip = "ACLS"
},
{
.longName = "chown",
.shortName = 'C',
.argInfo = POPT_ARG_STRING,
.arg = NULL,
.val = 'C',
.descrip = "Change ownership of a file",
.argDescrip = "USERNAME"
},
{
.longName = "chgrp",
.shortName = 'G',
.argInfo = POPT_ARG_STRING,
.arg = NULL,
.val = 'G',
.descrip = "Change group ownership of a file",
.argDescrip = "GROUPNAME"
},
{
.longName = "get",
.shortName = 'g',
.argInfo = POPT_ARG_STRING,
.arg = NULL,
.val = 'g',
.descrip = "Get a specific acl attribute",
.argDescrip = "ACL"
},
{
.longName = "stat_and_retry",
.shortName = 'R',
.argInfo = POPT_ARG_NONE,
.arg = &stat_and_retry,
.val = 1,
.descrip = "After 'get' do 'stat' and another 'get'"
},
POPT_TABLEEND
};
setbuf(stdout, NULL);
@ -210,7 +210,7 @@ int main(int argc, const char *argv[])
if (ret < 0)
{
printf("Could not get attribute list for [%s] %d: %s\n",
path, errno, strerror(errno));
path, errno, strerror(errno));
return 1;
}
@ -247,7 +247,7 @@ int main(int argc, const char *argv[])
if (ret < 0)
{
printf("Could not get attributes for [%s] %d: %s\n",
path, errno, strerror(errno));
path, errno, strerror(errno));
return 1;
}
@ -278,16 +278,16 @@ int main(int argc, const char *argv[])
case SMB_ACL_CHOWN:
snprintf(value, sizeof(value),
"system.nt_sec_desc.owner%s:%s",
numeric ? "" : "+", the_acl);
"system.nt_sec_desc.owner%s:%s",
numeric ? "" : "+", the_acl);
the_acl = value;
debugstr = "chown owner";
goto do_set;
case SMB_ACL_CHGRP:
snprintf(value, sizeof(value),
"system.nt_sec_desc.group%s:%s",
numeric ? "" : "+", the_acl);
"system.nt_sec_desc.group%s:%s",
numeric ? "" : "+", the_acl);
the_acl = value;
debugstr = "change group";
goto do_set;
@ -296,7 +296,7 @@ int main(int argc, const char *argv[])
flags = 0;
debugstr = "set attributes";
do_set:
do_set:
if ((p = strchr(the_acl, ':')) == NULL)
{
printf("Missing value. ACL must be name:value pair\n");
@ -309,7 +309,7 @@ do_set:
if (ret < 0)
{
printf("Could not %s for [%s] %d: %s\n",
debugstr, path, errno, strerror(errno));
debugstr, path, errno, strerror(errno));
return 1;
}
break;
@ -319,7 +319,7 @@ do_set:
if (ret < 0)
{
printf("Could not remove attribute %s for [%s] %d:%s\n",
the_acl, path, errno, strerror(errno));
the_acl, path, errno, strerror(errno));
return 1;
}
break;

View File

@ -19,55 +19,55 @@ enum acl_mode
int main(int argc, const char *argv[])
{
int flags;
int debug = 0;
static char *the_acl = NULL;
int ret;
const char *debugstr;
char value[1024];
SMBCCTX *context;
int flags;
int debug = 0;
static char *the_acl = NULL;
int ret;
const char *debugstr;
char value[1024];
SMBCCTX *context;
if (smbc_init(get_auth_data_fn, debug) != 0)
{
printf("Could not initialize smbc_ library\n");
return 1;
}
if (smbc_init(get_auth_data_fn, debug) != 0)
{
printf("Could not initialize smbc_ library\n");
return 1;
}
context = smbc_set_context(NULL);
smbc_setOptionFullTimeNames(context, 1);
the_acl = strdup("system.nt_sec_desc.*");
ret = smbc_getxattr(argv[1], the_acl, value, sizeof(value));
if (ret < 0)
{
printf("Could not get attributes for [%s] %d: %s\n",
argv[1], errno, strerror(errno));
return 1;
}
printf("Attributes for [%s] are:\n%s\n", argv[1], value);
context = smbc_set_context(NULL);
smbc_setOptionFullTimeNames(context, 1);
flags = 0;
debugstr = "set attributes (1st time)";
ret = smbc_setxattr(argv[1], the_acl, value, strlen(value), flags);
if (ret < 0)
{
printf("Could not %s for [%s] %d: %s\n",
debugstr, argv[1], errno, strerror(errno));
return 1;
}
flags = 0;
debugstr = "set attributes (2nd time)";
ret = smbc_setxattr(argv[1], the_acl, value, strlen(value), flags);
if (ret < 0)
{
printf("Could not %s for [%s] %d: %s\n",
debugstr, argv[1], errno, strerror(errno));
return 1;
}
return 0;
the_acl = strdup("system.nt_sec_desc.*");
ret = smbc_getxattr(argv[1], the_acl, value, sizeof(value));
if (ret < 0)
{
printf("Could not get attributes for [%s] %d: %s\n",
argv[1], errno, strerror(errno));
return 1;
}
printf("Attributes for [%s] are:\n%s\n", argv[1], value);
flags = 0;
debugstr = "set attributes (1st time)";
ret = smbc_setxattr(argv[1], the_acl, value, strlen(value), flags);
if (ret < 0)
{
printf("Could not %s for [%s] %d: %s\n",
debugstr, argv[1], errno, strerror(errno));
return 1;
}
flags = 0;
debugstr = "set attributes (2nd time)";
ret = smbc_setxattr(argv[1], the_acl, value, strlen(value), flags);
if (ret < 0)
{
printf("Could not %s for [%s] %d: %s\n",
debugstr, argv[1], errno, strerror(errno));
return 1;
}
return 0;
}

View File

@ -1,59 +1,59 @@
#include <sys/types.h>
#include <stdio.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <string.h>
#include <time.h>
#include <errno.h>
#include <libsmbclient.h>
#include <libsmbclient.h>
#include "get_auth_data_fn.h"
int main(int argc, char * argv[])
{
int ret;
int debug = 0;
char value[2048];
char path[2048];
char * the_acl;
char * p;
SMBCCTX * context;
smbc_init(get_auth_data_fn, debug);
context = smbc_set_context(NULL);
smbc_setOptionFullTimeNames(context, 1);
for (;;)
{
fprintf(stdout, "Path: ");
*path = '\0';
p = fgets(path, sizeof(path) - 1, stdin);
if (p == NULL) {
printf("Error reading from stdin\n");
return 1;
int main(int argc, char * argv[])
{
int ret;
int debug = 0;
char value[2048];
char path[2048];
char * the_acl;
char * p;
SMBCCTX * context;
smbc_init(get_auth_data_fn, debug);
context = smbc_set_context(NULL);
smbc_setOptionFullTimeNames(context, 1);
for (;;)
{
fprintf(stdout, "Path: ");
*path = '\0';
p = fgets(path, sizeof(path) - 1, stdin);
if (p == NULL) {
printf("Error reading from stdin\n");
return 1;
}
if (strlen(path) == 0)
{
return 0;
}
p = path + strlen(path) - 1;
if (*p == '\n')
{
*p = '\0';
}
the_acl = strdup("system.nt_sec_desc.*+");
ret = smbc_getxattr(path, the_acl, value, sizeof(value));
if (ret < 0)
{
printf("Could not get attributes for [%s] %d: %s\n",
path, errno, strerror(errno));
return 1;
}
printf("Attributes for [%s] are:\n%s\n", path, value);
}
if (strlen(path) == 0)
{
return 0;
}
p = path + strlen(path) - 1;
if (*p == '\n')
{
*p = '\0';
}
the_acl = strdup("system.nt_sec_desc.*+");
ret = smbc_getxattr(path, the_acl, value, sizeof(value));
if (ret < 0)
{
printf("Could not get attributes for [%s] %d: %s\n",
path, errno, strerror(errno));
return 1;
}
printf("Attributes for [%s] are:\n%s\n", path, value);
}
return 0;
return 0;
}

View File

@ -27,135 +27,135 @@ get_auth_data_with_context_fn(SMBCCTX * context,
int main(int argc, const char *argv[])
{
int debug = 0;
int debug_stderr = 0;
int no_auth = 0;
int context_auth = 0;
int scan = 0;
int iterations = -1;
int opt;
char * p;
char buf[1024];
poptContext pc;
SMBCCTX * context;
struct poptOption long_options[] =
{
POPT_AUTOHELP
{
"debug", 'd', POPT_ARG_INT, &debug,
0, "Set debug level", "integer"
},
{
"stderr", 'e', POPT_ARG_NONE, &debug_stderr,
0, "Debug log to stderr instead of stdout", "integer"
},
{
"scan", 's', POPT_ARG_NONE, &scan,
0, "Scan for servers and shares", "integer"
},
{
"iterations", 'i', POPT_ARG_INT, &iterations,
0, "Iterations", "integer"
},
{
"noauth", 'A', POPT_ARG_NONE, &no_auth,
0, "Do not request authentication data", "integer"
},
{
"contextauth", 'C', POPT_ARG_NONE, &context_auth,
0, "Use new authentication function with context", "integer"
},
{0}
};
setbuf(stdout, NULL);
int debug = 0;
int debug_stderr = 0;
int no_auth = 0;
int context_auth = 0;
int scan = 0;
int iterations = -1;
int opt;
char * p;
char buf[1024];
poptContext pc;
SMBCCTX * context;
struct poptOption long_options[] =
{
POPT_AUTOHELP
{
"debug", 'd', POPT_ARG_INT, &debug,
0, "Set debug level", "integer"
},
{
"stderr", 'e', POPT_ARG_NONE, &debug_stderr,
0, "Debug log to stderr instead of stdout", "integer"
},
{
"scan", 's', POPT_ARG_NONE, &scan,
0, "Scan for servers and shares", "integer"
},
{
"iterations", 'i', POPT_ARG_INT, &iterations,
0, "Iterations", "integer"
},
{
"noauth", 'A', POPT_ARG_NONE, &no_auth,
0, "Do not request authentication data", "integer"
},
{
"contextauth", 'C', POPT_ARG_NONE, &context_auth,
0, "Use new authentication function with context", "integer"
},
{0}
};
pc = poptGetContext("opendir", argc, argv, long_options, 0);
poptSetOtherOptionHelp(pc, "");
while ((opt = poptGetNextOpt(pc)) != -1) {
printf("Got option %d = %c\n", opt, opt);
switch (opt) {
}
}
setbuf(stdout, NULL);
/* Allocate a new context */
context = smbc_new_context();
if (!context) {
printf("Could not allocate new smbc context\n");
return 1;
}
/* If we're scanning, do no requests for authentication data */
if (scan) {
no_auth = 1;
}
pc = poptGetContext("opendir", argc, argv, long_options, 0);
/* Set mandatory options (is that a contradiction in terms?) */
smbc_setDebug(context, debug);
if (context_auth) {
smbc_setFunctionAuthDataWithContext(context,
get_auth_data_with_context_fn);
smbc_setOptionUserData(context, strdup("hello world"));
} else {
smbc_setFunctionAuthData(context, get_auth_data_fn);
}
poptSetOtherOptionHelp(pc, "");
smbc_setOptionUseKerberos(context, 1);
smbc_setOptionFallbackAfterKerberos(context, 1);
while ((opt = poptGetNextOpt(pc)) != -1) {
printf("Got option %d = %c\n", opt, opt);
switch (opt) {
}
}
/* If we've been asked to log to stderr instead of stdout, ... */
if (debug_stderr) {
/* ... then set the option to do so */
smbc_setOptionDebugToStderr(context, 1);
}
/* Allocate a new context */
context = smbc_new_context();
if (!context) {
printf("Could not allocate new smbc context\n");
return 1;
}
/* Initialize the context using the previously specified options */
if (!smbc_init_context(context)) {
smbc_free_context(context, 0);
printf("Could not initialize smbc context\n");
return 1;
}
/* If we're scanning, do no requests for authentication data */
if (scan) {
no_auth = 1;
}
/* Tell the compatibility layer to use this context */
smbc_set_context(context);
/* Set mandatory options (is that a contradiction in terms?) */
smbc_setDebug(context, debug);
if (context_auth) {
smbc_setFunctionAuthDataWithContext(context,
get_auth_data_with_context_fn);
smbc_setOptionUserData(context, strdup("hello world"));
} else {
smbc_setFunctionAuthData(context, get_auth_data_fn);
}
if (scan)
{
for (; iterations != 0;) {
if (iterations > 0) {
iterations--;
}
smbc_setOptionUseKerberos(context, 1);
smbc_setOptionFallbackAfterKerberos(context, 1);
snprintf(buf, sizeof(buf), "smb://");
browse(buf, scan, 0);
}
}
else
{
for (; iterations != 0;) {
if (iterations > 0) {
iterations--;
}
/* If we've been asked to log to stderr instead of stdout, ... */
if (debug_stderr) {
/* ... then set the option to do so */
smbc_setOptionDebugToStderr(context, 1);
}
fputs("url: ", stdout);
p = fgets(buf, sizeof(buf), stdin);
if (! p)
{
break;
}
/* Initialize the context using the previously specified options */
if (!smbc_init_context(context)) {
smbc_free_context(context, 0);
printf("Could not initialize smbc context\n");
return 1;
}
if ((p = strchr(buf, '\n')) != NULL)
{
*p = '\0';
}
browse(buf, scan, 0);
}
}
/* Tell the compatibility layer to use this context */
smbc_set_context(context);
exit(0);
if (scan)
{
for (; iterations != 0;) {
if (iterations > 0) {
iterations--;
}
snprintf(buf, sizeof(buf), "smb://");
browse(buf, scan, 0);
}
}
else
{
for (; iterations != 0;) {
if (iterations > 0) {
iterations--;
}
fputs("url: ", stdout);
p = fgets(buf, sizeof(buf), stdin);
if (! p)
{
break;
}
if ((p = strchr(buf, '\n')) != NULL)
{
*p = '\0';
}
browse(buf, scan, 0);
}
}
exit(0);
}
static void
@ -169,114 +169,113 @@ get_auth_data_with_context_fn(SMBCCTX * context,
char * pPassword,
int maxLenPassword)
{
printf("Authenticating with context %p", context);
if (context != NULL) {
char *user_data = smbc_getOptionUserData(context);
printf(" with user data %s", user_data);
}
printf("\n");
printf("Authenticating with context %p", context);
if (context != NULL) {
char *user_data = smbc_getOptionUserData(context);
printf(" with user data %s", user_data);
}
printf("\n");
get_auth_data_fn(pServer, pShare, pWorkgroup, maxLenWorkgroup,
pUsername, maxLenUsername, pPassword, maxLenPassword);
get_auth_data_fn(pServer, pShare, pWorkgroup, maxLenWorkgroup,
pUsername, maxLenUsername, pPassword, maxLenPassword);
}
static void browse(char * path, int scan, int indent)
{
char * p;
char buf[1024];
int dir;
struct stat st;
struct smbc_dirent * dirent;
char * p;
char buf[1024];
int dir;
struct stat st;
struct smbc_dirent * dirent;
if (! scan)
{
printf("Opening (%s)...\n", path);
}
if ((dir = smbc_opendir(path)) < 0)
{
printf("Could not open directory [%s] (%d:%s)\n",
path, errno, strerror(errno));
return;
}
if (! scan)
{
printf("Opening (%s)...\n", path);
}
while ((dirent = smbc_readdir(dir)) != NULL)
{
printf("%*.*s%-30s", indent, indent, "", dirent->name);
if ((dir = smbc_opendir(path)) < 0)
{
printf("Could not open directory [%s] (%d:%s)\n",
path, errno, strerror(errno));
return;
}
switch(dirent->smbc_type)
{
case SMBC_WORKGROUP:
printf("WORKGROUP");
break;
case SMBC_SERVER:
printf("SERVER");
break;
case SMBC_FILE_SHARE:
printf("FILE_SHARE");
break;
case SMBC_PRINTER_SHARE:
printf("PRINTER_SHARE");
break;
case SMBC_COMMS_SHARE:
printf("COMMS_SHARE");
break;
case SMBC_IPC_SHARE:
printf("IPC_SHARE");
break;
case SMBC_DIR:
printf("DIR");
break;
case SMBC_FILE:
printf("FILE");
while ((dirent = smbc_readdir(dir)) != NULL)
{
printf("%*.*s%-30s", indent, indent, "", dirent->name);
p = path + strlen(path);
strcat(p, "/");
strcat(p+1, dirent->name);
if (smbc_stat(path, &st) < 0)
{
printf(" unknown size (reason %d: %s)",
errno, strerror(errno));
}
else
{
printf(" size %lu", (unsigned long) st.st_size);
}
*p = '\0';
switch(dirent->smbc_type)
{
case SMBC_WORKGROUP:
printf("WORKGROUP");
break;
break;
case SMBC_LINK:
printf("LINK");
break;
}
case SMBC_SERVER:
printf("SERVER");
break;
printf("\n");
case SMBC_FILE_SHARE:
printf("FILE_SHARE");
break;
if (scan &&
(dirent->smbc_type == SMBC_WORKGROUP ||
dirent->smbc_type == SMBC_SERVER))
{
/*
* don't append server name to workgroup; what we want is:
*
* smb://workgroup_name
* or
* smb://server_name
*
*/
snprintf(buf, sizeof(buf), "smb://%s", dirent->name);
browse(buf, scan, indent + 2);
}
}
case SMBC_PRINTER_SHARE:
printf("PRINTER_SHARE");
break;
smbc_closedir(dir);
case SMBC_COMMS_SHARE:
printf("COMMS_SHARE");
break;
case SMBC_IPC_SHARE:
printf("IPC_SHARE");
break;
case SMBC_DIR:
printf("DIR");
break;
case SMBC_FILE:
printf("FILE");
p = path + strlen(path);
strcat(p, "/");
strcat(p+1, dirent->name);
if (smbc_stat(path, &st) < 0)
{
printf(" unknown size (reason %d: %s)",
errno, strerror(errno));
}
else
{
printf(" size %lu", (unsigned long) st.st_size);
}
*p = '\0';
break;
case SMBC_LINK:
printf("LINK");
break;
}
printf("\n");
if (scan &&
(dirent->smbc_type == SMBC_WORKGROUP ||
dirent->smbc_type == SMBC_SERVER))
{
/*
* don't append server name to workgroup; what we want is:
*
* smb://workgroup_name
* or
* smb://server_name
*
*/
snprintf(buf, sizeof(buf), "smb://%s", dirent->name);
browse(buf, scan, indent + 2);
}
}
smbc_closedir(dir);
}

View File

@ -28,143 +28,142 @@ static void smbc_auth_fn(
char *wrkgrp, int wrkgrplen,
char *user, int userlen,
char *passwd, int passwdlen){
(void) server;
(void) share;
(void) wrkgrp;
(void) wrkgrplen;
strncpy(wrkgrp, workgroup, wrkgrplen - 1); wrkgrp[wrkgrplen - 1] = 0;
strncpy(user, username, userlen - 1); user[userlen - 1] = 0;
strncpy(passwd, password, passwdlen - 1); passwd[passwdlen - 1] = 0;
(void) server;
(void) share;
(void) wrkgrp;
(void) wrkgrplen;
strncpy(wrkgrp, workgroup, wrkgrplen - 1); wrkgrp[wrkgrplen - 1] = 0;
strncpy(user, username, userlen - 1); user[userlen - 1] = 0;
strncpy(passwd, password, passwdlen - 1); passwd[passwdlen - 1] = 0;
}
static SMBCCTX* create_smbctx(void){
SMBCCTX *ctx;
SMBCCTX *ctx;
if ((ctx = smbc_new_context()) == NULL) return NULL;
if ((ctx = smbc_new_context()) == NULL) return NULL;
smbc_setDebug(ctx, debuglevel);
smbc_setFunctionAuthData(ctx, smbc_auth_fn);
smbc_setDebug(ctx, debuglevel);
smbc_setFunctionAuthData(ctx, smbc_auth_fn);
if (smbc_init_context(ctx) == NULL){
smbc_free_context(ctx, 1);
return NULL;
}
if (smbc_init_context(ctx) == NULL){
smbc_free_context(ctx, 1);
return NULL;
}
return ctx;
return ctx;
}
static void delete_smbctx(SMBCCTX* ctx){
smbc_getFunctionPurgeCachedServers(ctx)(ctx);
smbc_free_context(ctx, 1);
smbc_getFunctionPurgeCachedServers(ctx)(ctx);
smbc_free_context(ctx, 1);
}
static smbitem* get_smbitem_list(SMBCCTX *ctx, char *smb_path){
SMBCFILE *fd;
struct smbc_dirent *dirent;
smbitem *list = NULL, *item;
SMBCFILE *fd;
struct smbc_dirent *dirent;
smbitem *list = NULL, *item;
if ((fd = smbc_getFunctionOpendir(ctx)(ctx, smb_path)) == NULL)
return NULL;
while((dirent = smbc_getFunctionReaddir(ctx)(ctx, fd)) != NULL){
size_t slen;
if (strcmp(dirent->name, "") == 0) continue;
if (strcmp(dirent->name, ".") == 0) continue;
if (strcmp(dirent->name, "..") == 0) continue;
slen = strlen(dirent->name)+1;
if ((item = malloc(sizeof(smbitem) + slen)) == NULL)
continue;
item->next = list;
item->type = dirent->smbc_type;
memcpy(item->name, dirent->name, slen);
list = item;
}
smbc_getFunctionClose(ctx)(ctx, fd);
return /* smbitem_list_sort */ (list);
if ((fd = smbc_getFunctionOpendir(ctx)(ctx, smb_path)) == NULL)
return NULL;
while((dirent = smbc_getFunctionReaddir(ctx)(ctx, fd)) != NULL){
size_t slen;
if (strcmp(dirent->name, "") == 0) continue;
if (strcmp(dirent->name, ".") == 0) continue;
if (strcmp(dirent->name, "..") == 0) continue;
slen = strlen(dirent->name)+1;
if ((item = malloc(sizeof(smbitem) + slen)) == NULL)
continue;
item->next = list;
item->type = dirent->smbc_type;
memcpy(item->name, dirent->name, slen);
list = item;
}
smbc_getFunctionClose(ctx)(ctx, fd);
return /* smbitem_list_sort */ (list);
}
static void print_smb_path(const char *group, const char *path){
if ((strlen(group) == 0) && (strlen(path) == 0)) printf("/\n");
else if (strlen(path) == 0) printf("/%s\n", group);
else{
if (strlen(group) == 0) group = "(unknown_group)";
printf("/%s/%s\n", group, path);
}
if ((strlen(group) == 0) && (strlen(path) == 0)) printf("/\n");
else if (strlen(path) == 0) printf("/%s\n", group);
else{
if (strlen(group) == 0) group = "(unknown_group)";
printf("/%s/%s\n", group, path);
}
}
static void recurse(SMBCCTX *ctx, const char *smb_group, char *smb_path, int maxlen){
int len;
smbitem *list, *item;
SMBCCTX *ctx1;
len = strlen(smb_path);
list = get_smbitem_list(ctx, smb_path);
while(list != NULL){
switch(list->type){
case SMBC_WORKGROUP:
case SMBC_SERVER:
if (list->type == SMBC_WORKGROUP){
print_smb_path(list->name, "");
smb_group = list->name;
int len;
smbitem *list, *item;
SMBCCTX *ctx1;
len = strlen(smb_path);
list = get_smbitem_list(ctx, smb_path);
while(list != NULL){
switch(list->type){
case SMBC_WORKGROUP:
case SMBC_SERVER:
if (list->type == SMBC_WORKGROUP){
print_smb_path(list->name, "");
smb_group = list->name;
}
else print_smb_path(smb_group, list->name);
if (maxlen < 7 + strlen(list->name)) break;
strncpy(smb_path + 6, list->name, maxlen - 6);
smb_path[maxlen-1] = '\0';
if ((ctx1 = create_smbctx()) != NULL){
recurse(ctx1, smb_group, smb_path, maxlen);
delete_smbctx(ctx1);
}else{
recurse(ctx, smb_group, smb_path, maxlen);
smbc_getFunctionPurgeCachedServers(ctx)(ctx);
}
break;
case SMBC_FILE_SHARE:
case SMBC_DIR:
case SMBC_FILE:
if (maxlen < len + strlen(list->name) + 2) break;
smb_path[len] = '/';
strncpy(smb_path + len + 1, list->name, maxlen - len - 1);
smb_path[maxlen-1] = '\0';
print_smb_path(smb_group, smb_path + 6);
if (list->type != SMBC_FILE){
recurse(ctx, smb_group, smb_path, maxlen);
if (list->type == SMBC_FILE_SHARE)
smbc_getFunctionPurgeCachedServers(ctx)(ctx);
}
break;
}
else print_smb_path(smb_group, list->name);
if (maxlen < 7 + strlen(list->name)) break;
strncpy(smb_path + 6, list->name, maxlen - 6);
smb_path[maxlen-1] = '\0';
if ((ctx1 = create_smbctx()) != NULL){
recurse(ctx1, smb_group, smb_path, maxlen);
delete_smbctx(ctx1);
}else{
recurse(ctx, smb_group, smb_path, maxlen);
smbc_getFunctionPurgeCachedServers(ctx)(ctx);
}
break;
case SMBC_FILE_SHARE:
case SMBC_DIR:
case SMBC_FILE:
if (maxlen < len + strlen(list->name) + 2) break;
smb_path[len] = '/';
strncpy(smb_path + len + 1, list->name, maxlen - len - 1);
smb_path[maxlen-1] = '\0';
print_smb_path(smb_group, smb_path + 6);
if (list->type != SMBC_FILE){
recurse(ctx, smb_group, smb_path, maxlen);
if (list->type == SMBC_FILE_SHARE)
smbc_getFunctionPurgeCachedServers(ctx)(ctx);
}
break;
item = list;
list = list->next;
free(item);
}
item = list;
list = list->next;
free(item);
}
smb_path[len] = '\0';
smb_path[len] = '\0';
}
int main(int argc, char *argv[]){
int i;
SMBCCTX *ctx;
char smb_path[32768] = "smb://";
int i;
SMBCCTX *ctx;
char smb_path[32768] = "smb://";
if ((ctx = create_smbctx()) == NULL){
perror("Cant create samba context.");
return 1;
}
if ((ctx = create_smbctx()) == NULL){
perror("Cant create samba context.");
return 1;
}
if (argc == 1) recurse(ctx, "", smb_path, sizeof(smb_path));
else for(i = 1; i < argc; i++){
strncpy(smb_path + 6, argv[i], sizeof(smb_path) - 7);
smb_path[sizeof(smb_path) - 1] = '\0';
recurse(ctx, "", smb_path, sizeof(smb_path));
}
delete_smbctx(ctx);
return 0;
if (argc == 1) recurse(ctx, "", smb_path, sizeof(smb_path));
else for(i = 1; i < argc; i++){
strncpy(smb_path + 6, argv[i], sizeof(smb_path) - 7);
smb_path[sizeof(smb_path) - 1] = '\0';
recurse(ctx, "", smb_path, sizeof(smb_path));
}
delete_smbctx(ctx);
return 0;
}

View File

@ -1,62 +1,62 @@
#include <stdio.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <libsmbclient.h>
#include <string.h>
#include <time.h>
#include <libsmbclient.h>
#include "get_auth_data_fn.h"
int main(int argc, char * argv[])
{
int debug = 0;
int mode = 0666;
const char * pSmbPath = NULL;
struct stat st;
if (argc == 1)
{
pSmbPath = "smb://RANDOM/Public/small";
}
else if (argc == 2)
{
pSmbPath = argv[1];
}
else if (argc == 3)
{
pSmbPath = argv[1];
mode = (int) strtol(argv[2], NULL, 8);
}
else
{
printf("usage: "
"%s [ smb://path/to/file [ octal_mode ] ]\n",
argv[0]);
return 1;
}
int main(int argc, char * argv[])
{
int debug = 0;
int mode = 0666;
const char * pSmbPath = NULL;
struct stat st;
smbc_init(get_auth_data_fn, debug);
if (smbc_stat(pSmbPath, &st) < 0)
{
perror("smbc_stat");
return 1;
}
printf("\nBefore chmod: mode = %04o\n", (unsigned int)st.st_mode);
if (smbc_chmod(pSmbPath, mode) < 0)
{
perror("smbc_chmod");
return 1;
}
if (argc == 1)
{
pSmbPath = "smb://RANDOM/Public/small";
}
else if (argc == 2)
{
pSmbPath = argv[1];
}
else if (argc == 3)
{
pSmbPath = argv[1];
mode = (int) strtol(argv[2], NULL, 8);
}
else
{
printf("usage: "
"%s [ smb://path/to/file [ octal_mode ] ]\n",
argv[0]);
return 1;
}
if (smbc_stat(pSmbPath, &st) < 0)
{
perror("smbc_stat");
return 1;
}
printf("After chmod: mode = %04o\n", (unsigned int)st.st_mode);
return 0;
smbc_init(get_auth_data_fn, debug);
if (smbc_stat(pSmbPath, &st) < 0)
{
perror("smbc_stat");
return 1;
}
printf("\nBefore chmod: mode = %04o\n", (unsigned int)st.st_mode);
if (smbc_chmod(pSmbPath, mode) < 0)
{
perror("smbc_chmod");
return 1;
}
if (smbc_stat(pSmbPath, &st) < 0)
{
perror("smbc_stat");
return 1;
}
printf("After chmod: mode = %04o\n", (unsigned int)st.st_mode);
return 0;
}

View File

@ -5,29 +5,29 @@
static void create_and_destroy_context (void)
{
int i;
SMBCCTX *ctx;
ctx = smbc_new_context ();
/* Both should do the same thing */
smbc_setOptionDebugToStderr(ctx, 1);
smbc_option_set(ctx, strdup("debug_to_stderr"), 1);
smbc_setDebug(ctx, 1);
i = smbc_getDebug(ctx);
if (i != 1) {
printf("smbc_getDebug() did not return debug level set\n");
exit(1);
}
if (!smbc_getOptionDebugToStderr(ctx)) {
printf("smbc_setOptionDebugToStderr() did not stick\n");
exit(1);
}
smbc_init_context (ctx);
smbc_free_context (ctx, 1);
int i;
SMBCCTX *ctx;
ctx = smbc_new_context ();
/* Both should do the same thing */
smbc_setOptionDebugToStderr(ctx, 1);
smbc_option_set(ctx, strdup("debug_to_stderr"), 1);
smbc_setDebug(ctx, 1);
i = smbc_getDebug(ctx);
if (i != 1) {
printf("smbc_getDebug() did not return debug level set\n");
exit(1);
}
if (!smbc_getOptionDebugToStderr(ctx)) {
printf("smbc_setOptionDebugToStderr() did not stick\n");
exit(1);
}
smbc_init_context (ctx);
smbc_free_context (ctx, 1);
}
int main (int argc, char **argv)
{
create_and_destroy_context ();
create_and_destroy_context ();
return 0;
create_and_destroy_context ();
create_and_destroy_context ();
return 0;
}

View File

@ -1,134 +1,134 @@
#include <sys/types.h>
#include <sys/statvfs.h>
#include <stdio.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <string.h>
#include <time.h>
#include <errno.h>
#include <libsmbclient.h>
#include <libsmbclient.h>
#include "get_auth_data_fn.h"
int main(int argc, char * argv[])
{
int fd;
int ret;
int debug = 0;
char * p;
char path[2048];
struct stat statbuf;
struct statvfs statvfsbuf;
smbc_init(get_auth_data_fn, debug);
for (;;)
{
fprintf(stdout, "Path: ");
*path = '\0';
p = fgets(path, sizeof(path) - 1, stdin);
if (p == NULL) {
fprintf(stderr, "failed to read from stdin\n");
return 1;
}
if (strlen(path) == 0)
{
return 0;
}
int main(int argc, char * argv[])
{
int fd;
int ret;
int debug = 0;
char * p;
char path[2048];
struct stat statbuf;
struct statvfs statvfsbuf;
p = path + strlen(path) - 1;
if (*p == '\n')
{
*p = '\0';
}
/* Determine if it's a file or a folder */
if (smbc_stat(path, &statbuf) < 0)
{
perror("smbc_stat");
continue;
}
smbc_init(get_auth_data_fn, debug);
if (S_ISREG(statbuf.st_mode))
{
if ((fd = smbc_open(path, O_RDONLY, 0)) < 0)
{
perror("smbc_open");
continue;
}
}
else
{
if ((fd = smbc_opendir(path)) < 0)
{
perror("smbc_opendir");
continue;
}
}
for (;;)
{
fprintf(stdout, "Path: ");
*path = '\0';
p = fgets(path, sizeof(path) - 1, stdin);
if (p == NULL) {
fprintf(stderr, "failed to read from stdin\n");
return 1;
}
if (strlen(path) == 0)
{
return 0;
}
ret = smbc_fstatvfs(fd, &statvfsbuf);
p = path + strlen(path) - 1;
if (*p == '\n')
{
*p = '\0';
}
smbc_close(fd);
/* Determine if it's a file or a folder */
if (smbc_stat(path, &statbuf) < 0)
{
perror("smbc_stat");
continue;
}
if (ret < 0)
{
perror("fstatvfs");
}
else
{
printf("\n");
printf("Block Size: %lu\n", statvfsbuf.f_bsize);
printf("Fragment Size: %lu\n", statvfsbuf.f_frsize);
printf("Blocks: %llu\n",
(unsigned long long) statvfsbuf.f_blocks);
printf("Free Blocks: %llu\n",
(unsigned long long) statvfsbuf.f_bfree);
printf("Available Blocks: %llu\n",
(unsigned long long) statvfsbuf.f_bavail);
printf("Files : %llu\n",
(unsigned long long) statvfsbuf.f_files);
printf("Free Files: %llu\n",
(unsigned long long) statvfsbuf.f_ffree);
printf("Available Files: %llu\n",
(unsigned long long) statvfsbuf.f_favail);
if (S_ISREG(statbuf.st_mode))
{
if ((fd = smbc_open(path, O_RDONLY, 0)) < 0)
{
perror("smbc_open");
continue;
}
}
else
{
if ((fd = smbc_opendir(path)) < 0)
{
perror("smbc_opendir");
continue;
}
}
ret = smbc_fstatvfs(fd, &statvfsbuf);
smbc_close(fd);
if (ret < 0)
{
perror("fstatvfs");
}
else
{
printf("\n");
printf("Block Size: %lu\n", statvfsbuf.f_bsize);
printf("Fragment Size: %lu\n", statvfsbuf.f_frsize);
printf("Blocks: %llu\n",
(unsigned long long) statvfsbuf.f_blocks);
printf("Free Blocks: %llu\n",
(unsigned long long) statvfsbuf.f_bfree);
printf("Available Blocks: %llu\n",
(unsigned long long) statvfsbuf.f_bavail);
printf("Files : %llu\n",
(unsigned long long) statvfsbuf.f_files);
printf("Free Files: %llu\n",
(unsigned long long) statvfsbuf.f_ffree);
printf("Available Files: %llu\n",
(unsigned long long) statvfsbuf.f_favail);
#ifdef HAVE_FSID_INT
printf("File System ID: %lu\n",
(unsigned long) statvfsbuf.f_fsid);
printf("File System ID: %lu\n",
(unsigned long) statvfsbuf.f_fsid);
#endif
printf("\n");
printf("\n");
printf("Flags: 0x%lx\n", statvfsbuf.f_flag);
printf("Extended Features: ");
printf("Flags: 0x%lx\n", statvfsbuf.f_flag);
printf("Extended Features: ");
if (statvfsbuf.f_flag & SMBC_VFS_FEATURE_NO_UNIXCIFS)
{
printf("NO_UNIXCIFS ");
}
else
{
printf("unixcifs ");
}
if (statvfsbuf.f_flag & SMBC_VFS_FEATURE_NO_UNIXCIFS)
{
printf("NO_UNIXCIFS ");
}
else
{
printf("unixcifs ");
}
if (statvfsbuf.f_flag & SMBC_VFS_FEATURE_CASE_INSENSITIVE)
{
printf("CASE_INSENSITIVE ");
}
else
{
printf("case_sensitive ");
}
if (statvfsbuf.f_flag & SMBC_VFS_FEATURE_CASE_INSENSITIVE)
{
printf("CASE_INSENSITIVE ");
}
else
{
printf("case_sensitive ");
}
if (statvfsbuf.f_flag & SMBC_VFS_FEATURE_DFS)
{
printf("DFS ");
}
else
{
printf("no_dfs ");
}
if (statvfsbuf.f_flag & SMBC_VFS_FEATURE_DFS)
{
printf("DFS ");
}
else
{
printf("no_dfs ");
}
printf("\n");
}
}
printf("\n");
}
}
return 0;
return 0;
}

View File

@ -1,66 +1,66 @@
#include <sys/types.h>
#include <stdio.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <string.h>
#include <time.h>
#include <errno.h>
#include <libsmbclient.h>
#include <libsmbclient.h>
#include "get_auth_data_fn.h"
int main(int argc, char * argv[])
{
int fd;
int ret;
int debug = 0;
int savedErrno;
char buffer[2048];
char path[2048];
char * p;
smbc_init(get_auth_data_fn, debug);
for (;;)
{
fprintf(stdout, "Path: ");
*path = '\0';
p = fgets(path, sizeof(path) - 1, stdin);
if (p == NULL) {
fprintf(stderr, "failed to read from stdin\n");
return 1;
int main(int argc, char * argv[])
{
int fd;
int ret;
int debug = 0;
int savedErrno;
char buffer[2048];
char path[2048];
char * p;
smbc_init(get_auth_data_fn, debug);
for (;;)
{
fprintf(stdout, "Path: ");
*path = '\0';
p = fgets(path, sizeof(path) - 1, stdin);
if (p == NULL) {
fprintf(stderr, "failed to read from stdin\n");
return 1;
}
if (strlen(path) == 0)
{
return 0;
}
p = path + strlen(path) - 1;
if (*p == '\n')
{
*p = '\0';
}
if ((fd = smbc_open(path, O_RDONLY, 0)) < 0)
{
perror("smbc_open");
continue;
}
do
{
ret = smbc_read(fd, buffer, sizeof(buffer));
savedErrno = errno;
if (ret > 0) fwrite(buffer, 1, ret, stdout);
} while (ret > 0);
smbc_close(fd);
if (ret < 0)
{
errno = savedErrno;
perror("read");
}
}
if (strlen(path) == 0)
{
return 0;
}
p = path + strlen(path) - 1;
if (*p == '\n')
{
*p = '\0';
}
if ((fd = smbc_open(path, O_RDONLY, 0)) < 0)
{
perror("smbc_open");
continue;
}
do
{
ret = smbc_read(fd, buffer, sizeof(buffer));
savedErrno = errno;
if (ret > 0) fwrite(buffer, 1, ret, stdout);
} while (ret > 0);
smbc_close(fd);
if (ret < 0)
{
errno = savedErrno;
perror("read");
}
}
return 0;
return 0;
}

View File

@ -1,20 +1,20 @@
/*
/*
Unix SMB/CIFS implementation.
SMB client library test program
Copyright (C) Andrew Tridgell 1998
Copyright (C) Richard Sharpe 2000
Copyright (C) John Terpsra 2000
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@ -31,261 +31,261 @@
int main(int argc, char *argv[])
{
int err, fd, dh1, dsize, dirc;
const char *file = "smb://samba/public/testfile.txt";
const char *file2 = "smb://samba/public/testfile2.txt";
char buff[256];
char dirbuf[512];
char *dirp;
struct stat st1, st2;
int err, fd, dh1, dsize, dirc;
const char *file = "smb://samba/public/testfile.txt";
const char *file2 = "smb://samba/public/testfile2.txt";
char buff[256];
char dirbuf[512];
char *dirp;
struct stat st1, st2;
err = smbc_init(get_auth_data_fn, 10); /* Initialize things */
err = smbc_init(get_auth_data_fn, 10); /* Initialize things */
if (err < 0) {
if (err < 0) {
fprintf(stderr, "Initializing the smbclient library ...: %s\n", strerror(errno));
fprintf(stderr, "Initializing the smbclient library ...: %s\n", strerror(errno));
}
}
if (argc > 1) {
if (argc > 1) {
if ((dh1 = smbc_opendir(argv[1]))<1) {
if ((dh1 = smbc_opendir(argv[1]))<1) {
fprintf(stderr, "Could not open directory: %s: %s\n",
argv[1], strerror(errno));
fprintf(stderr, "Could not open directory: %s: %s\n",
argv[1], strerror(errno));
exit(1);
exit(1);
}
}
fprintf(stdout, "Directory handle: %u\n", dh1);
fprintf(stdout, "Directory handle: %u\n", dh1);
/* Now, list those directories, but in funny ways ... */
/* Now, list those directories, but in funny ways ... */
dirp = (char *)dirbuf;
dirp = (char *)dirbuf;
if ((dirc = smbc_getdents(dh1, (struct smbc_dirent *)dirp,
sizeof(dirbuf))) < 0) {
if ((dirc = smbc_getdents(dh1, (struct smbc_dirent *)dirp,
sizeof(dirbuf))) < 0) {
fprintf(stderr, "Problems getting directory entries: %s\n",
strerror(errno));
fprintf(stderr, "Problems getting directory entries: %s\n",
strerror(errno));
exit(1);
exit(1);
}
}
/* Now, process the list of names ... */
/* Now, process the list of names ... */
fprintf(stdout, "Directory listing, size = %u\n", dirc);
fprintf(stdout, "Directory listing, size = %u\n", dirc);
while (dirc > 0) {
while (dirc > 0) {
dsize = ((struct smbc_dirent *)dirp)->dirlen;
fprintf(stdout, "Dir Ent, Type: %u, Name: %s, Comment: %s\n",
((struct smbc_dirent *)dirp)->smbc_type,
((struct smbc_dirent *)dirp)->name,
((struct smbc_dirent *)dirp)->comment);
dsize = ((struct smbc_dirent *)dirp)->dirlen;
fprintf(stdout, "Dir Ent, Type: %u, Name: %s, Comment: %s\n",
((struct smbc_dirent *)dirp)->smbc_type,
((struct smbc_dirent *)dirp)->name,
((struct smbc_dirent *)dirp)->comment);
dirp += dsize;
dirc -= dsize;
dirp += dsize;
dirc -= dsize;
}
}
dirp = (char *)dirbuf;
dirp = (char *)dirbuf;
exit(1);
exit(1);
}
}
/* For now, open a file on a server that is hard coded ... later will
* read from the command line ...
*/
/* For now, open a file on a server that is hard coded ... later will
* read from the command line ...
*/
fd = smbc_open(file, O_RDWR | O_CREAT | O_TRUNC, 0666);
fd = smbc_open(file, O_RDWR | O_CREAT | O_TRUNC, 0666);
if (fd < 0) {
if (fd < 0) {
fprintf(stderr, "Creating file: %s: %s\n", file, strerror(errno));
exit(0);
fprintf(stderr, "Creating file: %s: %s\n", file, strerror(errno));
exit(0);
}
}
fprintf(stdout, "Opened or created file: %s\n", file);
fprintf(stdout, "Opened or created file: %s\n", file);
/* Now, write some date to the file ... */
/* Now, write some date to the file ... */
memset(buff, '\0', sizeof(buff));
snprintf(buff, sizeof(buff), "%s", "Some test data for the moment ...");
memset(buff, '\0', sizeof(buff));
snprintf(buff, sizeof(buff), "%s", "Some test data for the moment ...");
err = smbc_write(fd, buff, sizeof(buff));
err = smbc_write(fd, buff, sizeof(buff));
if (err < 0) {
fprintf(stderr, "writing file: %s: %s\n", file, strerror(errno));
exit(0);
if (err < 0) {
}
fprintf(stderr, "writing file: %s: %s\n", file, strerror(errno));
exit(0);
fprintf(stdout, "Wrote %lu bytes to file: %s\n",
(unsigned long) sizeof(buff), buff);
}
/* Now, seek the file back to offset 0 */
fprintf(stdout, "Wrote %lu bytes to file: %s\n",
(unsigned long) sizeof(buff), buff);
err = smbc_lseek(fd, SEEK_SET, 0);
/* Now, seek the file back to offset 0 */
if (err < 0) {
err = smbc_lseek(fd, SEEK_SET, 0);
fprintf(stderr, "Seeking file: %s: %s\n", file, strerror(errno));
exit(0);
if (err < 0) {
}
fprintf(stderr, "Seeking file: %s: %s\n", file, strerror(errno));
exit(0);
fprintf(stdout, "Completed lseek on file: %s\n", file);
}
/* Now, read the file contents back ... */
fprintf(stdout, "Completed lseek on file: %s\n", file);
err = smbc_read(fd, buff, sizeof(buff));
/* Now, read the file contents back ... */
if (err < 0) {
err = smbc_read(fd, buff, sizeof(buff));
fprintf(stderr, "Reading file: %s: %s\n", file, strerror(errno));
exit(0);
if (err < 0) {
}
fprintf(stderr, "Reading file: %s: %s\n", file, strerror(errno));
exit(0);
fprintf(stdout, "Read file: %s\n", buff); /* Should check the contents */
}
fprintf(stdout, "Now fstat'ing file: %s\n", file);
fprintf(stdout, "Read file: %s\n", buff); /* Should check the contents */
err = smbc_fstat(fd, &st1);
fprintf(stdout, "Now fstat'ing file: %s\n", file);
if (err < 0) {
err = smbc_fstat(fd, &st1);
fprintf(stderr, "Fstat'ing file: %s: %s\n", file, strerror(errno));
exit(0);
if (err < 0) {
}
fprintf(stderr, "Fstat'ing file: %s: %s\n", file, strerror(errno));
exit(0);
}
/* Now, close the file ... */
err = smbc_close(fd);
/* Now, close the file ... */
if (err < 0) {
err = smbc_close(fd);
fprintf(stderr, "Closing file: %s: %s\n", file, strerror(errno));
if (err < 0) {
}
fprintf(stderr, "Closing file: %s: %s\n", file, strerror(errno));
/* Now, rename the file ... */
}
err = smbc_rename(file, file2);
/* Now, rename the file ... */
if (err < 0) {
err = smbc_rename(file, file2);
fprintf(stderr, "Renaming file: %s to %s: %s\n", file, file2, strerror(errno));
if (err < 0) {
}
fprintf(stderr, "Renaming file: %s to %s: %s\n", file, file2, strerror(errno));
fprintf(stdout, "Renamed file %s to %s\n", file, file2);
}
/* Now, create a file and delete it ... */
fprintf(stdout, "Renamed file %s to %s\n", file, file2);
fprintf(stdout, "Now, creating file: %s so we can delete it.\n", file);
/* Now, create a file and delete it ... */
fd = smbc_open(file, O_RDWR | O_CREAT, 0666);
fprintf(stdout, "Now, creating file: %s so we can delete it.\n", file);
if (fd < 0) {
fd = smbc_open(file, O_RDWR | O_CREAT, 0666);
fprintf(stderr, "Creating file: %s: %s\n", file, strerror(errno));
exit(0);
if (fd < 0) {
}
fprintf(stderr, "Creating file: %s: %s\n", file, strerror(errno));
exit(0);
fprintf(stdout, "Opened or created file: %s\n", file);
}
err = smbc_close(fd);
fprintf(stdout, "Opened or created file: %s\n", file);
if (err < 0) {
err = smbc_close(fd);
fprintf(stderr, "Closing file: %s: %s\n", file, strerror(errno));
exit(0);
if (err < 0) {
}
/* Now, delete the file ... */
fprintf(stderr, "Closing file: %s: %s\n", file, strerror(errno));
exit(0);
fprintf(stdout, "File %s created, now deleting ...\n", file);
}
err = smbc_unlink(file);
/* Now, delete the file ... */
if (err < 0) {
fprintf(stdout, "File %s created, now deleting ...\n", file);
fprintf(stderr, "Deleting file: %s: %s\n", file, strerror(errno));
exit(0);
err = smbc_unlink(file);
}
if (err < 0) {
/* Now, stat the file, file 2 ... */
fprintf(stderr, "Deleting file: %s: %s\n", file, strerror(errno));
exit(0);
fprintf(stdout, "Now stat'ing file: %s\n", file);
}
err = smbc_stat(file2, &st2);
/* Now, stat the file, file 2 ... */
if (err < 0) {
fprintf(stdout, "Now stat'ing file: %s\n", file);
fprintf(stderr, "Stat'ing file: %s: %s\n", file, strerror(errno));
exit(0);
err = smbc_stat(file2, &st2);
}
if (err < 0) {
fprintf(stdout, "Stat'ed file: %s. Size = %d, mode = %04X\n", file2,
(int)st2.st_size, (unsigned int)st2.st_mode);
fprintf(stdout, " time: %s\n", ctime(&st2.st_atime));
fprintf(stdout, "Earlier stat: %s, Size = %d, mode = %04X\n", file,
(int)st1.st_size, (unsigned int)st1.st_mode);
fprintf(stdout, " time: %s\n", ctime(&st1.st_atime));
fprintf(stderr, "Stat'ing file: %s: %s\n", file, strerror(errno));
exit(0);
/* Now, make a directory ... */
}
fprintf(stdout, "Making directory smb://samba/public/make-dir\n");
fprintf(stdout, "Stat'ed file: %s. Size = %d, mode = %04X\n", file2,
(int)st2.st_size, (unsigned int)st2.st_mode);
fprintf(stdout, " time: %s\n", ctime(&st2.st_atime));
fprintf(stdout, "Earlier stat: %s, Size = %d, mode = %04X\n", file,
(int)st1.st_size, (unsigned int)st1.st_mode);
fprintf(stdout, " time: %s\n", ctime(&st1.st_atime));
if (smbc_mkdir("smb://samba/public/make-dir", 0666) < 0) {
/* Now, make a directory ... */
fprintf(stderr, "Error making directory: smb://samba/public/make-dir: %s\n",
strerror(errno));
fprintf(stdout, "Making directory smb://samba/public/make-dir\n");
if (errno == EEXIST) { /* Try to delete the directory */
if (smbc_mkdir("smb://samba/public/make-dir", 0666) < 0) {
fprintf(stdout, "Trying to delete directory: smb://samba/public/make-dir\n");
fprintf(stderr, "Error making directory: smb://samba/public/make-dir: %s\n",
strerror(errno));
if (smbc_rmdir("smb://samba/public/make-dir") < 0) { /* Error */
if (errno == EEXIST) { /* Try to delete the directory */
fprintf(stderr, "Error removing directory: smb://samba/public/make-dir: %s\n", strerror(errno));
fprintf(stdout, "Trying to delete directory: smb://samba/public/make-dir\n");
exit(0);
if (smbc_rmdir("smb://samba/public/make-dir") < 0) { /* Error */
}
fprintf(stderr, "Error removing directory: smb://samba/public/make-dir: %s\n", strerror(errno));
fprintf(stdout, "Making directory: smb://samba/public/make-dir\n");
exit(0);
if (smbc_mkdir("smb://samba/public/make-dir", 666) < 0) {
}
fprintf(stderr, "Error making directory: smb://samba/public/make-dir: %s\n",
strerror(errno));
fprintf(stdout, "Making directory: smb://samba/public/make-dir\n");
fprintf(stderr, "I give up!\n");
if (smbc_mkdir("smb://samba/public/make-dir", 666) < 0) {
exit(1);
fprintf(stderr, "Error making directory: smb://samba/public/make-dir: %s\n",
strerror(errno));
}
fprintf(stderr, "I give up!\n");
}
exit(1);
exit(0);
}
}
fprintf(stdout, "Made dir: make-dir\n");
return 0;
}
exit(0);
}
fprintf(stdout, "Made dir: make-dir\n");
return 0;
}

View File

@ -1,70 +1,70 @@
#include <stdio.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <libsmbclient.h>
#include <string.h>
#include <time.h>
#include <libsmbclient.h>
#include "get_auth_data_fn.h"
int main(int argc, char * argv[])
{
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;
if (argc == 1)
{
pSmbPath = "smb://RANDOM/Public/small";
pLocalPath = "/random/home/samba/small";
}
else if (argc == 2)
{
pSmbPath = argv[1];
pLocalPath = NULL;
}
else if (argc == 3)
{
pSmbPath = argv[1];
pLocalPath = argv[2];
}
else
{
printf("usage: "
"%s [ smb://path/to/file [ /nfs/or/local/path/to/file ] ]\n",
argv[0]);
return 1;
}
int main(int argc, char * argv[])
{
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;
smbc_init(get_auth_data_fn, debug);
if (smbc_stat(pSmbPath, &st) < 0)
{
perror("smbc_stat");
return 1;
}
printf("\nSAMBA\n mtime:%lld/%s ctime:%lld/%s atime:%lld/%s\n",
(long long)st.st_mtime, ctime_r(&st.st_mtime, m_time),
(long long)st.st_ctime, ctime_r(&st.st_ctime, c_time),
(long long)st.st_atime, ctime_r(&st.st_atime, a_time));
if (pLocalPath != NULL)
{
if (stat(pLocalPath, &st) < 0)
{
perror("stat");
return 1;
}
printf("LOCAL\n mtime:%lld/%s ctime:%lld/%s atime:%lld/%s\n",
(long long)st.st_mtime, ctime_r(&st.st_mtime, m_time),
(long long)st.st_ctime, ctime_r(&st.st_ctime, c_time),
(long long)st.st_atime, ctime_r(&st.st_atime, a_time));
}
if (argc == 1)
{
pSmbPath = "smb://RANDOM/Public/small";
pLocalPath = "/random/home/samba/small";
}
else if (argc == 2)
{
pSmbPath = argv[1];
pLocalPath = NULL;
}
else if (argc == 3)
{
pSmbPath = argv[1];
pLocalPath = argv[2];
}
else
{
printf("usage: "
"%s [ smb://path/to/file [ /nfs/or/local/path/to/file ] ]\n",
argv[0]);
return 1;
}
return 0;
smbc_init(get_auth_data_fn, debug);
if (smbc_stat(pSmbPath, &st) < 0)
{
perror("smbc_stat");
return 1;
}
printf("\nSAMBA\n mtime:%lld/%s ctime:%lld/%s atime:%lld/%s\n",
(long long)st.st_mtime, ctime_r(&st.st_mtime, m_time),
(long long)st.st_ctime, ctime_r(&st.st_ctime, c_time),
(long long)st.st_atime, ctime_r(&st.st_atime, a_time));
if (pLocalPath != NULL)
{
if (stat(pLocalPath, &st) < 0)
{
perror("stat");
return 1;
}
printf("LOCAL\n mtime:%lld/%s ctime:%lld/%s atime:%lld/%s\n",
(long long)st.st_mtime, ctime_r(&st.st_mtime, m_time),
(long long)st.st_ctime, ctime_r(&st.st_ctime, c_time),
(long long)st.st_atime, ctime_r(&st.st_atime, a_time));
}
return 0;
}

View File

@ -38,33 +38,33 @@ static int gettime(const char * pUrl,
char m_time[32];
char c_time[32];
char a_time[32];
smbc_init(get_auth_data_fn, 0);
if (smbc_stat(pUrl, &st) < 0)
{
perror("smbc_stat");
return 1;
}
printf("SAMBA\n mtime:%lld/%s ctime:%lld/%s atime:%lld/%s\n",
(long long)st.st_mtime, ctime_r(&st.st_mtime, m_time),
(long long)st.st_ctime, ctime_r(&st.st_ctime, c_time),
(long long)st.st_atime, ctime_r(&st.st_atime, a_time));
/* check the stat on this file */
if (stat(pLocalPath, &st) < 0)
{
perror("stat");
return 1;
}
printf("LOCAL\n mtime:%lld/%s ctime:%lld/%s atime:%lld/%s\n",
(long long)st.st_mtime, ctime_r(&st.st_mtime, m_time),
(long long)st.st_ctime, ctime_r(&st.st_ctime, c_time),
(long long)st.st_atime, ctime_r(&st.st_atime, a_time));
return 0;
}

View File

@ -25,15 +25,15 @@ int main(int argc, char* argv[])
return 1;
}
smbc_init(get_auth_data_fn, 0);
if (smbc_stat(pUrl, &st1) < 0)
{
perror("smbc_stat");
return 1;
}
if ((fd = smbc_open(pUrl, O_RDONLY, 0)) < 0)
{
perror("smbc_open");
@ -45,7 +45,7 @@ int main(int argc, char* argv[])
perror("smbc_fstat");
return 1;
}
smbc_close(fd);
#define COMPARE(name, field) \
@ -72,4 +72,3 @@ int main(int argc, char* argv[])
return 0;
}

View File

@ -1,106 +1,106 @@
#include <sys/types.h>
#include <sys/statvfs.h>
#include <stdio.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <string.h>
#include <time.h>
#include <errno.h>
#include <libsmbclient.h>
#include <libsmbclient.h>
#include "get_auth_data_fn.h"
int main(int argc, char * argv[])
{
int ret;
int debug = 0;
char * p;
char path[2048];
struct statvfs statvfsbuf;
smbc_init(get_auth_data_fn, debug);
for (;;)
{
fprintf(stdout, "Path: ");
*path = '\0';
p = fgets(path, sizeof(path) - 1, stdin);
if (p == NULL) {
fprintf(stderr, "failed to read from stdin\n");
return 1;
}
if (strlen(path) == 0)
{
return 0;
}
int main(int argc, char * argv[])
{
int ret;
int debug = 0;
char * p;
char path[2048];
struct statvfs statvfsbuf;
p = path + strlen(path) - 1;
if (*p == '\n')
{
*p = '\0';
}
ret = smbc_statvfs(path, &statvfsbuf);
smbc_init(get_auth_data_fn, debug);
if (ret < 0)
{
perror("fstatvfs");
}
else
{
printf("\n");
printf("Block Size: %lu\n", statvfsbuf.f_bsize);
printf("Fragment Size: %lu\n", statvfsbuf.f_frsize);
printf("Blocks: %llu\n",
(unsigned long long) statvfsbuf.f_blocks);
printf("Free Blocks: %llu\n",
(unsigned long long) statvfsbuf.f_bfree);
printf("Available Blocks: %llu\n",
(unsigned long long) statvfsbuf.f_bavail);
printf("Files : %llu\n",
(unsigned long long) statvfsbuf.f_files);
printf("Free Files: %llu\n",
(unsigned long long) statvfsbuf.f_ffree);
printf("Available Files: %llu\n",
(unsigned long long) statvfsbuf.f_favail);
for (;;)
{
fprintf(stdout, "Path: ");
*path = '\0';
p = fgets(path, sizeof(path) - 1, stdin);
if (p == NULL) {
fprintf(stderr, "failed to read from stdin\n");
return 1;
}
if (strlen(path) == 0)
{
return 0;
}
p = path + strlen(path) - 1;
if (*p == '\n')
{
*p = '\0';
}
ret = smbc_statvfs(path, &statvfsbuf);
if (ret < 0)
{
perror("fstatvfs");
}
else
{
printf("\n");
printf("Block Size: %lu\n", statvfsbuf.f_bsize);
printf("Fragment Size: %lu\n", statvfsbuf.f_frsize);
printf("Blocks: %llu\n",
(unsigned long long) statvfsbuf.f_blocks);
printf("Free Blocks: %llu\n",
(unsigned long long) statvfsbuf.f_bfree);
printf("Available Blocks: %llu\n",
(unsigned long long) statvfsbuf.f_bavail);
printf("Files : %llu\n",
(unsigned long long) statvfsbuf.f_files);
printf("Free Files: %llu\n",
(unsigned long long) statvfsbuf.f_ffree);
printf("Available Files: %llu\n",
(unsigned long long) statvfsbuf.f_favail);
#ifdef HAVE_FSID_INT
printf("File System ID: %lu\n",
(unsigned long) statvfsbuf.f_fsid);
printf("File System ID: %lu\n",
(unsigned long) statvfsbuf.f_fsid);
#endif
printf("\n");
printf("\n");
printf("Flags: 0x%lx\n", statvfsbuf.f_flag);
printf("Extended Features: ");
printf("Flags: 0x%lx\n", statvfsbuf.f_flag);
printf("Extended Features: ");
if (statvfsbuf.f_flag & SMBC_VFS_FEATURE_NO_UNIXCIFS)
{
printf("NO_UNIXCIFS ");
}
else
{
printf("unixcifs ");
}
if (statvfsbuf.f_flag & SMBC_VFS_FEATURE_NO_UNIXCIFS)
{
printf("NO_UNIXCIFS ");
}
else
{
printf("unixcifs ");
}
if (statvfsbuf.f_flag & SMBC_VFS_FEATURE_CASE_INSENSITIVE)
{
printf("CASE_INSENSITIVE ");
}
else
{
printf("case_sensitive ");
}
if (statvfsbuf.f_flag & SMBC_VFS_FEATURE_CASE_INSENSITIVE)
{
printf("CASE_INSENSITIVE ");
}
else
{
printf("case_sensitive ");
}
if (statvfsbuf.f_flag & SMBC_VFS_FEATURE_DFS)
{
printf("DFS ");
}
else
{
printf("no_dfs ");
}
if (statvfsbuf.f_flag & SMBC_VFS_FEATURE_DFS)
{
printf("DFS ");
}
else
{
printf("no_dfs ");
}
printf("\n");
}
}
printf("\n");
}
}
return 0;
return 0;
}

View File

@ -1,80 +1,80 @@
#include <stdio.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <string.h>
#include <time.h>
#include <errno.h>
#include <libsmbclient.h>
#include <libsmbclient.h>
#include "get_auth_data_fn.h"
int main(int argc, char * argv[])
{
int fd;
int ret;
int debug = 0;
int savedErrno;
char buffer[128];
struct stat st;
if (argc != 2)
{
printf("usage: "
"%s smb://path/to/file\n",
argv[0]);
return 1;
}
int main(int argc, char * argv[])
{
int fd;
int ret;
int debug = 0;
int savedErrno;
char buffer[128];
struct stat st;
smbc_init(get_auth_data_fn, debug);
if ((fd = smbc_open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, 0)) < 0)
{
perror("smbc_open");
return 1;
}
if (argc != 2)
{
printf("usage: "
"%s smb://path/to/file\n",
argv[0]);
return 1;
}
snprintf(buffer, sizeof(buffer), "%s", "Hello world.\nThis is a test.\n");
smbc_init(get_auth_data_fn, debug);
ret = smbc_write(fd, buffer, strlen(buffer));
savedErrno = errno;
smbc_close(fd);
if ((fd = smbc_open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, 0)) < 0)
{
perror("smbc_open");
return 1;
}
if (ret < 0)
{
errno = savedErrno;
perror("write");
}
snprintf(buffer, sizeof(buffer), "%s", "Hello world.\nThis is a test.\n");
if (smbc_stat(argv[1], &st) < 0)
{
perror("smbc_stat");
return 1;
}
printf("Original size: %lu\n", (unsigned long) st.st_size);
if ((fd = smbc_open(argv[1], O_WRONLY, 0)) < 0)
{
perror("smbc_open");
return 1;
}
ret = smbc_write(fd, buffer, strlen(buffer));
savedErrno = errno;
smbc_close(fd);
ret = smbc_ftruncate(fd, 13);
savedErrno = errno;
smbc_close(fd);
if (ret < 0)
{
errno = savedErrno;
perror("smbc_ftruncate");
return 1;
}
if (smbc_stat(argv[1], &st) < 0)
{
perror("smbc_stat");
return 1;
}
printf("New size: %lu\n", (unsigned long) st.st_size);
return 0;
if (ret < 0)
{
errno = savedErrno;
perror("write");
}
if (smbc_stat(argv[1], &st) < 0)
{
perror("smbc_stat");
return 1;
}
printf("Original size: %lu\n", (unsigned long) st.st_size);
if ((fd = smbc_open(argv[1], O_WRONLY, 0)) < 0)
{
perror("smbc_open");
return 1;
}
ret = smbc_ftruncate(fd, 13);
savedErrno = errno;
smbc_close(fd);
if (ret < 0)
{
errno = savedErrno;
perror("smbc_ftruncate");
return 1;
}
if (smbc_stat(argv[1], &st) < 0)
{
perror("smbc_stat");
return 1;
}
printf("New size: %lu\n", (unsigned long) st.st_size);
return 0;
}

View File

@ -1,75 +1,75 @@
#include "config.h"
#include <stdio.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <libsmbclient.h>
#include <string.h>
#include <time.h>
#include <libsmbclient.h>
#include "get_auth_data_fn.h"
int main(int argc, char * argv[])
{
int debug = 0;
char m_time[32];
char c_time[32];
char a_time[32];
const char * pSmbPath = NULL;
time_t t = time(NULL);
struct stat st;
struct utimbuf utimbuf;
if (argc == 1)
{
pSmbPath = "smb://RANDOM/Public/small";
}
else if (argc == 2)
{
pSmbPath = argv[1];
}
else if (argc == 3)
{
pSmbPath = argv[1];
t = (time_t) strtol(argv[2], NULL, 10);
}
else
{
printf("usage: "
"%s [ smb://path/to/file [ mtime ] ]\n",
argv[0]);
return 1;
}
int main(int argc, char * argv[])
{
int debug = 0;
char m_time[32];
char c_time[32];
char a_time[32];
const char * pSmbPath = NULL;
time_t t = time(NULL);
struct stat st;
struct utimbuf utimbuf;
smbc_init(get_auth_data_fn, debug);
if (smbc_stat(pSmbPath, &st) < 0)
{
perror("smbc_stat");
return 1;
}
printf("Before\n mtime:%lld/%s ctime:%lld/%s atime:%lld/%s\n",
(long long)st.st_mtime, ctime_r(&st.st_mtime, m_time),
(long long)st.st_ctime, ctime_r(&st.st_ctime, c_time),
(long long)st.st_atime, ctime_r(&st.st_atime, a_time));
utimbuf.actime = t; /* unchangeable (won't change) */
utimbuf.modtime = t; /* this one should succeed */
if (smbc_utime(pSmbPath, &utimbuf) < 0)
{
perror("smbc_utime");
return 1;
}
if (argc == 1)
{
pSmbPath = "smb://RANDOM/Public/small";
}
else if (argc == 2)
{
pSmbPath = argv[1];
}
else if (argc == 3)
{
pSmbPath = argv[1];
t = (time_t) strtol(argv[2], NULL, 10);
}
else
{
printf("usage: "
"%s [ smb://path/to/file [ mtime ] ]\n",
argv[0]);
return 1;
}
if (smbc_stat(pSmbPath, &st) < 0)
{
perror("smbc_stat");
return 1;
}
printf("After\n mtime:%lld/%s ctime:%lld/%s atime:%lld/%s\n",
(long long)st.st_mtime, ctime_r(&st.st_mtime, m_time),
(long long)st.st_ctime, ctime_r(&st.st_ctime, c_time),
(long long)st.st_atime, ctime_r(&st.st_atime, a_time));
return 0;
smbc_init(get_auth_data_fn, debug);
if (smbc_stat(pSmbPath, &st) < 0)
{
perror("smbc_stat");
return 1;
}
printf("Before\n mtime:%lld/%s ctime:%lld/%s atime:%lld/%s\n",
(long long)st.st_mtime, ctime_r(&st.st_mtime, m_time),
(long long)st.st_ctime, ctime_r(&st.st_ctime, c_time),
(long long)st.st_atime, ctime_r(&st.st_atime, a_time));
utimbuf.actime = t; /* unchangeable (won't change) */
utimbuf.modtime = t; /* this one should succeed */
if (smbc_utime(pSmbPath, &utimbuf) < 0)
{
perror("smbc_utime");
return 1;
}
if (smbc_stat(pSmbPath, &st) < 0)
{
perror("smbc_stat");
return 1;
}
printf("After\n mtime:%lld/%s ctime:%lld/%s atime:%lld/%s\n",
(long long)st.st_mtime, ctime_r(&st.st_mtime, m_time),
(long long)st.st_ctime, ctime_r(&st.st_ctime, c_time),
(long long)st.st_atime, ctime_r(&st.st_atime, a_time));
return 0;
}

View File

@ -1,72 +1,72 @@
#include <sys/types.h>
#include <stdio.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <string.h>
#include <time.h>
#include <errno.h>
#include <libsmbclient.h>
#include <libsmbclient.h>
#include "get_auth_data_fn.h"
int main(int argc, char * argv[])
{
int fd;
int ret;
int debug = 0;
int savedErrno;
char buffer[2048];
char path[2048];
char * p;
smbc_init(get_auth_data_fn, debug);
printf("CAUTION: This program will overwrite a file. "
"Press ENTER to continue.");
p = fgets(buffer, sizeof(buffer), stdin);
if (p == NULL) {
fprintf(stderr, "failed to read from stdin\n");
return 1;
}
int main(int argc, char * argv[])
{
int fd;
int ret;
int debug = 0;
int savedErrno;
char buffer[2048];
char path[2048];
char * p;
for (;;)
{
fprintf(stdout, "\nPath: ");
*path = '\0';
p = fgets(path, sizeof(path) - 1, stdin);
if (p == NULL) {
fprintf(stderr, "failed to read from stdin\n");
return 1;
}
if (strlen(path) == 0)
{
return 0;
}
smbc_init(get_auth_data_fn, debug);
p = path + strlen(path) - 1;
if (*p == '\n')
{
*p = '\0';
}
if ((fd = smbc_open(path, O_WRONLY | O_CREAT | O_TRUNC, 0)) < 0)
{
perror("smbc_open");
continue;
}
printf("CAUTION: This program will overwrite a file. "
"Press ENTER to continue.");
p = fgets(buffer, sizeof(buffer), stdin);
if (p == NULL) {
fprintf(stderr, "failed to read from stdin\n");
return 1;
}
snprintf(buffer, sizeof(buffer), "%s", "Hello world\n");
ret = smbc_write(fd, buffer, strlen(buffer));
savedErrno = errno;
smbc_close(fd);
for (;;)
{
fprintf(stdout, "\nPath: ");
*path = '\0';
p = fgets(path, sizeof(path) - 1, stdin);
if (p == NULL) {
fprintf(stderr, "failed to read from stdin\n");
return 1;
}
if (strlen(path) == 0)
{
return 0;
}
if (ret < 0)
{
errno = savedErrno;
perror("write");
}
}
p = path + strlen(path) - 1;
if (*p == '\n')
{
*p = '\0';
}
return 0;
if ((fd = smbc_open(path, O_WRONLY | O_CREAT | O_TRUNC, 0)) < 0)
{
perror("smbc_open");
continue;
}
snprintf(buffer, sizeof(buffer), "%s", "Hello world\n");
ret = smbc_write(fd, buffer, strlen(buffer));
savedErrno = errno;
smbc_close(fd);
if (ret < 0)
{
errno = savedErrno;
perror("write");
}
}
return 0;
}

File diff suppressed because it is too large Load Diff