static char *get_basepath(TALLOC_CTX *ctx)
{
- char *basepath = talloc_strdup(ctx, lp_usershare_path());
+ char *basepath = lp_usershare_path(ctx);
if (!basepath) {
return NULL;
us_path = talloc_asprintf(talloc_tos(),
"%s/%s",
- lp_usershare_path(),
+ lp_usershare_path(talloc_tos()),
sharename);
if (!us_path) {
TALLOC_FREE(sharename);
static int get_share_list(TALLOC_CTX *ctx, const char *wcard, bool only_ours)
{
- SMB_STRUCT_DIR *dp;
- SMB_STRUCT_DIRENT *de;
+ DIR *dp;
+ struct dirent *de;
uid_t myuid = geteuid();
struct file_list *fl = NULL;
char *basepath = get_basepath(ctx);
if (!basepath) {
return -1;
}
- dp = sys_opendir(basepath);
+ dp = opendir(basepath);
if (!dp) {
d_fprintf(stderr,
_("get_share_list: cannot open usershare directory %s. "
return -1;
}
- while((de = sys_readdir(dp)) != 0) {
+ while((de = readdir(dp)) != 0) {
SMB_STRUCT_STAT sbuf;
char *path;
const char *n = de->d_name;
basepath,
n);
if (!path) {
- sys_closedir(dp);
+ closedir(dp);
return -1;
}
}
/* (Finally) - add to list. */
- fl = TALLOC_P(ctx, struct file_list);
+ fl = talloc(ctx, struct file_list);
if (!fl) {
- sys_closedir(dp);
+ closedir(dp);
return -1;
}
fl->pathname = talloc_strdup(ctx, n);
if (!fl->pathname) {
- sys_closedir(dp);
+ closedir(dp);
return -1;
}
DLIST_ADD(flist, fl);
}
- sys_closedir(dp);
+ closedir(dp);
return 0;
}
}
#ifdef O_NOFOLLOW
- fd = sys_open(basepath, O_RDONLY|O_NOFOLLOW, 0);
+ fd = open(basepath, O_RDONLY|O_NOFOLLOW, 0);
#else
- fd = sys_open(basepath, O_RDONLY, 0);
+ fd = open(basepath, O_RDONLY, 0);
#endif
if (fd == -1) {
return net_usershare_info_usage(c, argc, argv);
}
- strlower_m(wcard);
+ if (!strlower_m(wcard)) {
+ return -1;
+ }
ctx = talloc_init("share_info");
ret = get_share_list(ctx, wcard, only_ours);
static int count_num_usershares(void)
{
- SMB_STRUCT_DIR *dp;
- SMB_STRUCT_DIRENT *de;
+ DIR *dp;
+ struct dirent *de;
int num_usershares = 0;
TALLOC_CTX *ctx = talloc_tos();
char *basepath = get_basepath(ctx);
return -1;
}
- dp = sys_opendir(basepath);
+ dp = opendir(basepath);
if (!dp) {
d_fprintf(stderr,
_("count_num_usershares: cannot open usershare "
return -1;
}
- while((de = sys_readdir(dp)) != 0) {
+ while((de = readdir(dp)) != 0) {
SMB_STRUCT_STAT sbuf;
char *path;
const char *n = de->d_name;
basepath,
n);
if (!path) {
- sys_closedir(dp);
+ closedir(dp);
return -1;
}
num_usershares++;
}
- sys_closedir(dp);
+ closedir(dp);
return num_usershares;
}
return net_usershare_list_usage(c, argc, argv);
}
- strlower_m(wcard);
+ if (!strlower_m(wcard)) {
+ return -1;
+ }
ctx = talloc_init("share_list");
ret = get_share_list(ctx, wcard, only_ours);
int net_usershare(struct net_context *c, int argc, const char **argv)
{
- SMB_STRUCT_DIR *dp;
+ DIR *dp;
struct functable func[] = {
{
return -1;
}
- dp = sys_opendir(lp_usershare_path());
+ dp = opendir(lp_usershare_path(talloc_tos()));
if (!dp) {
int err = errno;
d_fprintf(stderr,
_("net usershare: cannot open usershare directory %s. "
"Error %s\n"),
- lp_usershare_path(), strerror(err) );
+ lp_usershare_path(talloc_tos()), strerror(err) );
if (err == EACCES) {
d_fprintf(stderr,
_("You do not have permission to create a "
}
return -1;
}
- sys_closedir(dp);
+ closedir(dp);
return net_run_function(c, argc, argv, "net usershare", func);
}