Commit d4f8fdd6 authored by VL's avatar VL Committed by Jeremy Allison
Browse files

libsmb: Convert SMBC_getatr() to NTSTATUS



This avoids a few calls to SMBC_errno()
Signed-off-by: VL's avatarVolker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison's avatarJeremy Allison <jra@samba.org>
parent 0b351cda
......@@ -400,7 +400,7 @@ int
SMBC_close_ctx(SMBCCTX *context,
SMBCFILE *file);
bool
NTSTATUS
SMBC_getatr(SMBCCTX * context,
SMBCSRV *srv,
const char *path,
......
......@@ -985,10 +985,12 @@ SMBC_opendir_ctx(SMBCCTX *context,
*/
path[path_len] = '\0'; /* restore original path */
if (SMBC_getatr(context,
srv,
path,
&sb) &&
status = SMBC_getatr(
context,
srv,
path,
&sb);
if (NT_STATUS_IS_OK(status) &&
!S_ISDIR(sb.st_mode)) {
/* It is. Correct the error value */
......@@ -2255,14 +2257,13 @@ SMBC_unlink_ctx(SMBCCTX *context,
int saverr = errno;
struct stat sb = {0};
bool ok;
ok = SMBC_getatr(context, srv, path, &sb);
if (!ok) {
status = SMBC_getatr(context, srv, path, &sb);
if (!NT_STATUS_IS_OK(status)) {
/* Hmmm, bad error ... What? */
errno = SMBC_errno(context, targetcli);
TALLOC_FREE(frame);
errno = cli_status_to_errno(status);
return -1;
}
......
......@@ -450,7 +450,7 @@ SMBC_close_ctx(SMBCCTX *context,
* Get info from an SMB server on a file. Use a qpathinfo call first
* and if that fails, use getatr, as Win95 sometimes refuses qpathinfo
*/
bool
NTSTATUS
SMBC_getatr(SMBCCTX * context,
SMBCSRV *srv,
const char *path,
......@@ -472,25 +472,22 @@ SMBC_getatr(SMBCCTX * context,
NTSTATUS status;
if (!context || !context->internal->initialized) {
errno = EINVAL;
TALLOC_FREE(frame);
return False;
return NT_STATUS_INVALID_PARAMETER;
}
/* path fixup for . and .. */
if (ISDOT(path) || ISDOTDOT(path)) {
fixedpath = talloc_strdup(frame, "\\");
if (!fixedpath) {
errno = ENOMEM;
TALLOC_FREE(frame);
return False;
return NT_STATUS_NO_MEMORY;
}
} else {
fixedpath = talloc_strdup(frame, path);
if (!fixedpath) {
errno = ENOMEM;
TALLOC_FREE(frame);
return False;
return NT_STATUS_NO_MEMORY;
}
trim_string(fixedpath, NULL, "\\..");
trim_string(fixedpath, NULL, "\\.");
......@@ -505,9 +502,8 @@ SMBC_getatr(SMBCCTX * context,
&targetcli, &targetpath);
if (!NT_STATUS_IS_OK(status)) {
d_printf("Couldn't resolve %s\n", path);
errno = ENOENT;
TALLOC_FREE(frame);
return False;
return NT_STATUS_OBJECT_NAME_NOT_FOUND;
}
if (!srv->no_pathinfo2) {
......@@ -571,15 +567,14 @@ setup_stat:
write_time_ts);
TALLOC_FREE(frame);
return true;
return NT_STATUS_OK;
all_failed:
srv->no_pathinfo2 = False;
srv->no_pathinfo3 = False;
errno = EPERM;
TALLOC_FREE(frame);
return False;
return NT_STATUS_ACCESS_DENIED;
}
/*
......
......@@ -173,6 +173,7 @@ SMBC_stat_ctx(SMBCCTX *context,
char *workgroup = NULL;
char *path = NULL;
uint16_t port = 0;
NTSTATUS status;
TALLOC_CTX *frame = talloc_stackframe();
if (!context || !context->internal->initialized) {
......@@ -221,9 +222,10 @@ SMBC_stat_ctx(SMBCCTX *context,
return -1; /* errno set by SMBC_server */
}
if (!SMBC_getatr(context, srv, path, st)) {
errno = SMBC_errno(context, srv->cli);
status = SMBC_getatr(context, srv, path, st);
if (!NT_STATUS_IS_OK(status)) {
TALLOC_FREE(frame);
errno = cli_status_to_errno(status);
return -1;
}
......
......@@ -552,6 +552,7 @@ dos_attr_query(SMBCCTX *context,
{
struct stat sb = {0};
struct DOS_ATTR_DESC *ret = NULL;
NTSTATUS status;
ret = talloc(ctx, struct DOS_ATTR_DESC);
if (!ret) {
......@@ -560,10 +561,11 @@ dos_attr_query(SMBCCTX *context,
}
/* Obtain the DOS attributes */
if (!SMBC_getatr(context, srv, filename, &sb)) {
errno = SMBC_errno(context, srv->cli);
status = SMBC_getatr(context, srv, filename, &sb);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(5, ("dos_attr_query Failed to query old attributes\n"));
TALLOC_FREE(ret);
errno = cli_status_to_errno(status);
return NULL;
}
......@@ -1151,13 +1153,15 @@ cacl_get(SMBCCTX *context,
off_t size = 0;
uint16_t mode = 0;
SMB_INO_T ino = 0;
NTSTATUS status;
/* Point to the portion after "system.dos_attr." */
name += 16; /* if (all) this will be invalid but unused */
/* Obtain the DOS attributes */
if (!SMBC_getatr(context, srv, filename, &sb)) {
errno = SMBC_errno(context, srv->cli);
status = SMBC_getatr(context, srv, filename, &sb);
if (!NT_STATUS_IS_OK(status)) {
errno = cli_status_to_errno(status);
return -1;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment