diff --git a/source3/rpc_server/srv_srvsvc_nt.c b/source3/rpc_server/srv_srvsvc_nt.c index 070f7fd..70caf97 100644 --- a/source3/rpc_server/srv_srvsvc_nt.c +++ b/source3/rpc_server/srv_srvsvc_nt.c @@ -537,7 +537,32 @@ static WERROR init_srv_share_info_ctr(pipes_struct *p, /* Count the number of entries. */ for (snum = 0; snum < num_services; snum++) { - if (lp_browseable(snum) && lp_snum_ok(snum) && + allowed[snum] = true; + if (lp_pathname(snum) != NULL) + { + /*check if the path exists.if it does not exist, then set to non-browseable*/ + /* expand the path first, for it may contain some variable such as %u %m */ + SMB_STRUCT_STAT sbuf; + char *path = talloc_asprintf(ctx, "%s", lp_pathname(snum)); + path = talloc_sub_advanced( + ctx, lp_servicename(snum), + get_current_username(), lp_pathname(snum), + p->server_info->utok.uid, get_current_username(), + "", path); + + if (sys_stat(path, &sbuf) != 0) + { + DEBUG(3, ("init_srv_share_info_ctr: stat of %s failed. %s\n", path, strerror(errno))); + allowed[snum] = false; + } + + if (!S_ISDIR(sbuf.st_ex_mode)) + { + DEBUG(3,("init_srv_share_info_ctr: %s is not a directory.\n", path)); + allowed[snum] = false; + } + } + if (allowed[snum] && lp_browseable(snum) && lp_snum_ok(snum) && is_enumeration_allowed(p, snum) && (all_shares || !is_hidden_share(snum)) ) { DEBUG(10, ("counting service %s\n", lp_servicename(snum))); @@ -545,6 +570,7 @@ static WERROR init_srv_share_info_ctr(pipes_struct *p, num_entries++; } else { DEBUG(10, ("NOT counting service %s\n", lp_servicename(snum))); + allowed[snum] = false; } }