* Yavor Doganov <ya...@gnu.org>, 2011-10-21, 13:07:
Package: theunarchiver

When I unpack RAR archives with unar, it creates
$HOME/GNUstep/Library directory:

I wish it didn't clutter my home directory with useless directories...

This directory is not useless, and gnustep-base makes sure to create it as many methods rely on its existence.

Right. I meant that it's useless for me, because unar is the only GNUstep software I use, so the directory is always empty.

The attached patch should do the desired cleanup, but:

- Please test extensively, it is potentially dangerous.
- There could be a race condition in the unlikely case that the same user is running `unar' and another GNUstep program simultaneously.

I took another approach to work around this problem: I created a LD_PRELOAD'able library that overrides the mkdir() function.

I think the same effect could be achieved by linking antignustep.o directly into the unar binary. (Though I know absolutely nothing about Objective-C, so I could be wrong.)

--
Jakub Wilk
/*
 * Copyright © 2011 Jakub Wilk <jw...@debian.org>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the “Software”), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#include <dlfcn.h>
#include <errno.h>
#include <pwd.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

static int done;
static int (*original_mkdir)(const char *, mode_t);

int mkdir(const char *path, mode_t mode)
{
    if (mode != 0777) {
        done = 1;
        return original_mkdir(path, mode);
    }
    if (!done) {
        done = 1;
        /* Don't allow creating the very first directory (which should be
         * $HOME/GNUstep), but only if the call passes sanity checks.
         */
        if (mode == 0777) {
            struct passwd* pw = getpwuid(getuid());
            if (pw == NULL || pw->pw_dir)
                return -1;
            size_t home_len = strlen(pw->pw_dir);
            if (strncmp(path, pw->pw_dir, home_len) == 0 && strcmp(path + home_len, "/GNUstep") == 0) {
                errno = EACCES;
                return -1;
            }
        }
    }
    if (!original_mkdir) {
        original_mkdir = dlsym(RTLD_NEXT, "mkdir");
        if (!original_mkdir) {
            errno = EINVAL;
            return -1;
        }
    }
    return original_mkdir(path, mode);
}

/* vim:set ts=4 sw=4 et:*/

Reply via email to