From 20baa11f33c5282c609258e21a07c7255df7ae30 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 21 Apr 2011 16:50:49 -0700 Subject: Remove duplicate code - move to parent_dirname() as a common function. --- source3/smbd/vfs.c | 39 ++++++++++++++------------------------- 1 file changed, 14 insertions(+), 25 deletions(-) (limited to 'source3/smbd/vfs.c') diff --git a/source3/smbd/vfs.c b/source3/smbd/vfs.c index 414e00c080..c3c7b1a66b 100644 --- a/source3/smbd/vfs.c +++ b/source3/smbd/vfs.c @@ -899,7 +899,6 @@ char *vfs_GetWd(TALLOC_CTX *ctx, connection_struct *conn) NTSTATUS check_reduced_name(connection_struct *conn, const char *fname) { char *resolved_name = NULL; - char *p = NULL; DEBUG(3,("check_reduced_name [%s] [%s]\n", fname, conn->connectpath)); @@ -915,28 +914,20 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname) case ENOENT: { TALLOC_CTX *ctx = talloc_tos(); - char *tmp_fname = NULL; - char *last_component = NULL; - /* Last component didn't exist. Remove it and try and canonicalise the directory. */ - - tmp_fname = talloc_strdup(ctx, fname); - if (!tmp_fname) { + char *dir_name = NULL; + const char *last_component = NULL; + char *new_name = NULL; + + /* Last component didn't exist. + Remove it and try and canonicalise + the directory name. */ + if (!parent_dirname(ctx, fname, + &dir_name, + &last_component)) { return NT_STATUS_NO_MEMORY; } - p = strrchr_m(tmp_fname, '/'); - if (p) { - *p++ = '\0'; - last_component = p; - } else { - last_component = tmp_fname; - tmp_fname = talloc_strdup(ctx, - "."); - if (!tmp_fname) { - return NT_STATUS_NO_MEMORY; - } - } - resolved_name = SMB_VFS_REALPATH(conn,tmp_fname); + resolved_name = SMB_VFS_REALPATH(conn,dir_name); if (!resolved_name) { NTSTATUS status = map_nt_error_from_unix(errno); @@ -951,18 +942,16 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname) nt_errstr(status))); return status; } - tmp_fname = talloc_asprintf(ctx, + new_name = talloc_asprintf(ctx, "%s/%s", resolved_name, last_component); - if (!tmp_fname) { + if (!new_name) { return NT_STATUS_NO_MEMORY; } SAFE_FREE(resolved_name); - resolved_name = SMB_STRDUP(tmp_fname); + resolved_name = SMB_STRDUP(new_name); if (!resolved_name) { - DEBUG(0, ("check_reduced_name: malloc " - "fail for %s\n", tmp_fname)); return NT_STATUS_NO_MEMORY; } break; -- cgit