From 3a247bd5cb3f925a04293f3287fa69f6f2498eae Mon Sep 17 00:00:00 2001 From: Juan RP Date: Thu, 2 Aug 2012 12:20:18 +0200 Subject: [PATCH] xbps-{bin,repo}: make sure that user has write permission on {root,meta,cache}dir. Fixes issue #27 --- bin/xbps-bin/main.c | 19 +++++++++++++++++++ bin/xbps-repo/main.c | 14 ++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/bin/xbps-bin/main.c b/bin/xbps-bin/main.c index e8d7be76..d3ad11aa 100644 --- a/bin/xbps-bin/main.c +++ b/bin/xbps-bin/main.c @@ -232,6 +232,25 @@ main(int argc, char **argv) maxcols = get_maxcols(); + /* + * Check that we have write permission on rootdir, metadir and cachedir. + */ + if (((strcasecmp(argv[0], "install") == 0) || + (strcasecmp(argv[0], "update") == 0) || + (strcasecmp(argv[0], "remove") == 0) || + (strcasecmp(argv[0], "dist-upgrade") == 0) || + (strcasecmp(argv[0], "remove-orphans") == 0)) && !dry_run) { + if ((access(xh.rootdir, W_OK) == -1) || + (access(xh.metadir, W_OK) == -1) || + (access(xh.cachedir, W_OK) == -1)) { + xbps_error_printf("xbps-bin: cannot write to " + "rootdir/cachedir/metadir: %s\n", + strerror(errno)); + xbps_end(&xh); + exit(EXIT_FAILURE); + } + } + if (strcasecmp(argv[0], "list") == 0) { /* Lists packages currently registered in database. */ if (argc < 1 || argc > 2) diff --git a/bin/xbps-repo/main.c b/bin/xbps-repo/main.c index 8f3b3064..c2b1713e 100644 --- a/bin/xbps-repo/main.c +++ b/bin/xbps-repo/main.c @@ -151,6 +151,20 @@ main(int argc, char **argv) exit(EXIT_FAILURE); } + /* + * Check that we have write permission on cachedir/metadir. + */ + if ((strcasecmp(argv[0], "sync") == 0) || + (strcasecmp(argv[0], "clean") == 0)) { + if ((access(xh.metadir, W_OK) == -1) || + (access(xh.cachedir, W_OK) == -1)) { + xbps_error_printf("xbps-repo: cannot write to " + "cachedir/metadir: %s\n", strerror(errno)); + xbps_end(&xh); + exit(EXIT_FAILURE); + } + } + if (strcasecmp(argv[0], "list") == 0) { /* Lists all repositories registered in pool. */ if (argc != 1)