summaryrefslogtreecommitdiff
path: root/src/pacman
diff options
context:
space:
mode:
Diffstat (limited to 'src/pacman')
-rw-r--r--src/pacman/Makefile2
-rw-r--r--src/pacman/conf.c18
-rw-r--r--src/pacman/db.c103
-rw-r--r--src/pacman/db.h2
-rw-r--r--src/pacman/pacman.c23
-rw-r--r--src/pacman/query.c4
-rw-r--r--src/pacman/sync.c6
-rw-r--r--src/pacman/util.c16
-rw-r--r--src/pacman/util.h1
9 files changed, 127 insertions, 48 deletions
diff --git a/src/pacman/Makefile b/src/pacman/Makefile
index 9aebc67c..a6b6cad2 100644
--- a/src/pacman/Makefile
+++ b/src/pacman/Makefile
@@ -25,7 +25,7 @@ all: pacman
%.o: %.c %.h
$(CC) -c $(CFLAGS) -o $@ $<
-pacman: $(OBJECTS) ../../lib/libalpm/libalpm.a
+pacman: $(OBJECTS) ../../lib/libalpm/libalpm.a ../../lib/libftp/libftp.a
$(CC) $(OBJECTS) -o $@ $(CFLAGS) $(LDFLAGS)
# $(CC) $(OBJECTS) -o $@.static $(CFLAGS) $(LDFLAGS)
diff --git a/src/pacman/conf.c b/src/pacman/conf.c
index 7bf02d03..0aceecf2 100644
--- a/src/pacman/conf.c
+++ b/src/pacman/conf.c
@@ -159,6 +159,24 @@ int parseconfig(char *file)
return(1);
}
vprint("config: noupgrade: %s\n", p);
+ } else if(!strcmp(key, "NOEXTRACT")) {
+ char *p = ptr;
+ char *q;
+ while((q = strchr(p, ' '))) {
+ *q = '\0';
+ if(alpm_set_option(PM_OPT_NOEXTRACT, (long)p) == -1) {
+ ERR(NL, "failed to set option NOEXTRACT (%s)\n", alpm_strerror(pm_errno));
+ return(1);
+ }
+ vprint("config: noextract: %s\n", p);
+ p = q;
+ p++;
+ }
+ if(alpm_set_option(PM_OPT_NOEXTRACT, (long)p) == -1) {
+ ERR(NL, "failed to set option NOEXTRACT (%s)\n", alpm_strerror(pm_errno));
+ return(1);
+ }
+ vprint("config: noextract: %s\n", p);
} else if(!strcmp(key, "IGNOREPKG")) {
char *p = ptr;
char *q;
diff --git a/src/pacman/db.c b/src/pacman/db.c
index e6e17775..a00aaad4 100644
--- a/src/pacman/db.c
+++ b/src/pacman/db.c
@@ -34,63 +34,86 @@
#include "sync.h"
#include "db.h"
-int db_search(PM_DB *db, char *treename, char *needle)
+int db_search(PM_DB *db, const char *treename, list_t *needles)
{
- PM_LIST *lp;
- char *targ;
+ list_t *i;
- targ = strdup(needle);
- strtoupper(targ);
+ if(needles == NULL || needles->data == NULL) {
+ return(0);
+ }
+
+ for(i = needles; i; i = i->next) {
+ PM_LIST *j;
+ char *targ;
+ int ret;
- for(lp = alpm_db_getpkgcache(db); lp; lp = alpm_list_next(lp)) {
- PM_PKG *pkg = alpm_list_getdata(lp);
- char *haystack;
- char *pkgname, *pkgdesc;
- int match = 0;
+ if(i->data == NULL) {
+ continue;
+ }
+ targ = strdup(i->data);
- pkgname = alpm_pkg_getinfo(pkg, PM_PKG_NAME);
- pkgdesc = alpm_pkg_getinfo(pkg, PM_PKG_DESC);
+ for(j = alpm_db_getpkgcache(db); j; j = alpm_list_next(j)) {
+ PM_PKG *pkg = alpm_list_getdata(j);
+ char *haystack;
+ char *pkgname, *pkgdesc;
+ int match = 0;
- /* check name */
- haystack = strdup(pkgname);
- strtoupper(haystack);
- if(strstr(haystack, targ)) {
- match = 1;
- }
- FREE(haystack);
+ pkgname = alpm_pkg_getinfo(pkg, PM_PKG_NAME);
+ pkgdesc = alpm_pkg_getinfo(pkg, PM_PKG_DESC);
- /* check description */
- if(!match) {
- haystack = strdup(pkgdesc);
- strtoupper(haystack);
- if(strstr(haystack, targ)) {
+ /* check name */
+ haystack = strdup(pkgname);
+ ret = reg_match(haystack, targ);
+ if(ret < 0) {
+ /* bad regexp */
+ FREE(haystack);
+ return(1);
+ } else if(ret) {
match = 1;
}
FREE(haystack);
- }
-
- /* check provides */
- if(!match) {
- PM_LIST *m;
- for(m = alpm_pkg_getinfo(pkg, PM_PKG_PROVIDES); m; m = alpm_list_next(m)) {
- haystack = strdup(alpm_list_getdata(m));
- strtoupper(haystack);
- if(strstr(haystack, targ)) {
+ /* check description */
+ if(!match) {
+ haystack = strdup(pkgdesc);
+ ret = reg_match(haystack, targ);
+ if(ret < 0) {
+ /* bad regexp */
+ FREE(haystack);
+ return(1);
+ } else if(ret) {
match = 1;
}
FREE(haystack);
}
- }
- if(match) {
- printf("%s/%s %s\n ", treename, pkgname, (char *)alpm_pkg_getinfo(pkg, PM_PKG_VERSION));
- indentprint(pkgdesc, 4);
- printf("\n");
+ /* check provides */
+ if(!match) {
+ PM_LIST *m;
+
+ for(m = alpm_pkg_getinfo(pkg, PM_PKG_PROVIDES); m; m = alpm_list_next(m)) {
+ haystack = strdup(alpm_list_getdata(m));
+ ret = reg_match(haystack, targ);
+ if(ret < 0) {
+ /* bad regexp */
+ FREE(haystack);
+ return(1);
+ } else if(ret) {
+ match = 1;
+ }
+ FREE(haystack);
+ }
+ }
+
+ if(match) {
+ printf("%s/%s %s\n ", treename, pkgname, (char *)alpm_pkg_getinfo(pkg, PM_PKG_VERSION));
+ indentprint(pkgdesc, 4);
+ printf("\n");
+ }
}
- }
- FREE(targ);
+ FREE(targ);
+ }
return(0);
}
diff --git a/src/pacman/db.h b/src/pacman/db.h
index 7b38719f..d28b0976 100644
--- a/src/pacman/db.h
+++ b/src/pacman/db.h
@@ -21,7 +21,7 @@
#ifndef _PM_DB_H
#define _PM_DB_H
-int db_search(PM_DB *db, char *treename, char *needle);
+int db_search(PM_DB *db, const char *treename, list_t *needles);
#endif /* _PM_DB_H */
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index 89033813..eb5a8da8 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -26,6 +26,7 @@
#include <getopt.h>
#include <string.h>
#include <signal.h>
+#include <unistd.h>
#ifndef CYGWIN
#include <mcheck.h> /* debug */
#else
@@ -96,6 +97,7 @@ int main(int argc, char *argv[])
{
int ret = 0;
char *cenv = NULL;
+ uid_t myuid;
#ifndef CYGWIN
/* debug */
@@ -122,6 +124,27 @@ int main(int argc, char *argv[])
exit(ret);
}
+ /* see if we're root or not */
+ myuid = geteuid();
+ if(!myuid && getenv("FAKEROOTKEY")) {
+ /* fakeroot doesn't count, we're non-root */
+ myuid = 99;
+ }
+
+ /* check if we have sufficient permission for the requested operation */
+ if(myuid > 0) {
+ if(pmo_op != PM_OP_MAIN && pmo_op != PM_OP_QUERY && pmo_op != PM_OP_DEPTEST) {
+ if((pmo_op == PM_OP_SYNC && !pmo_s_sync &&
+ (pmo_s_search || pmo_s_printuris || pmo_group || pmo_q_list ||
+ pmo_q_info)) || (pmo_op == PM_OP_DEPTEST && !pmo_d_resolve)) {
+ /* special case: PM_OP_SYNC can be used w/ pmo_s_search by any user */
+ } else {
+ ERR(NL, "you cannot perform this operation unless you are root.\n");
+ exit(1);
+ }
+ }
+ }
+
if(pmo_root == NULL) {
pmo_root = strdup("/");
}
diff --git a/src/pacman/query.c b/src/pacman/query.c
index 6f4f7c4c..71c02c71 100644
--- a/src/pacman/query.c
+++ b/src/pacman/query.c
@@ -106,8 +106,8 @@ int pacman_query(list_t *targets)
int done = 0;
if(pmo_q_search) {
- for(targ = targets; targ; targ = targ->next) {
- db_search(db_local, "local", targ->data);
+ if(db_search(db_local, "local", targets)) {
+ return(1);
}
return(0);
}
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index 17b9b3a2..4d1c5143 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -219,10 +219,8 @@ static int sync_search(list_t *syncs, list_t *targets)
for(i = syncs; i; i = i->next) {
sync_t *sync = i->data;
if(targets) {
- list_t *j;
-
- for(j = targets; j; j = j->next) {
- db_search(sync->db, sync->treename, j->data);
+ if(db_search(sync->db, sync->treename, targets)) {
+ return(1);
}
} else {
PM_LIST *lp;
diff --git a/src/pacman/util.c b/src/pacman/util.c
index 1d3844a3..5a60070b 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -29,6 +29,7 @@
#include <ctype.h>
#include <dirent.h>
#include <unistd.h>
+#include <regex.h>
#ifdef CYGWIN
#include <limits.h> /* PATH_MAX */
#endif
@@ -224,4 +225,19 @@ int yesno(char *fmt, ...)
return(0);
}
+/* match a string against a regular expression */
+int reg_match(char *string, char *pattern)
+{
+ int result;
+ regex_t reg;
+
+ if(regcomp(&reg, pattern, REG_EXTENDED | REG_NOSUB | REG_ICASE) != 0) {
+ fprintf(stderr, "error: %s is not a valid regular expression.\n", pattern);
+ return(-1);
+ }
+ result = regexec(&reg, string, 0, 0, 0);
+ regfree(&reg);
+ return(!(result));
+}
+
/* vim: set ts=2 sw=2 noet: */
diff --git a/src/pacman/util.h b/src/pacman/util.h
index b181dbd1..755f0b96 100644
--- a/src/pacman/util.h
+++ b/src/pacman/util.h
@@ -34,6 +34,7 @@ void indentprint(char *str, int indent);
char *strtrim(char *str);
char *strtoupper(char *str);
int yesno(char *fmt, ...);
+int reg_match(char *string, char *pattern);
#endif /* _PM_UTIL_H */