diff options
author | Simo Sorce <idra@samba.org> | 2006-07-23 18:43:07 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 14:10:18 -0500 |
commit | 9c66f601f1520a99b9236c32bc9f03a33bd4b2aa (patch) | |
tree | bba8797304b7db98aa205c3cb04344072be00030 /source4/rpc_server | |
parent | 2dc38416b65177aca94b4de3c9cfcb5c8edb0df2 (diff) | |
download | samba-9c66f601f1520a99b9236c32bc9f03a33bd4b2aa.tar.gz samba-9c66f601f1520a99b9236c32bc9f03a33bd4b2aa.tar.bz2 samba-9c66f601f1520a99b9236c32bc9f03a33bd4b2aa.zip |
r17206: Add a modular API for share configuration.
Commit the classic backwards compatible module which is the default one
(This used to be commit a89cc346b9296cb49929898d257a064a6c2bae86)
Diffstat (limited to 'source4/rpc_server')
-rw-r--r-- | source4/rpc_server/common/common.h | 1 | ||||
-rw-r--r-- | source4/rpc_server/common/share_info.c | 64 | ||||
-rw-r--r-- | source4/rpc_server/config.mk | 2 | ||||
-rw-r--r-- | source4/rpc_server/srvsvc/dcesrv_srvsvc.c | 238 | ||||
-rw-r--r-- | source4/rpc_server/srvsvc/srvsvc_ntvfs.c | 34 |
5 files changed, 216 insertions, 123 deletions
diff --git a/source4/rpc_server/common/common.h b/source4/rpc_server/common/common.h index 0dc3814c71..7fec95ac52 100644 --- a/source4/rpc_server/common/common.h +++ b/source4/rpc_server/common/common.h @@ -60,4 +60,5 @@ struct dcesrv_context; +#include "param/share.h" #include "rpc_server/common/proto.h" diff --git a/source4/rpc_server/common/share_info.c b/source4/rpc_server/common/share_info.c index 285218bad1..727e89e84a 100644 --- a/source4/rpc_server/common/share_info.c +++ b/source4/rpc_server/common/share_info.c @@ -21,6 +21,7 @@ */ #include "includes.h" +#include "param/share.h" #include "librpc/gen_ndr/srvsvc.h" #include "rpc_server/dcerpc_server.h" @@ -29,42 +30,19 @@ */ /* This hardcoded value should go into a ldb database! */ -uint32_t dcesrv_common_get_count_of_shares(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx) -{ - /* what's about int -> uint32_t overflow */ - return lp_numservices(); -} - -_PUBLIC_ const char *dcesrv_common_get_share_name(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx, int snum) -{ - return talloc_strdup(mem_ctx, lp_servicename(snum)); -} - -const char *dcesrv_common_get_share_comment(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx, int snum) -{ - return talloc_strdup(mem_ctx, lp_comment(snum)); -} - -/* This hardcoded value should go into a ldb database! */ -uint32_t dcesrv_common_get_share_permissions(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx, int snum) +uint32_t dcesrv_common_get_share_permissions(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx, struct share_config *scfg) { return 0; } /* This hardcoded value should go into a ldb database! */ -uint32_t dcesrv_common_get_share_max_users(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx, int snum) -{ - return lp_max_connections(snum); -} - -/* This hardcoded value should go into a ldb database! */ -uint32_t dcesrv_common_get_share_current_users(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx, int snum) +uint32_t dcesrv_common_get_share_current_users(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx, struct share_config *scfg) { return 1; } /* This hardcoded value should go into a ldb database! */ -enum srvsvc_ShareType dcesrv_common_get_share_type(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx, int snum) +enum srvsvc_ShareType dcesrv_common_get_share_type(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx, struct share_config *scfg) { /* for disk share 0x00000000 * for print share 0x00000001 @@ -75,17 +53,19 @@ enum srvsvc_ShareType dcesrv_common_get_share_type(TALLOC_CTX *mem_ctx, struct d * this ones are hidden in NetShareEnum, but shown in NetShareEnumAll */ enum srvsvc_ShareType share_type = 0; + const char *sharetype; - if (!lp_browseable(snum)) { + if (!share_bool_option(scfg, SHARE_BROWSEABLE, SHARE_BROWSEABLE_DEFAULT)) { share_type |= STYPE_HIDDEN; } - if (strcasecmp(lp_fstype(snum), "IPC") == 0) { + sharetype = share_string_option(scfg, SHARE_TYPE, SHARE_TYPE_DEFAULT); + if (sharetype && strcasecmp(sharetype, "IPC") == 0) { share_type |= STYPE_IPC; return share_type; } - if (lp_print_ok(snum)) { + if (sharetype && strcasecmp(sharetype, "PRINTER") == 0) { share_type |= STYPE_PRINTQ; return share_type; } @@ -96,40 +76,32 @@ enum srvsvc_ShareType dcesrv_common_get_share_type(TALLOC_CTX *mem_ctx, struct d } /* This hardcoded value should go into a ldb database! */ -const char *dcesrv_common_get_share_path(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx, int snum) +const char *dcesrv_common_get_share_path(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx, struct share_config *scfg) { - if (strcasecmp(lp_fstype(snum), "IPC") == 0) { + const char *sharetype; + + sharetype = share_string_option(scfg, SHARE_TYPE, SHARE_TYPE_DEFAULT); + + if (sharetype && strcasecmp(sharetype, "IPC") == 0) { return talloc_strdup(mem_ctx, ""); } return talloc_strdup(mem_ctx, "C:\\"); } /* This hardcoded value should go into a ldb database! */ -const char *dcesrv_common_get_share_password(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx, int snum) -{ - return NULL; -} - -/* This hardcoded value should go into a ldb database! */ -uint32_t dcesrv_common_get_share_csc_policy(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx, int snum) -{ - return 0; -} - -/* This hardcoded value should go into a ldb database! */ -uint32_t dcesrv_common_get_share_dfs_flags(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx, int snum) +uint32_t dcesrv_common_get_share_dfs_flags(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx, struct share_config *scfg) { return 0; } /* This hardcoded value should go into a ldb database! */ -uint32_t dcesrv_common_get_share_unknown(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx, int snum) +uint32_t dcesrv_common_get_share_unknown(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx, struct share_config *scfg) { return 0; } /* This hardcoded value should go into a ldb database! */ -struct security_descriptor *dcesrv_common_get_security_descriptor(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx, int snum) +struct security_descriptor *dcesrv_common_get_security_descriptor(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx, struct share_config *scfg) { return NULL; } diff --git a/source4/rpc_server/config.mk b/source4/rpc_server/config.mk index afe18217c1..292a86de5b 100644 --- a/source4/rpc_server/config.mk +++ b/source4/rpc_server/config.mk @@ -56,7 +56,7 @@ OBJ_FILES = \ srvsvc/dcesrv_srvsvc.o \ srvsvc/srvsvc_ntvfs.o PUBLIC_DEPENDENCIES = \ - DCERPC_COMMON NDR_SRVSVC + DCERPC_COMMON NDR_SRVSVC share # End MODULE dcerpc_srvsvc ################################################ diff --git a/source4/rpc_server/srvsvc/dcesrv_srvsvc.c b/source4/rpc_server/srvsvc/dcesrv_srvsvc.c index 44296655ac..fbff1d6cf8 100644 --- a/source4/rpc_server/srvsvc/dcesrv_srvsvc.c +++ b/source4/rpc_server/srvsvc/dcesrv_srvsvc.c @@ -21,13 +21,13 @@ */ #include "includes.h" +#include "ntvfs/ntvfs.h" #include "rpc_server/dcerpc_server.h" #include "librpc/gen_ndr/ndr_srvsvc.h" #include "rpc_server/common/common.h" #include "auth/auth.h" #include "libcli/security/security.h" #include "system/time.h" -#include "ntvfs/ntvfs.h" #include "rpc_server/srvsvc/proto.h" #define SRVSVC_CHECK_ADMIN_ACCESS do { \ @@ -465,76 +465,77 @@ static WERROR srvsvc_NetShareAdd(struct dcesrv_call_state *dce_call, TALLOC_CTX } static WERROR srvsvc_fiel_ShareInfo(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, - int snum, uint32_t level, union srvsvc_NetShareInfo *info) + struct share_config *scfg, uint32_t level, + union srvsvc_NetShareInfo *info) { struct dcesrv_context *dce_ctx = dce_call->conn->dce_ctx; switch (level) { case 0: { - info->info0->name = dcesrv_common_get_share_name(mem_ctx, dce_ctx, snum); + info->info0->name = talloc_strdup(mem_ctx, scfg->name); W_ERROR_HAVE_NO_MEMORY(info->info0->name); return WERR_OK; } case 1: { - info->info1->name = dcesrv_common_get_share_name(mem_ctx, dce_ctx, snum); + info->info1->name = talloc_strdup(mem_ctx, scfg->name); W_ERROR_HAVE_NO_MEMORY(info->info1->name); - info->info1->type = dcesrv_common_get_share_type(mem_ctx, dce_ctx, snum); - info->info1->comment = dcesrv_common_get_share_comment(mem_ctx, dce_ctx, snum); + info->info1->type = dcesrv_common_get_share_type(mem_ctx, dce_ctx, scfg); + info->info1->comment = talloc_strdup(mem_ctx, share_string_option(scfg, SHARE_COMMENT, "")); W_ERROR_HAVE_NO_MEMORY(info->info1->comment); return WERR_OK; } case 2: { - info->info2->name = dcesrv_common_get_share_name(mem_ctx, dce_ctx, snum); + info->info2->name = talloc_strdup(mem_ctx, scfg->name); W_ERROR_HAVE_NO_MEMORY(info->info2->name); - info->info2->type = dcesrv_common_get_share_type(mem_ctx, dce_ctx, snum); - info->info2->comment = dcesrv_common_get_share_comment(mem_ctx, dce_ctx, snum); + info->info2->type = dcesrv_common_get_share_type(mem_ctx, dce_ctx, scfg); + info->info2->comment = talloc_strdup(mem_ctx, share_string_option(scfg, SHARE_COMMENT, "")); W_ERROR_HAVE_NO_MEMORY(info->info2->comment); - info->info2->permissions = dcesrv_common_get_share_permissions(mem_ctx, dce_ctx, snum); - info->info2->max_users = dcesrv_common_get_share_max_users(mem_ctx, dce_ctx, snum); - info->info2->current_users = dcesrv_common_get_share_current_users(mem_ctx, dce_ctx, snum); - info->info2->path = dcesrv_common_get_share_path(mem_ctx, dce_ctx, snum); + info->info2->permissions = dcesrv_common_get_share_permissions(mem_ctx, dce_ctx, scfg); + info->info2->max_users = share_int_option(scfg, SHARE_MAX_CONNECTIONS, SHARE_MAX_CONNECTIONS_DEFAULT); + info->info2->current_users = dcesrv_common_get_share_current_users(mem_ctx, dce_ctx, scfg); + info->info2->path = dcesrv_common_get_share_path(mem_ctx, dce_ctx, scfg); W_ERROR_HAVE_NO_MEMORY(info->info2->path); - info->info2->password = dcesrv_common_get_share_password(mem_ctx, dce_ctx, snum); + info->info2->password = talloc_strdup(mem_ctx, share_string_option(scfg, SHARE_PASSWORD, NULL)); return WERR_OK; } case 501: { - info->info501->name = dcesrv_common_get_share_name(mem_ctx, dce_ctx, snum); + info->info501->name = talloc_strdup(mem_ctx, scfg->name); W_ERROR_HAVE_NO_MEMORY(info->info501->name); - info->info501->type = dcesrv_common_get_share_type(mem_ctx, dce_ctx, snum); - info->info501->comment = dcesrv_common_get_share_comment(mem_ctx, dce_ctx, snum); + info->info501->type = dcesrv_common_get_share_type(mem_ctx, dce_ctx, scfg); + info->info501->comment = talloc_strdup(mem_ctx, share_string_option(scfg, SHARE_COMMENT, "")); W_ERROR_HAVE_NO_MEMORY(info->info501->comment); - info->info501->csc_policy = dcesrv_common_get_share_csc_policy(mem_ctx, dce_ctx, snum); + info->info501->csc_policy = share_int_option(scfg, SHARE_CSC_POLICY, SHARE_CSC_POLICY_DEFAULT); return WERR_OK; } case 502: { - info->info502->name = dcesrv_common_get_share_name(mem_ctx, dce_ctx, snum); + info->info502->name = talloc_strdup(mem_ctx, scfg->name); W_ERROR_HAVE_NO_MEMORY(info->info502->name); - info->info502->type = dcesrv_common_get_share_type(mem_ctx, dce_ctx, snum); - info->info502->comment = dcesrv_common_get_share_comment(mem_ctx, dce_ctx, snum); + info->info502->type = dcesrv_common_get_share_type(mem_ctx, dce_ctx, scfg); + info->info502->comment = talloc_strdup(mem_ctx, share_string_option(scfg, SHARE_COMMENT, "")); W_ERROR_HAVE_NO_MEMORY(info->info502->comment); - info->info502->permissions = dcesrv_common_get_share_permissions(mem_ctx, dce_ctx, snum); - info->info502->max_users = dcesrv_common_get_share_max_users(mem_ctx, dce_ctx, snum); - info->info502->current_users = dcesrv_common_get_share_current_users(mem_ctx, dce_ctx, snum); - info->info502->path = dcesrv_common_get_share_path(mem_ctx, dce_ctx, snum); + info->info502->permissions = dcesrv_common_get_share_permissions(mem_ctx, dce_ctx, scfg); + info->info502->max_users = share_int_option(scfg, SHARE_MAX_CONNECTIONS, SHARE_MAX_CONNECTIONS_DEFAULT); + info->info502->current_users = dcesrv_common_get_share_current_users(mem_ctx, dce_ctx, scfg); + info->info502->path = dcesrv_common_get_share_path(mem_ctx, dce_ctx, scfg); W_ERROR_HAVE_NO_MEMORY(info->info502->path); - info->info502->password = dcesrv_common_get_share_password(mem_ctx, dce_ctx, snum); - info->info502->unknown = dcesrv_common_get_share_unknown(mem_ctx, dce_ctx, snum); - info->info502->sd = dcesrv_common_get_security_descriptor(mem_ctx, dce_ctx, snum); + info->info502->password = talloc_strdup(mem_ctx, share_string_option(scfg, SHARE_PASSWORD, NULL)); + info->info502->unknown = dcesrv_common_get_share_unknown(mem_ctx, dce_ctx, scfg); + info->info502->sd = dcesrv_common_get_security_descriptor(mem_ctx, dce_ctx, scfg); return WERR_OK; } case 1005: { - info->info1005->dfs_flags = dcesrv_common_get_share_dfs_flags(mem_ctx, dce_ctx, snum); + info->info1005->dfs_flags = dcesrv_common_get_share_dfs_flags(mem_ctx, dce_ctx, scfg); return WERR_OK; } @@ -551,7 +552,11 @@ static WERROR srvsvc_fiel_ShareInfo(struct dcesrv_call_state *dce_call, TALLOC_C static WERROR srvsvc_NetShareEnumAll(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct srvsvc_NetShareEnumAll *r) { - struct dcesrv_context *dce_ctx = dce_call->conn->dce_ctx; + NTSTATUS nterr; + int numshares = 0; + const char **snames; + struct share_context *sctx; + struct share_config *scfg; r->out.level = r->in.level; ZERO_STRUCT(r->out.ctr); @@ -561,6 +566,16 @@ static WERROR srvsvc_NetShareEnumAll(struct dcesrv_call_state *dce_call, TALLOC_ /* TODO: - paging of results */ + nterr = share_get_context(mem_ctx, &sctx); + if (!NT_STATUS_IS_OK(nterr)) { + return ntstatus_to_werror(nterr); + } + + nterr = share_list_all(mem_ctx, sctx, &numshares, &snames); + if (!NT_STATUS_IS_OK(nterr)) { + return ntstatus_to_werror(nterr); + } + switch (r->in.level) { case 0: { @@ -570,7 +585,7 @@ static WERROR srvsvc_NetShareEnumAll(struct dcesrv_call_state *dce_call, TALLOC_ ctr0 = talloc(mem_ctx, struct srvsvc_NetShareCtr0); W_ERROR_HAVE_NO_MEMORY(ctr0); - ctr0->count = dcesrv_common_get_count_of_shares(mem_ctx, dce_ctx); + ctr0->count = numshares; ctr0->array = NULL; if (ctr0->count == 0) { @@ -581,16 +596,23 @@ static WERROR srvsvc_NetShareEnumAll(struct dcesrv_call_state *dce_call, TALLOC_ ctr0->array = talloc_array(mem_ctx, struct srvsvc_NetShareInfo0, ctr0->count); W_ERROR_HAVE_NO_MEMORY(ctr0->array); - for (i=0; i < ctr0->count; i++) { + for (i = 0; i < ctr0->count; i++) { WERROR status; union srvsvc_NetShareInfo info; + nterr = share_get_config(mem_ctx, sctx, snames[i], &scfg); + if (!NT_STATUS_IS_OK(nterr)) { + DEBUG(1, ("ERROR: Service [%s] disappeared after enumeration", snames[i])); + return WERR_GENERAL_FAILURE; + } info.info0 = &ctr0->array[i]; - status = srvsvc_fiel_ShareInfo(dce_call, mem_ctx, i, r->in.level, &info); + status = srvsvc_fiel_ShareInfo(dce_call, mem_ctx, scfg, r->in.level, &info); if (!W_ERROR_IS_OK(status)) { return status; } + talloc_free(scfg); } + talloc_free(snames); r->out.ctr.ctr0 = ctr0; r->out.totalentries = r->out.ctr.ctr0->count; @@ -604,7 +626,7 @@ static WERROR srvsvc_NetShareEnumAll(struct dcesrv_call_state *dce_call, TALLOC_ ctr1 = talloc(mem_ctx, struct srvsvc_NetShareCtr1); W_ERROR_HAVE_NO_MEMORY(ctr1); - ctr1->count = dcesrv_common_get_count_of_shares(mem_ctx, dce_ctx); + ctr1->count = numshares; ctr1->array = NULL; if (ctr1->count == 0) { @@ -619,12 +641,19 @@ static WERROR srvsvc_NetShareEnumAll(struct dcesrv_call_state *dce_call, TALLOC_ WERROR status; union srvsvc_NetShareInfo info; + nterr = share_get_config(mem_ctx, sctx, snames[i], &scfg); + if (!NT_STATUS_IS_OK(nterr)) { + DEBUG(1, ("ERROR: Service [%s] disappeared after enumeration", snames[i])); + return WERR_GENERAL_FAILURE; + } info.info1 = &ctr1->array[i]; - status = srvsvc_fiel_ShareInfo(dce_call, mem_ctx, i, r->in.level, &info); + status = srvsvc_fiel_ShareInfo(dce_call, mem_ctx, scfg, r->in.level, &info); if (!W_ERROR_IS_OK(status)) { return status; } + talloc_free(scfg); } + talloc_free(snames); r->out.ctr.ctr1 = ctr1; r->out.totalentries = r->out.ctr.ctr1->count; @@ -640,7 +669,7 @@ static WERROR srvsvc_NetShareEnumAll(struct dcesrv_call_state *dce_call, TALLOC_ ctr2 = talloc(mem_ctx, struct srvsvc_NetShareCtr2); W_ERROR_HAVE_NO_MEMORY(ctr2); - ctr2->count = dcesrv_common_get_count_of_shares(mem_ctx, dce_ctx); + ctr2->count = numshares; ctr2->array = NULL; if (ctr2->count == 0) { @@ -655,12 +684,19 @@ static WERROR srvsvc_NetShareEnumAll(struct dcesrv_call_state *dce_call, TALLOC_ WERROR status; union srvsvc_NetShareInfo info; + nterr = share_get_config(mem_ctx, sctx, snames[i], &scfg); + if (!NT_STATUS_IS_OK(nterr)) { + DEBUG(1, ("ERROR: Service [%s] disappeared after enumeration", snames[i])); + return WERR_GENERAL_FAILURE; + } info.info2 = &ctr2->array[i]; - status = srvsvc_fiel_ShareInfo(dce_call, mem_ctx, i, r->in.level, &info); + status = srvsvc_fiel_ShareInfo(dce_call, mem_ctx, scfg, r->in.level, &info); if (!W_ERROR_IS_OK(status)) { return status; } + talloc_free(scfg); } + talloc_free(snames); r->out.ctr.ctr2 = ctr2; r->out.totalentries = r->out.ctr.ctr2->count; @@ -676,7 +712,7 @@ static WERROR srvsvc_NetShareEnumAll(struct dcesrv_call_state *dce_call, TALLOC_ ctr501 = talloc(mem_ctx, struct srvsvc_NetShareCtr501); W_ERROR_HAVE_NO_MEMORY(ctr501); - ctr501->count = dcesrv_common_get_count_of_shares(mem_ctx, dce_ctx); + ctr501->count = numshares; ctr501->array = NULL; if (ctr501->count == 0) { @@ -691,12 +727,19 @@ static WERROR srvsvc_NetShareEnumAll(struct dcesrv_call_state *dce_call, TALLOC_ WERROR status; union srvsvc_NetShareInfo info; + nterr = share_get_config(mem_ctx, sctx, snames[i], &scfg); + if (!NT_STATUS_IS_OK(nterr)) { + DEBUG(1, ("ERROR: Service [%s] disappeared after enumeration", snames[i])); + return WERR_GENERAL_FAILURE; + } info.info501 = &ctr501->array[i]; - status = srvsvc_fiel_ShareInfo(dce_call, mem_ctx, i, r->in.level, &info); + status = srvsvc_fiel_ShareInfo(dce_call, mem_ctx, scfg, r->in.level, &info); if (!W_ERROR_IS_OK(status)) { return status; } + talloc_free(scfg); } + talloc_free(snames); r->out.ctr.ctr501 = ctr501; r->out.totalentries = r->out.ctr.ctr501->count; @@ -712,7 +755,7 @@ static WERROR srvsvc_NetShareEnumAll(struct dcesrv_call_state *dce_call, TALLOC_ ctr502 = talloc(mem_ctx, struct srvsvc_NetShareCtr502); W_ERROR_HAVE_NO_MEMORY(ctr502); - ctr502->count = dcesrv_common_get_count_of_shares(mem_ctx, dce_ctx); + ctr502->count = numshares; ctr502->array = NULL; if (ctr502->count == 0) { @@ -727,12 +770,19 @@ static WERROR srvsvc_NetShareEnumAll(struct dcesrv_call_state *dce_call, TALLOC_ WERROR status; union srvsvc_NetShareInfo info; + nterr = share_get_config(mem_ctx, sctx, snames[i], &scfg); + if (!NT_STATUS_IS_OK(nterr)) { + DEBUG(1, ("ERROR: Service [%s] disappeared after enumeration", snames[i])); + return WERR_GENERAL_FAILURE; + } info.info502 = &ctr502->array[i]; - status = srvsvc_fiel_ShareInfo(dce_call, mem_ctx, i, r->in.level, &info); + status = srvsvc_fiel_ShareInfo(dce_call, mem_ctx, scfg, r->in.level, &info); if (!W_ERROR_IS_OK(status)) { return status; } + talloc_free(scfg); } + talloc_free(snames); r->out.ctr.ctr502 = ctr502; r->out.totalentries = r->out.ctr.ctr502->count; @@ -752,7 +802,9 @@ static WERROR srvsvc_NetShareEnumAll(struct dcesrv_call_state *dce_call, TALLOC_ static WERROR srvsvc_NetShareGetInfo(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct srvsvc_NetShareGetInfo *r) { - int snum; + NTSTATUS nterr; + struct share_context *sctx = NULL; + struct share_config *scfg = NULL; ZERO_STRUCT(r->out); @@ -763,9 +815,14 @@ static WERROR srvsvc_NetShareGetInfo(struct dcesrv_call_state *dce_call, TALLOC_ return WERR_INVALID_PARAM; } - snum = lp_servicenumber(r->in.share_name); - if (snum < 0) { - return WERR_NET_NAME_NOT_FOUND; + nterr = share_get_context(mem_ctx, &sctx); + if (!NT_STATUS_IS_OK(nterr)) { + return ntstatus_to_werror(nterr); + } + + nterr = share_get_config(mem_ctx, sctx, r->in.share_name, &scfg); + if (!NT_STATUS_IS_OK(nterr)) { + return ntstatus_to_werror(nterr); } switch (r->in.level) { @@ -777,7 +834,7 @@ static WERROR srvsvc_NetShareGetInfo(struct dcesrv_call_state *dce_call, TALLOC_ info.info0 = talloc(mem_ctx, struct srvsvc_NetShareInfo0); W_ERROR_HAVE_NO_MEMORY(info.info0); - status = srvsvc_fiel_ShareInfo(dce_call, mem_ctx, snum, r->in.level, &info); + status = srvsvc_fiel_ShareInfo(dce_call, mem_ctx, scfg, r->in.level, &info); if (!W_ERROR_IS_OK(status)) { return status; } @@ -793,7 +850,7 @@ static WERROR srvsvc_NetShareGetInfo(struct dcesrv_call_state *dce_call, TALLOC_ info.info1 = talloc(mem_ctx, struct srvsvc_NetShareInfo1); W_ERROR_HAVE_NO_MEMORY(info.info1); - status = srvsvc_fiel_ShareInfo(dce_call, mem_ctx, snum, r->in.level, &info); + status = srvsvc_fiel_ShareInfo(dce_call, mem_ctx, scfg, r->in.level, &info); if (!W_ERROR_IS_OK(status)) { return status; } @@ -811,7 +868,7 @@ static WERROR srvsvc_NetShareGetInfo(struct dcesrv_call_state *dce_call, TALLOC_ info.info2 = talloc(mem_ctx, struct srvsvc_NetShareInfo2); W_ERROR_HAVE_NO_MEMORY(info.info2); - status = srvsvc_fiel_ShareInfo(dce_call, mem_ctx, snum, r->in.level, &info); + status = srvsvc_fiel_ShareInfo(dce_call, mem_ctx, scfg, r->in.level, &info); if (!W_ERROR_IS_OK(status)) { return status; } @@ -827,7 +884,7 @@ static WERROR srvsvc_NetShareGetInfo(struct dcesrv_call_state *dce_call, TALLOC_ info.info501 = talloc(mem_ctx, struct srvsvc_NetShareInfo501); W_ERROR_HAVE_NO_MEMORY(info.info501); - status = srvsvc_fiel_ShareInfo(dce_call, mem_ctx, snum, r->in.level, &info); + status = srvsvc_fiel_ShareInfo(dce_call, mem_ctx, scfg, r->in.level, &info); if (!W_ERROR_IS_OK(status)) { return status; } @@ -845,7 +902,7 @@ static WERROR srvsvc_NetShareGetInfo(struct dcesrv_call_state *dce_call, TALLOC_ info.info502 = talloc(mem_ctx, struct srvsvc_NetShareInfo502); W_ERROR_HAVE_NO_MEMORY(info.info502); - status = srvsvc_fiel_ShareInfo(dce_call, mem_ctx, snum, r->in.level, &info); + status = srvsvc_fiel_ShareInfo(dce_call, mem_ctx, scfg, r->in.level, &info); if (!W_ERROR_IS_OK(status)) { return status; } @@ -861,7 +918,7 @@ static WERROR srvsvc_NetShareGetInfo(struct dcesrv_call_state *dce_call, TALLOC_ info.info1005 = talloc(mem_ctx, struct srvsvc_NetShareInfo1005); W_ERROR_HAVE_NO_MEMORY(info.info1005); - status = srvsvc_fiel_ShareInfo(dce_call, mem_ctx, snum, r->in.level, &info); + status = srvsvc_fiel_ShareInfo(dce_call, mem_ctx, scfg, r->in.level, &info); if (!W_ERROR_IS_OK(status)) { return status; } @@ -1192,6 +1249,11 @@ static WERROR srvsvc_NetPRNameCompare(struct dcesrv_call_state *dce_call, TALLOC static WERROR srvsvc_NetShareEnum(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct srvsvc_NetShareEnum *r) { + NTSTATUS nterr; + int numshares = 0; + const char **snames; + struct share_context *sctx; + struct share_config *scfg; struct dcesrv_context *dce_ctx = dce_call->conn->dce_ctx; r->out.level = r->in.level; @@ -1202,6 +1264,16 @@ static WERROR srvsvc_NetShareEnum(struct dcesrv_call_state *dce_call, TALLOC_CTX /* TODO: - paging of results */ + nterr = share_get_context(mem_ctx, &sctx); + if (!NT_STATUS_IS_OK(nterr)) { + return ntstatus_to_werror(nterr); + } + + nterr = share_list_all(mem_ctx, sctx, &numshares, &snames); + if (!NT_STATUS_IS_OK(nterr)) { + return ntstatus_to_werror(nterr); + } + switch (r->in.level) { case 0: { @@ -1212,7 +1284,7 @@ static WERROR srvsvc_NetShareEnum(struct dcesrv_call_state *dce_call, TALLOC_CTX ctr0 = talloc(mem_ctx, struct srvsvc_NetShareCtr0); W_ERROR_HAVE_NO_MEMORY(ctr0); - count = dcesrv_common_get_count_of_shares(mem_ctx, dce_ctx); + count = numshares; ctr0->count = count; ctr0->array = NULL; @@ -1227,18 +1299,28 @@ static WERROR srvsvc_NetShareEnum(struct dcesrv_call_state *dce_call, TALLOC_CTX for (i=0; i < count; i++) { WERROR status; union srvsvc_NetShareInfo info; - enum srvsvc_ShareType type = dcesrv_common_get_share_type(mem_ctx, dce_ctx, i); + enum srvsvc_ShareType type; + nterr = share_get_config(mem_ctx, sctx, snames[i], &scfg); + if (!NT_STATUS_IS_OK(nterr)) { + DEBUG(1, ("ERROR: Service [%s] disappeared after enumeration", snames[i])); + return WERR_GENERAL_FAILURE; + } + + type = dcesrv_common_get_share_type(mem_ctx, dce_ctx, scfg); if (type & STYPE_HIDDEN) { ctr0->count--; + talloc_free(scfg); continue; } info.info0 = &ctr0->array[y]; - status = srvsvc_fiel_ShareInfo(dce_call, mem_ctx, i, r->in.level, &info); + status = srvsvc_fiel_ShareInfo(dce_call, mem_ctx, scfg, r->in.level, &info); W_ERROR_NOT_OK_RETURN(status); + talloc_free(scfg); y++; } + talloc_free(snames); r->out.ctr.ctr0 = ctr0; r->out.totalentries = r->out.ctr.ctr0->count; @@ -1253,7 +1335,7 @@ static WERROR srvsvc_NetShareEnum(struct dcesrv_call_state *dce_call, TALLOC_CTX ctr1 = talloc(mem_ctx, struct srvsvc_NetShareCtr1); W_ERROR_HAVE_NO_MEMORY(ctr1); - count = dcesrv_common_get_count_of_shares(mem_ctx, dce_ctx); + count = numshares; ctr1->count = count; ctr1->array = NULL; @@ -1268,18 +1350,28 @@ static WERROR srvsvc_NetShareEnum(struct dcesrv_call_state *dce_call, TALLOC_CTX for (i=0; i < count; i++) { WERROR status; union srvsvc_NetShareInfo info; - enum srvsvc_ShareType type = dcesrv_common_get_share_type(mem_ctx, dce_ctx, i); + enum srvsvc_ShareType type; + nterr = share_get_config(mem_ctx, sctx, snames[i], &scfg); + if (!NT_STATUS_IS_OK(nterr)) { + DEBUG(1, ("ERROR: Service [%s] disappeared after enumeration", snames[i])); + return WERR_GENERAL_FAILURE; + } + + type = dcesrv_common_get_share_type(mem_ctx, dce_ctx, scfg); if (type & STYPE_HIDDEN) { ctr1->count--; + talloc_free(scfg); continue; } info.info1 = &ctr1->array[y]; - status = srvsvc_fiel_ShareInfo(dce_call, mem_ctx, i, r->in.level, &info); + status = srvsvc_fiel_ShareInfo(dce_call, mem_ctx, scfg, r->in.level, &info); W_ERROR_NOT_OK_RETURN(status); + talloc_free(scfg); y++; } + talloc_free(snames); r->out.ctr.ctr1 = ctr1; r->out.totalentries = r->out.ctr.ctr1->count; @@ -1296,7 +1388,7 @@ static WERROR srvsvc_NetShareEnum(struct dcesrv_call_state *dce_call, TALLOC_CTX ctr2 = talloc(mem_ctx, struct srvsvc_NetShareCtr2); W_ERROR_HAVE_NO_MEMORY(ctr2); - count = dcesrv_common_get_count_of_shares(mem_ctx, dce_ctx); + count = numshares; ctr2->count = count; ctr2->array = NULL; @@ -1311,18 +1403,28 @@ static WERROR srvsvc_NetShareEnum(struct dcesrv_call_state *dce_call, TALLOC_CTX for (i=0; i < count; i++) { WERROR status; union srvsvc_NetShareInfo info; - enum srvsvc_ShareType type = dcesrv_common_get_share_type(mem_ctx, dce_ctx, i); + enum srvsvc_ShareType type; + + nterr = share_get_config(mem_ctx, sctx, snames[i], &scfg); + if (!NT_STATUS_IS_OK(nterr)) { + DEBUG(1, ("ERROR: Service [%s] disappeared after enumeration", snames[i])); + return WERR_GENERAL_FAILURE; + } + type = dcesrv_common_get_share_type(mem_ctx, dce_ctx, scfg); if (type & STYPE_HIDDEN) { ctr2->count--; + talloc_free(scfg); continue; } info.info2 = &ctr2->array[y]; - status = srvsvc_fiel_ShareInfo(dce_call, mem_ctx, i, r->in.level, &info); + status = srvsvc_fiel_ShareInfo(dce_call, mem_ctx, scfg, r->in.level, &info); W_ERROR_NOT_OK_RETURN(status); + talloc_free(scfg); y++; } + talloc_free(snames); r->out.ctr.ctr2 = ctr2; r->out.totalentries = r->out.ctr.ctr2->count; @@ -1339,7 +1441,7 @@ static WERROR srvsvc_NetShareEnum(struct dcesrv_call_state *dce_call, TALLOC_CTX ctr502 = talloc(mem_ctx, struct srvsvc_NetShareCtr502); W_ERROR_HAVE_NO_MEMORY(ctr502); - count = dcesrv_common_get_count_of_shares(mem_ctx, dce_ctx); + count = numshares; ctr502->count = count; ctr502->array = NULL; @@ -1354,18 +1456,28 @@ static WERROR srvsvc_NetShareEnum(struct dcesrv_call_state *dce_call, TALLOC_CTX for (i=0; i < count; i++) { WERROR status; union srvsvc_NetShareInfo info; - enum srvsvc_ShareType type = dcesrv_common_get_share_type(mem_ctx, dce_ctx, i); + enum srvsvc_ShareType type; + + nterr = share_get_config(mem_ctx, sctx, snames[i], &scfg); + if (!NT_STATUS_IS_OK(nterr)) { + DEBUG(1, ("ERROR: Service [%s] disappeared after enumeration", snames[i])); + return WERR_GENERAL_FAILURE; + } + type = dcesrv_common_get_share_type(mem_ctx, dce_ctx, scfg); if (type & STYPE_HIDDEN) { ctr502->count--; + talloc_free(scfg); continue; } info.info502 = &ctr502->array[y]; - status = srvsvc_fiel_ShareInfo(dce_call, mem_ctx, i, r->in.level, &info); + status = srvsvc_fiel_ShareInfo(dce_call, mem_ctx, scfg, r->in.level, &info); W_ERROR_NOT_OK_RETURN(status); + talloc_free(scfg); y++; } + talloc_free(snames); r->out.ctr.ctr502 = ctr502; r->out.totalentries = r->out.ctr.ctr502->count; diff --git a/source4/rpc_server/srvsvc/srvsvc_ntvfs.c b/source4/rpc_server/srvsvc/srvsvc_ntvfs.c index 8bd88e53e9..d8d305cf9b 100644 --- a/source4/rpc_server/srvsvc/srvsvc_ntvfs.c +++ b/source4/rpc_server/srvsvc/srvsvc_ntvfs.c @@ -20,10 +20,10 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "includes.h" +#include "ntvfs/ntvfs.h" #include "rpc_server/dcerpc_server.h" #include "librpc/gen_ndr/ndr_srvsvc.h" #include "rpc_server/common/common.h" -#include "ntvfs/ntvfs.h" #include "rpc_server/srvsvc/proto.h" #include "lib/socket/socket.h" @@ -58,27 +58,35 @@ NTSTATUS srvsvc_create_ntvfs_context(struct dcesrv_call_state *dce_call, struct srvsvc_ntvfs_ctx *c; struct ntvfs_request *ntvfs_req; enum ntvfs_type type; - int snum; + struct share_context *sctx; + struct share_config *scfg; + const char *sharetype; + + status = share_get_context(mem_ctx, &sctx); + if (!NT_STATUS_IS_OK(status)) { + return status; + } - snum = lp_find_valid_service(share); - if (snum == -1) { + status = share_get_config(mem_ctx, sctx, share, &scfg); + if (!NT_STATUS_IS_OK(status)) { DEBUG(0,("srvsvc_create_ntvfs_context: couldn't find service %s\n", share)); - return NT_STATUS_BAD_NETWORK_NAME; + return status; } #if 0 /* TODO: fix access cecking */ if (!socket_check_access(dce_call->connection->socket, - lp_servicename(snum), - lp_hostsallow(snum), - lp_hostsdeny(snum))) { + scfg->name, + share_string_list_option(scfg, SHARE_HOSTS_ALLOW), + share_string_list_option(scfg, SHARE_HOSTS_DENY))) { return NT_STATUS_ACCESS_DENIED; } #endif /* work out what sort of connection this is */ - if (strcmp(lp_fstype(snum), "IPC") == 0) { + sharetype = share_string_option(scfg, SHARE_TYPE, SHARE_TYPE_DEFAULT); + if (sharetype && strcmp(sharetype, "IPC") == 0) { type = NTVFS_IPC; - } else if (lp_print_ok(snum)) { + } else if (sharetype && strcmp(sharetype, "PRINTER")) { type = NTVFS_PRINT; } else { type = NTVFS_DISK; @@ -88,7 +96,7 @@ NTSTATUS srvsvc_create_ntvfs_context(struct dcesrv_call_state *dce_call, NT_STATUS_HAVE_NO_MEMORY(c); /* init ntvfs function pointers */ - status = ntvfs_init_connection(c, snum, type, + status = ntvfs_init_connection(c, scfg, type, PROTOCOL_NT1, dce_call->event_ctx, dce_call->conn->msg_ctx, @@ -96,7 +104,7 @@ NTSTATUS srvsvc_create_ntvfs_context(struct dcesrv_call_state *dce_call, &c->ntvfs); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("srvsvc_create_ntvfs_context: ntvfs_init_connection failed for service %s\n", - lp_servicename(snum))); + scfg->name)); return status; } talloc_set_destructor(c, srvsvc_ntvfs_ctx_destructor); @@ -118,7 +126,7 @@ NTSTATUS srvsvc_create_ntvfs_context(struct dcesrv_call_state *dce_call, NT_STATUS_HAVE_NO_MEMORY(ntvfs_req); /* Invoke NTVFS connection hook */ - status = ntvfs_connect(ntvfs_req, lp_servicename(snum)); + status = ntvfs_connect(ntvfs_req, scfg->name); if (!NT_STATUS_IS_OK(status)) { DEBUG(0,("srvsvc_create_ntvfs_context: NTVFS ntvfs_connect() failed!\n")); return status; |