]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3: lib: Remove the old canonicalize_absolute_path().
authorJeremy Allison <jra@samba.org>
Tue, 21 Apr 2020 20:30:38 +0000 (13:30 -0700)
committerRalph Boehme <slow@samba.org>
Wed, 22 Apr 2020 08:15:35 +0000 (08:15 +0000)
This code was really hard to understand.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/lib/util_path.c

index 5053d91935e2105b9f509698ea75b0725dae78eb..c34b734384cfc75fd7244fc474d5ae3622b43cbb 100644 (file)
@@ -107,160 +107,6 @@ char *cache_path(TALLOC_CTX *mem_ctx, const char *name)
  * @retval Pointer to a talloc'ed string containing the absolute full path.
  **/
 
-#if 0
-char *canonicalize_absolute_path(TALLOC_CTX *ctx, const char *abs_path)
-{
-       char *destname;
-       char *d;
-       const char *s = abs_path;
-       bool start_of_name_component = true;
-
-       /* Allocate for strlen + '\0' + possible leading '/' */
-       destname = (char *)talloc_size(ctx, strlen(abs_path) + 2);
-       if (destname == NULL) {
-               return NULL;
-        }
-       d = destname;
-
-       *d++ = '/'; /* Always start with root. */
-
-       while (*s) {
-               if (*s == '/') {
-                       /* Eat multiple '/' */
-                       while (*s == '/') {
-                               s++;
-                       }
-                       if ((d > destname + 1) && (*s != '\0')) {
-                               if (!start_of_name_component) {
-                                       /*
-                                        * Only write a / if we
-                                        * haven't just written one.
-                                        */
-                                       *d++ = '/';
-                               }
-                       }
-                       start_of_name_component = true;
-                       continue;
-               }
-
-               if (start_of_name_component) {
-                       if ((s[0] == '.') && (s[1] == '.') &&
-                                       (s[2] == '/' || s[2] == '\0')) {
-                               /* Uh oh - "/../" or "/..\0" ! */
-
-                               /* Go past the .. leaving us on the / or '\0' */
-                               s += 2;
-
-                               /* If  we just added a '/' - delete it */
-                               if ((d > destname) && (*(d-1) == '/')) {
-                                       *(d-1) = '\0';
-                                       d--;
-                               }
-
-                               /*
-                                * Are we at the start ?
-                                * Can't go back further if so.
-                                */
-                               if (d <= destname) {
-                                       *d++ = '/'; /* Can't delete root */
-                                       continue;
-                               }
-                               /* Go back one level... */
-                               /*
-                                * Decrement d first as d points to
-                                * the *next* char to write into.
-                                */
-                               for (d--; d > destname; d--) {
-                                       if (*d == '/') {
-                                               break;
-                                       }
-                               }
-
-                               /*
-                                * Are we at the start ?
-                                * Can't go back further if so.
-                                */
-                               if (d <= destname) {
-                                       *d++ = '/'; /* Can't delete root */
-                                       continue;
-                               }
-
-                               /*
-                                * Step forward one to leave the
-                                * last written '/' alone.
-                                */
-                               d++;
-
-                               /*
-                                * We're still at the start of a name
-                                * component, just the previous one.
-                                */
-                               continue;
-                       } else if ((s[0] == '.') &&
-                                       ((s[1] == '\0') || s[1] == '/')) {
-                               /*
-                                * Component of pathname can't be "." only.
-                                * Skip the '.' .
-                                */
-                               if (s[1] == '/') {
-                                       s += 2;
-                               } else {
-                                       s++;
-                               }
-                               continue;
-                       }
-               }
-
-               if (!(*s & 0x80)) {
-                       *d++ = *s++;
-               } else {
-                       size_t siz;
-                       /* Get the size of the next MB character. */
-                       next_codepoint(s,&siz);
-                       switch(siz) {
-                               case 5:
-                                       *d++ = *s++;
-
-                                       FALL_THROUGH;
-                               case 4:
-                                       *d++ = *s++;
-
-                                       FALL_THROUGH;
-                               case 3:
-                                       *d++ = *s++;
-
-                                       FALL_THROUGH;
-                               case 2:
-                                       *d++ = *s++;
-
-                                       FALL_THROUGH;
-                               case 1:
-                                       *d++ = *s++;
-                                       break;
-                               default:
-                                       break;
-                       }
-               }
-               start_of_name_component = false;
-       }
-       *d = '\0';
-
-       /* And must not end in '/' */
-       if (d > destname + 1 && (*(d-1) == '/')) {
-               *(d-1) = '\0';
-       }
-
-       return destname;
-}
-#endif
-
-/*
- * Canonicalizes an absolute path, removing '.' and ".." components
- * and consolitating multiple '/' characters. As this can only be
- * called once widelinks_chdir with an absolute path has been called,
- * we can assert that the start of path must be '/'.
- */
-
 char *canonicalize_absolute_path(TALLOC_CTX *ctx, const char *pathname_in)
 {
        /*