From cdb46ef3fa6d2bea95ae45b8b807497982b18fd5 Mon Sep 17 00:00:00 2001 From: Aaron Griffin Date: Sun, 4 Mar 2007 09:08:54 +0000 Subject: * Fixed a whole mess of extra '/' pathing issues when a different root is specified * Use db->path when appropriate * Commented out the FAKEROOT checks in libalpm. This should never ever be done. TODO test this quite a bit, as this will never cause the transactions to fail if RW operations are requested... right now it is totally up to the front end to decide when to fail * Use realpath() to canonicalize the root path when specified, so _alpm_makepath() doesn't freak out * Fixed some output/indent of MDFile and SHAFile algorithms * More efficient sprintf() usage in MDFile/SHAFile * Added real error output to _alpm_makepath --- lib/libalpm/handle.c | 57 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 23 deletions(-) (limited to 'lib/libalpm/handle.c') diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c index 5ca8258e..c17d86a5 100644 --- a/lib/libalpm/handle.c +++ b/lib/libalpm/handle.c @@ -56,25 +56,25 @@ pmhandle_t *_alpm_handle_new() #ifndef CYGWIN /* see if we're root or not */ handle->uid = geteuid(); -#ifndef FAKEROOT - if(!handle->uid && getenv("FAKEROOTKEY")) { - /* fakeroot doesn't count, we're non-root */ - handle->uid = 99; - } -#endif - - /* see if we're root or not (fakeroot does not count) */ -#ifndef FAKEROOT - if(handle->uid == 0 && !getenv("FAKEROOTKEY")) { - /* } make vim indent work - stupid ifdef's */ -#else - if(handle->uid == 0) { -#endif - handle->access = PM_ACCESS_RW; - } else { - handle->access = PM_ACCESS_RO; - } -#else +//#ifndef FAKEROOT +// if(!handle->uid && getenv("FAKEROOTKEY")) { +// /* fakeroot doesn't count, we're non-root */ +// handle->uid = 99; +// } +//#endif +// +// /* see if we're root or not (fakeroot does not count) */ +//#ifndef FAKEROOT +// if(handle->uid == 0 && !getenv("FAKEROOTKEY")) { +// /* } make vim indent work - stupid ifdef's */ +//#else +// if(handle->uid == 0) { +//#endif +// handle->access = PM_ACCESS_RW; +// } else { +// handle->access = PM_ACCESS_RO; +// } +//#else handle->access = PM_ACCESS_RW; #endif @@ -152,16 +152,27 @@ void SYMEXPORT alpm_option_set_logmask(unsigned short mask) { handle->logmask = void alpm_option_set_root(const char *root) { if(handle->root) FREE(handle->root); - if(root) { + /* According to the man page, realpath is safe to use IFF the second arg is + * NULL. */ + char *realroot = realpath(root, NULL); + if(!realroot) { + realroot = root; + _alpm_log(PM_LOG_ERROR, _("cannot canonicalize specified root path '%s'"), root); + } + + /* check again, in case both are null */ + if(realroot) { /* verify root ends in a '/' */ - int rootlen = strlen(root); - if(root[rootlen-1] != '/') { + int rootlen = strlen(realroot); + if(realroot[rootlen-1] != '/') { rootlen += 1; } handle->root = calloc(rootlen+1, sizeof(char)); - strncpy(handle->root, root, rootlen); + strncpy(handle->root, realroot, rootlen); handle->root[rootlen-1] = '/'; _alpm_log(PM_LOG_DEBUG, _("option 'root' = %s"), handle->root); + + free(realroot); } } -- cgit v1.2.3-24-g4f1b