summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorVolker Lendecke <vlendec@samba.org>2007-06-16 18:07:44 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:23:25 -0500
commit43e51b39892e1742a22c3fb61c4e8afc6a09edc0 (patch)
treeeff0702adfe05dd0efb878a6651b235b8b3821a2 /source3
parent32ba5145b8c8385f56a1e8f025c7be1bc848077b (diff)
downloadsamba-43e51b39892e1742a22c3fb61c4e8afc6a09edc0.tar.gz
samba-43e51b39892e1742a22c3fb61c4e8afc6a09edc0.tar.bz2
samba-43e51b39892e1742a22c3fb61c4e8afc6a09edc0.zip
r23522: Save us a kilobyte stack space in a hot code path: I can't see a reason
why check_path_syntax should not be able to run in-line. The destination pointer either walks side by side with the source pointer or is decremented. So as far as I can see s>=d is true throughout the whole routine. Jeremy, I'm checking this only into 3_0 for now. Please review and ack or directly merge this to 3_0_26. Thanks, Volker (This used to be commit 34a13c82a3b72d6900614b57c58fbaefeeca8fa7)
Diffstat (limited to 'source3')
-rw-r--r--source3/smbd/msdfs.c8
-rw-r--r--source3/smbd/reply.c53
2 files changed, 28 insertions, 33 deletions
diff --git a/source3/smbd/msdfs.c b/source3/smbd/msdfs.c
index 9f203bfd19..a3de199116 100644
--- a/source3/smbd/msdfs.c
+++ b/source3/smbd/msdfs.c
@@ -144,14 +144,16 @@ static NTSTATUS parse_dfs_path(const char *pathname,
*ppath_contains_wcard = False;
+ pstrcpy(pdp->reqpath, p);
+
/* Rest is reqpath. */
if (pdp->posix_path) {
- status = check_path_syntax_posix(pdp->reqpath, p);
+ status = check_path_syntax_posix(pdp->reqpath);
} else {
if (allow_wcards) {
- status = check_path_syntax_wcard(pdp->reqpath, p, ppath_contains_wcard);
+ status = check_path_syntax_wcard(pdp->reqpath, ppath_contains_wcard);
} else {
- status = check_path_syntax(pdp->reqpath, p);
+ status = check_path_syntax(pdp->reqpath);
}
}
diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c
index 72a3f5da8e..b826cc7bda 100644
--- a/source3/smbd/reply.c
+++ b/source3/smbd/reply.c
@@ -47,13 +47,12 @@ extern BOOL global_encrypted_passwords_negotiated;
/* Custom version for processing POSIX paths. */
#define IS_PATH_SEP(c,posix_only) ((c) == '/' || (!(posix_only) && (c) == '\\'))
-NTSTATUS check_path_syntax_internal(pstring destname,
- const pstring srcname,
- BOOL posix_path,
- BOOL *p_last_component_contains_wcard)
+static NTSTATUS check_path_syntax_internal(char *path,
+ BOOL posix_path,
+ BOOL *p_last_component_contains_wcard)
{
- char *d = destname;
- const char *s = srcname;
+ char *d = path;
+ const char *s = path;
NTSTATUS ret = NT_STATUS_OK;
BOOL start_of_name_component = True;
@@ -69,7 +68,7 @@ NTSTATUS check_path_syntax_internal(pstring destname,
while (IS_PATH_SEP(*s,posix_path)) {
s++;
}
- if ((d != destname) && (*s != '\0')) {
+ if ((d != path) && (*s != '\0')) {
/* We only care about non-leading or trailing '/' or '\\' */
*d++ = '/';
}
@@ -89,13 +88,13 @@ NTSTATUS check_path_syntax_internal(pstring destname,
*/
/* If we just added a '/' - delete it */
- if ((d > destname) && (*(d-1) == '/')) {
+ if ((d > path) && (*(d-1) == '/')) {
*(d-1) = '\0';
d--;
}
/* Are we at the start ? Can't go back further if so. */
- if (d <= destname) {
+ if (d <= path) {
ret = NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
break;
}
@@ -103,7 +102,7 @@ NTSTATUS check_path_syntax_internal(pstring destname,
/* We know this is safe as '/' cannot be part of a mb sequence. */
/* NOTE - if this assumption is invalid we are not in good shape... */
/* Decrement d first as d points to the *next* char to write into. */
- for (d--; d > destname; d--) {
+ for (d--; d > path; d--) {
if (*d == '/')
break;
}
@@ -177,10 +176,10 @@ NTSTATUS check_path_syntax_internal(pstring destname,
No wildcards allowed.
****************************************************************************/
-NTSTATUS check_path_syntax(pstring destname, const pstring srcname)
+NTSTATUS check_path_syntax(char *path)
{
BOOL ignore;
- return check_path_syntax_internal(destname, srcname, False, &ignore);
+ return check_path_syntax_internal(path, False, &ignore);
}
/****************************************************************************
@@ -189,9 +188,9 @@ NTSTATUS check_path_syntax(pstring destname, const pstring srcname)
a wildcard.
****************************************************************************/
-NTSTATUS check_path_syntax_wcard(pstring destname, const pstring srcname, BOOL *p_contains_wcard)
+NTSTATUS check_path_syntax_wcard(char *path, BOOL *p_contains_wcard)
{
- return check_path_syntax_internal(destname, srcname, False, p_contains_wcard);
+ return check_path_syntax_internal(path, False, p_contains_wcard);
}
/****************************************************************************
@@ -200,10 +199,10 @@ NTSTATUS check_path_syntax_wcard(pstring destname, const pstring srcname, BOOL *
set (a safe assumption).
****************************************************************************/
-NTSTATUS check_path_syntax_posix(pstring destname, const pstring srcname)
+NTSTATUS check_path_syntax_posix(char *name)
{
BOOL ignore;
- return check_path_syntax_internal(destname, srcname, True, &ignore);
+ return check_path_syntax_internal(path, True, &ignore);
}
/****************************************************************************
@@ -213,17 +212,15 @@ NTSTATUS check_path_syntax_posix(pstring destname, const pstring srcname)
size_t srvstr_get_path_wcard(char *inbuf, char *dest, const char *src, size_t dest_len, size_t src_len, int flags,
NTSTATUS *err, BOOL *contains_wcard)
{
- pstring tmppath;
- char *tmppath_ptr = tmppath;
size_t ret;
#ifdef DEVELOPER
SMB_ASSERT(dest_len == sizeof(pstring));
#endif
if (src_len == 0) {
- ret = srvstr_pull_buf( inbuf, tmppath_ptr, src, dest_len, flags);
+ ret = srvstr_pull_buf( inbuf, dest, src, dest_len, flags);
} else {
- ret = srvstr_pull( inbuf, tmppath_ptr, src, dest_len, src_len, flags);
+ ret = srvstr_pull( inbuf, dest, src, dest_len, src_len, flags);
}
*contains_wcard = False;
@@ -233,15 +230,14 @@ size_t srvstr_get_path_wcard(char *inbuf, char *dest, const char *src, size_t de
* For a DFS path the function parse_dfs_path()
* will do the path processing, just make a copy.
*/
- pstrcpy(dest, tmppath);
*err = NT_STATUS_OK;
return ret;
}
if (lp_posix_pathnames()) {
- *err = check_path_syntax_posix(dest, tmppath);
+ *err = check_path_syntax_posix(dest);
} else {
- *err = check_path_syntax_wcard(dest, tmppath, contains_wcard);
+ *err = check_path_syntax_wcard(dest, contains_wcard);
}
return ret;
@@ -253,17 +249,15 @@ size_t srvstr_get_path_wcard(char *inbuf, char *dest, const char *src, size_t de
size_t srvstr_get_path(char *inbuf, char *dest, const char *src, size_t dest_len, size_t src_len, int flags, NTSTATUS *err)
{
- pstring tmppath;
- char *tmppath_ptr = tmppath;
size_t ret;
#ifdef DEVELOPER
SMB_ASSERT(dest_len == sizeof(pstring));
#endif
if (src_len == 0) {
- ret = srvstr_pull_buf( inbuf, tmppath_ptr, src, dest_len, flags);
+ ret = srvstr_pull_buf( inbuf, dest, src, dest_len, flags);
} else {
- ret = srvstr_pull( inbuf, tmppath_ptr, src, dest_len, src_len, flags);
+ ret = srvstr_pull( inbuf, dest, src, dest_len, src_len, flags);
}
if (SVAL(inbuf,smb_flg2) & FLAGS2_DFS_PATHNAMES) {
@@ -271,15 +265,14 @@ size_t srvstr_get_path(char *inbuf, char *dest, const char *src, size_t dest_len
* For a DFS path the function parse_dfs_path()
* will do the path processing, just make a copy.
*/
- pstrcpy(dest, tmppath);
*err = NT_STATUS_OK;
return ret;
}
if (lp_posix_pathnames()) {
- *err = check_path_syntax_posix(dest, tmppath);
+ *err = check_path_syntax_posix(dest);
} else {
- *err = check_path_syntax(dest, tmppath);
+ *err = check_path_syntax(dest);
}
return ret;