| @@ -1,745 +1,751 @@ | | | @@ -1,745 +1,751 @@ |
1 | /* $NetBSD: main.c,v 1.56 2009/10/07 12:53:26 joerg Exp $ */ | | 1 | /* $NetBSD: main.c,v 1.57 2009/10/08 16:16:12 joerg Exp $ */ |
2 | | | 2 | |
3 | #if HAVE_CONFIG_H | | 3 | #if HAVE_CONFIG_H |
4 | #include "config.h" | | 4 | #include "config.h" |
5 | #endif | | 5 | #endif |
6 | #include <nbcompat.h> | | 6 | #include <nbcompat.h> |
7 | #if HAVE_SYS_CDEFS_H | | 7 | #if HAVE_SYS_CDEFS_H |
8 | #include <sys/cdefs.h> | | 8 | #include <sys/cdefs.h> |
9 | #endif | | 9 | #endif |
10 | __RCSID("$NetBSD: main.c,v 1.56 2009/10/07 12:53:26 joerg Exp $"); | | 10 | __RCSID("$NetBSD: main.c,v 1.57 2009/10/08 16:16:12 joerg Exp $"); |
11 | | | 11 | |
12 | /*- | | 12 | /*- |
13 | * Copyright (c) 1999-2009 The NetBSD Foundation, Inc. | | 13 | * Copyright (c) 1999-2009 The NetBSD Foundation, Inc. |
14 | * All rights reserved. | | 14 | * All rights reserved. |
15 | * | | 15 | * |
16 | * This code is derived from software contributed to The NetBSD Foundation | | 16 | * This code is derived from software contributed to The NetBSD Foundation |
17 | * by Hubert Feyrer <hubert@feyrer.de> and | | 17 | * by Hubert Feyrer <hubert@feyrer.de> and |
18 | * by Joerg Sonnenberger <joerg@NetBSD.org>. | | 18 | * by Joerg Sonnenberger <joerg@NetBSD.org>. |
19 | * | | 19 | * |
20 | * Redistribution and use in source and binary forms, with or without | | 20 | * Redistribution and use in source and binary forms, with or without |
21 | * modification, are permitted provided that the following conditions | | 21 | * modification, are permitted provided that the following conditions |
22 | * are met: | | 22 | * are met: |
23 | * 1. Redistributions of source code must retain the above copyright | | 23 | * 1. Redistributions of source code must retain the above copyright |
24 | * notice, this list of conditions and the following disclaimer. | | 24 | * notice, this list of conditions and the following disclaimer. |
25 | * 2. Redistributions in binary form must reproduce the above copyright | | 25 | * 2. Redistributions in binary form must reproduce the above copyright |
26 | * notice, this list of conditions and the following disclaimer in the | | 26 | * notice, this list of conditions and the following disclaimer in the |
27 | * documentation and/or other materials provided with the distribution. | | 27 | * documentation and/or other materials provided with the distribution. |
28 | * | | 28 | * |
29 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | | 29 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
30 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 30 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
31 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 31 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
32 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 32 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
33 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 33 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
34 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 34 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
35 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 35 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
36 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 36 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
37 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 37 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
38 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 38 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
39 | * POSSIBILITY OF SUCH DAMAGE. | | 39 | * POSSIBILITY OF SUCH DAMAGE. |
40 | */ | | 40 | */ |
41 | | | 41 | |
42 | #if HAVE_SYS_TYPES_H | | 42 | #if HAVE_SYS_TYPES_H |
43 | #include <sys/types.h> | | 43 | #include <sys/types.h> |
44 | #endif | | 44 | #endif |
45 | #if HAVE_SYS_STAT_H | | 45 | #if HAVE_SYS_STAT_H |
46 | #include <sys/stat.h> | | 46 | #include <sys/stat.h> |
47 | #endif | | 47 | #endif |
48 | #if HAVE_DIRENT_H | | 48 | #if HAVE_DIRENT_H |
49 | #include <dirent.h> | | 49 | #include <dirent.h> |
50 | #endif | | 50 | #endif |
51 | #if HAVE_ERR_H | | 51 | #if HAVE_ERR_H |
52 | #include <err.h> | | 52 | #include <err.h> |
53 | #endif | | 53 | #endif |
54 | #if HAVE_ERRNO_H | | 54 | #if HAVE_ERRNO_H |
55 | #include <errno.h> | | 55 | #include <errno.h> |
56 | #endif | | 56 | #endif |
57 | #if HAVE_FCNTL_H | | 57 | #if HAVE_FCNTL_H |
58 | #include <fcntl.h> | | 58 | #include <fcntl.h> |
59 | #endif | | 59 | #endif |
60 | #ifndef NETBSD | | 60 | #ifndef NETBSD |
61 | #include <nbcompat/md5.h> | | 61 | #include <nbcompat/md5.h> |
62 | #else | | 62 | #else |
63 | #include <md5.h> | | 63 | #include <md5.h> |
64 | #endif | | 64 | #endif |
65 | #if HAVE_LIMITS_H | | 65 | #if HAVE_LIMITS_H |
66 | #include <limits.h> | | 66 | #include <limits.h> |
67 | #endif | | 67 | #endif |
68 | #if HAVE_STDIO_H | | 68 | #if HAVE_STDIO_H |
69 | #include <stdio.h> | | 69 | #include <stdio.h> |
70 | #endif | | 70 | #endif |
71 | #if HAVE_STRING_H | | 71 | #if HAVE_STRING_H |
72 | #include <string.h> | | 72 | #include <string.h> |
73 | #endif | | 73 | #endif |
74 | | | 74 | |
75 | #ifndef BOOTSTRAP | | 75 | #ifndef BOOTSTRAP |
76 | #include <archive.h> | | 76 | #include <archive.h> |
77 | #include <fetch.h> | | 77 | #include <fetch.h> |
78 | #endif | | 78 | #endif |
79 | | | 79 | |
80 | #include "admin.h" | | 80 | #include "admin.h" |
81 | #include "lib.h" | | 81 | #include "lib.h" |
82 | | | 82 | |
83 | #define DEFAULT_SFX ".t[bg]z" /* default suffix for ls{all,best} */ | | 83 | #define DEFAULT_SFX ".t[bg]z" /* default suffix for ls{all,best} */ |
84 | | | 84 | |
85 | struct pkgdb_count { | | 85 | struct pkgdb_count { |
86 | size_t files; | | 86 | size_t files; |
87 | size_t directories; | | 87 | size_t directories; |
88 | size_t packages; | | 88 | size_t packages; |
89 | }; | | 89 | }; |
90 | | | 90 | |
91 | static const char Options[] = "C:K:SVbd:qs:v"; | | 91 | static const char Options[] = "C:K:SVbd:qs:v"; |
92 | | | 92 | |
93 | int quiet, verbose; | | 93 | int quiet, verbose; |
94 | | | 94 | |
95 | static void set_unset_variable(char **, Boolean); | | 95 | static void set_unset_variable(char **, Boolean); |
96 | | | 96 | |
97 | /* print usage message and exit */ | | 97 | /* print usage message and exit */ |
98 | void | | 98 | void |
99 | usage(void) | | 99 | usage(void) |
100 | { | | 100 | { |
101 | (void) fprintf(stderr, "usage: %s [-bqSVv] [-C config] [-d lsdir] [-K pkg_dbdir] [-s sfx] command [args ...]\n" | | 101 | (void) fprintf(stderr, "usage: %s [-bqSVv] [-C config] [-d lsdir] [-K pkg_dbdir] [-s sfx] command [args ...]\n" |
102 | "Where 'commands' and 'args' are:\n" | | 102 | "Where 'commands' and 'args' are:\n" |
103 | " rebuild - rebuild pkgdb from +CONTENTS files\n" | | 103 | " rebuild - rebuild pkgdb from +CONTENTS files\n" |
104 | " rebuild-tree - rebuild +REQUIRED_BY files from forward deps\n" | | 104 | " rebuild-tree - rebuild +REQUIRED_BY files from forward deps\n" |
105 | " check [pkg ...] - check md5 checksum of installed files\n" | | 105 | " check [pkg ...] - check md5 checksum of installed files\n" |
106 | " add pkg ... - add pkg files to database\n" | | 106 | " add pkg ... - add pkg files to database\n" |
107 | " delete pkg ... - delete file entries for pkg in database\n" | | 107 | " delete pkg ... - delete file entries for pkg in database\n" |
108 | " set variable=value pkg ... - set installation variable for package\n" | | 108 | " set variable=value pkg ... - set installation variable for package\n" |
109 | " unset variable pkg ... - unset installation variable for package\n" | | 109 | " unset variable pkg ... - unset installation variable for package\n" |
110 | " lsall /path/to/pkgpattern - list all pkgs matching the pattern\n" | | 110 | " lsall /path/to/pkgpattern - list all pkgs matching the pattern\n" |
111 | " lsbest /path/to/pkgpattern - list pkgs matching the pattern best\n" | | 111 | " lsbest /path/to/pkgpattern - list pkgs matching the pattern best\n" |
112 | " dump - dump database\n" | | 112 | " dump - dump database\n" |
113 | " pmatch pattern pkg - returns true if pkg matches pattern, otherwise false\n" | | 113 | " pmatch pattern pkg - returns true if pkg matches pattern, otherwise false\n" |
114 | " fetch-pkg-vulnerabilities [-s] - fetch new vulnerability file\n" | | 114 | " fetch-pkg-vulnerabilities [-s] - fetch new vulnerability file\n" |
115 | " check-pkg-vulnerabilities [-s] <file> - check syntax and checksums of the vulnerability file\n" | | 115 | " check-pkg-vulnerabilities [-s] <file> - check syntax and checksums of the vulnerability file\n" |
116 | " audit [-es] [-t type] ... - check installed packages for vulnerabilities\n" | | 116 | " audit [-es] [-t type] ... - check installed packages for vulnerabilities\n" |
117 | " audit-pkg [-es] [-t type] ... - check listed packages for vulnerabilities\n" | | 117 | " audit-pkg [-es] [-t type] ... - check listed packages for vulnerabilities\n" |
118 | " audit-batch [-es] [-t type] ... - check packages in listed files for vulnerabilities\n" | | 118 | " audit-batch [-es] [-t type] ... - check packages in listed files for vulnerabilities\n" |
119 | " audit-history [-t type] ... - print all advisories for package names\n" | | 119 | " audit-history [-t type] ... - print all advisories for package names\n" |
120 | " check-license <condition> - check if condition is acceptable\n" | | 120 | " check-license <condition> - check if condition is acceptable\n" |
121 | " check-single-license <license> - check if license is acceptable\n" | | 121 | " check-single-license <license> - check if license is acceptable\n" |
122 | " config-var name - print current value of the configuration variable\n" | | 122 | " config-var name - print current value of the configuration variable\n" |
123 | " check-signature ... - verify the signature of packages\n" | | 123 | " check-signature ... - verify the signature of packages\n" |
124 | " x509-sign-package pkg spkg key cert - create X509 signature\n" | | 124 | " x509-sign-package pkg spkg key cert - create X509 signature\n" |
125 | " gpg-sign-package pkg spkg - create GPG signature\n", | | 125 | " gpg-sign-package pkg spkg - create GPG signature\n", |
126 | getprogname()); | | 126 | getprogname()); |
127 | exit(EXIT_FAILURE); | | 127 | exit(EXIT_FAILURE); |
128 | } | | 128 | } |
129 | | | 129 | |
130 | /* | | 130 | /* |
131 | * add1pkg(<pkg>) | | 131 | * add1pkg(<pkg>) |
132 | * adds the files listed in the +CONTENTS of <pkg> into the | | 132 | * adds the files listed in the +CONTENTS of <pkg> into the |
133 | * pkgdb.byfile.db database file in the current package dbdir. It | | 133 | * pkgdb.byfile.db database file in the current package dbdir. It |
134 | * returns the number of files added to the database file. | | 134 | * returns the number of files added to the database file. |
135 | */ | | 135 | */ |
136 | static int | | 136 | static int |
137 | add_pkg(const char *pkgdir, void *vp) | | 137 | add_pkg(const char *pkgdir, void *vp) |
138 | { | | 138 | { |
139 | FILE *f; | | 139 | FILE *f; |
140 | plist_t *p; | | 140 | plist_t *p; |
141 | package_t Plist; | | 141 | package_t Plist; |
142 | char *contents; | | 142 | char *contents; |
143 | const char *PkgDBDir; | | 143 | const char *PkgDBDir; |
144 | char *PkgName, *dirp; | | 144 | char *PkgName, *dirp; |
145 | char file[MaxPathSize]; | | 145 | char file[MaxPathSize]; |
146 | char dir[MaxPathSize]; | | 146 | char dir[MaxPathSize]; |
147 | struct pkgdb_count *count; | | 147 | struct pkgdb_count *count; |
148 | | | 148 | |
149 | if (!pkgdb_open(ReadWrite)) | | 149 | if (!pkgdb_open(ReadWrite)) |
150 | err(EXIT_FAILURE, "cannot open pkgdb"); | | 150 | err(EXIT_FAILURE, "cannot open pkgdb"); |
151 | | | 151 | |
152 | count = vp; | | 152 | count = vp; |
153 | ++count->packages; | | 153 | ++count->packages; |
154 | | | 154 | |
155 | PkgDBDir = _pkgdb_getPKGDB_DIR(); | | 155 | PkgDBDir = _pkgdb_getPKGDB_DIR(); |
156 | contents = pkgdb_pkg_file(pkgdir, CONTENTS_FNAME); | | 156 | contents = pkgdb_pkg_file(pkgdir, CONTENTS_FNAME); |
157 | if ((f = fopen(contents, "r")) == NULL) | | 157 | if ((f = fopen(contents, "r")) == NULL) |
158 | errx(EXIT_FAILURE, "%s: can't open `%s'", pkgdir, CONTENTS_FNAME); | | 158 | errx(EXIT_FAILURE, "%s: can't open `%s'", pkgdir, CONTENTS_FNAME); |
159 | free(contents); | | 159 | free(contents); |
160 | | | 160 | |
161 | read_plist(&Plist, f); | | 161 | read_plist(&Plist, f); |
162 | if ((p = find_plist(&Plist, PLIST_NAME)) == NULL) { | | 162 | if ((p = find_plist(&Plist, PLIST_NAME)) == NULL) { |
163 | errx(EXIT_FAILURE, "Package `%s' has no @name, aborting.", pkgdir); | | 163 | errx(EXIT_FAILURE, "Package `%s' has no @name, aborting.", pkgdir); |
164 | } | | 164 | } |
165 | | | 165 | |
166 | PkgName = p->name; | | 166 | PkgName = p->name; |
167 | dirp = NULL; | | 167 | dirp = NULL; |
168 | for (p = Plist.head; p; p = p->next) { | | 168 | for (p = Plist.head; p; p = p->next) { |
169 | switch(p->type) { | | 169 | switch(p->type) { |
170 | case PLIST_FILE: | | 170 | case PLIST_FILE: |
171 | if (dirp == NULL) { | | 171 | if (dirp == NULL) { |
172 | errx(EXIT_FAILURE, "@cwd not yet found, please send-pr!"); | | 172 | errx(EXIT_FAILURE, "@cwd not yet found, please send-pr!"); |
173 | } | | 173 | } |
174 | (void) snprintf(file, sizeof(file), "%s/%s", dirp, p->name); | | 174 | (void) snprintf(file, sizeof(file), "%s/%s", dirp, p->name); |
175 | if (!(isfile(file) || islinktodir(file))) { | | 175 | if (!(isfile(file) || islinktodir(file))) { |
176 | if (isbrokenlink(file)) { | | 176 | if (isbrokenlink(file)) { |
177 | warnx("%s: Symlink `%s' exists and is in %s but target does not exist!", | | 177 | warnx("%s: Symlink `%s' exists and is in %s but target does not exist!", |
178 | PkgName, file, CONTENTS_FNAME); | | 178 | PkgName, file, CONTENTS_FNAME); |
179 | } else { | | 179 | } else { |
180 | warnx("%s: File `%s' is in %s but not on filesystem!", | | 180 | warnx("%s: File `%s' is in %s but not on filesystem!", |
181 | PkgName, file, CONTENTS_FNAME); | | 181 | PkgName, file, CONTENTS_FNAME); |
182 | } | | 182 | } |
183 | } else { | | 183 | } else { |
184 | pkgdb_store(file, PkgName); | | 184 | pkgdb_store(file, PkgName); |
185 | ++count->files; | | 185 | ++count->files; |
186 | } | | 186 | } |
187 | break; | | 187 | break; |
188 | case PLIST_PKGDIR: | | 188 | case PLIST_PKGDIR: |
189 | add_pkgdir(PkgName, dirp, p->name); | | 189 | add_pkgdir(PkgName, dirp, p->name); |
190 | ++count->directories; | | 190 | ++count->directories; |
191 | break; | | 191 | break; |
192 | case PLIST_CWD: | | 192 | case PLIST_CWD: |
193 | if (strcmp(p->name, ".") != 0) { | | 193 | if (strcmp(p->name, ".") != 0) { |
194 | dirp = p->name; | | 194 | dirp = p->name; |
195 | } else { | | 195 | } else { |
196 | (void) snprintf(dir, sizeof(dir), "%s/%s", PkgDBDir, pkgdir); | | 196 | (void) snprintf(dir, sizeof(dir), "%s/%s", PkgDBDir, pkgdir); |
197 | dirp = dir; | | 197 | dirp = dir; |
198 | } | | 198 | } |
199 | break; | | 199 | break; |
200 | case PLIST_IGNORE: | | 200 | case PLIST_IGNORE: |
201 | p = p->next; | | 201 | p = p->next; |
202 | break; | | 202 | break; |
203 | case PLIST_SHOW_ALL: | | 203 | case PLIST_SHOW_ALL: |
204 | case PLIST_SRC: | | 204 | case PLIST_SRC: |
205 | case PLIST_CMD: | | 205 | case PLIST_CMD: |
206 | case PLIST_CHMOD: | | 206 | case PLIST_CHMOD: |
207 | case PLIST_CHOWN: | | 207 | case PLIST_CHOWN: |
208 | case PLIST_CHGRP: | | 208 | case PLIST_CHGRP: |
209 | case PLIST_COMMENT: | | 209 | case PLIST_COMMENT: |
210 | case PLIST_NAME: | | 210 | case PLIST_NAME: |
211 | case PLIST_UNEXEC: | | 211 | case PLIST_UNEXEC: |
212 | case PLIST_DISPLAY: | | 212 | case PLIST_DISPLAY: |
213 | case PLIST_PKGDEP: | | 213 | case PLIST_PKGDEP: |
214 | case PLIST_DIR_RM: | | 214 | case PLIST_DIR_RM: |
215 | case PLIST_OPTION: | | 215 | case PLIST_OPTION: |
216 | case PLIST_PKGCFL: | | 216 | case PLIST_PKGCFL: |
217 | case PLIST_BLDDEP: | | 217 | case PLIST_BLDDEP: |
218 | break; | | 218 | break; |
219 | } | | 219 | } |
220 | } | | 220 | } |
221 | free_plist(&Plist); | | 221 | free_plist(&Plist); |
222 | fclose(f); | | 222 | fclose(f); |
223 | pkgdb_close(); | | 223 | pkgdb_close(); |
224 | | | 224 | |
225 | return 0; | | 225 | return 0; |
226 | } | | 226 | } |
227 | | | 227 | |
228 | static void | | 228 | static void |
229 | delete1pkg(const char *pkgdir) | | 229 | delete1pkg(const char *pkgdir) |
230 | { | | 230 | { |
231 | if (!pkgdb_open(ReadWrite)) | | 231 | if (!pkgdb_open(ReadWrite)) |
232 | err(EXIT_FAILURE, "cannot open pkgdb"); | | 232 | err(EXIT_FAILURE, "cannot open pkgdb"); |
233 | (void) pkgdb_remove_pkg(pkgdir); | | 233 | (void) pkgdb_remove_pkg(pkgdir); |
234 | pkgdb_close(); | | 234 | pkgdb_close(); |
235 | } | | 235 | } |
236 | | | 236 | |
237 | static void | | 237 | static void |
238 | rebuild(void) | | 238 | rebuild(void) |
239 | { | | 239 | { |
240 | char cachename[MaxPathSize]; | | 240 | char cachename[MaxPathSize]; |
241 | struct pkgdb_count count; | | 241 | struct pkgdb_count count; |
242 | | | 242 | |
243 | count.files = 0; | | 243 | count.files = 0; |
244 | count.directories = 0; | | 244 | count.directories = 0; |
245 | count.packages = 0; | | 245 | count.packages = 0; |
246 | | | 246 | |
247 | (void) _pkgdb_getPKGDB_FILE(cachename, sizeof(cachename)); | | 247 | (void) _pkgdb_getPKGDB_FILE(cachename, sizeof(cachename)); |
248 | if (unlink(cachename) != 0 && errno != ENOENT) | | 248 | if (unlink(cachename) != 0 && errno != ENOENT) |
249 | err(EXIT_FAILURE, "unlink %s", cachename); | | 249 | err(EXIT_FAILURE, "unlink %s", cachename); |
250 | | | 250 | |
251 | setbuf(stdout, NULL); | | 251 | setbuf(stdout, NULL); |
252 | | | 252 | |
253 | iterate_pkg_db(add_pkg, &count); | | 253 | iterate_pkg_db(add_pkg, &count); |
254 | | | 254 | |
255 | printf("\n"); | | 255 | printf("\n"); |
256 | printf("Stored %zu file%s and %zu explizit director%s" | | 256 | printf("Stored %zu file%s and %zu explicit director%s" |
257 | " from %zu package%s in %s.\n", | | 257 | " from %zu package%s in %s.\n", |
258 | count.files, count.files == 1 ? "" : "s", | | 258 | count.files, count.files == 1 ? "" : "s", |
259 | count.directories, count.directories == 1 ? "y" : "ies", | | 259 | count.directories, count.directories == 1 ? "y" : "ies", |
260 | count.packages, count.packages == 1 ? "" : "s", | | 260 | count.packages, count.packages == 1 ? "" : "s", |
261 | cachename); | | 261 | cachename); |
262 | } | | 262 | } |
263 | | | 263 | |
264 | static int | | 264 | static int |
265 | lspattern(const char *pkg, void *vp) | | 265 | lspattern(const char *pkg, void *vp) |
266 | { | | 266 | { |
267 | const char *dir = vp; | | 267 | const char *dir = vp; |
268 | printf("%s/%s\n", dir, pkg); | | 268 | printf("%s/%s\n", dir, pkg); |
269 | return 0; | | 269 | return 0; |
270 | } | | 270 | } |
271 | | | 271 | |
272 | static int | | 272 | static int |
273 | lsbasepattern(const char *pkg, void *vp) | | 273 | lsbasepattern(const char *pkg, void *vp) |
274 | { | | 274 | { |
275 | puts(pkg); | | 275 | puts(pkg); |
276 | return 0; | | 276 | return 0; |
277 | } | | 277 | } |
278 | | | 278 | |
279 | static int | | 279 | static int |
280 | remove_required_by(const char *pkgname, void *cookie) | | 280 | remove_required_by(const char *pkgname, void *cookie) |
281 | { | | 281 | { |
282 | char *path; | | 282 | char *path; |
283 | | | 283 | |
284 | path = pkgdb_pkg_file(pkgname, REQUIRED_BY_FNAME); | | 284 | path = pkgdb_pkg_file(pkgname, REQUIRED_BY_FNAME); |
285 | | | 285 | |
286 | if (unlink(path) == -1 && errno != ENOENT) | | 286 | if (unlink(path) == -1 && errno != ENOENT) |
287 | err(EXIT_FAILURE, "Cannot remove %s", path); | | 287 | err(EXIT_FAILURE, "Cannot remove %s", path); |
288 | | | 288 | |
289 | free(path); | | 289 | free(path); |
290 | | | 290 | |
291 | return 0; | | 291 | return 0; |
292 | } | | 292 | } |
293 | | | 293 | |
294 | static void | | 294 | static void |
295 | add_required_by(const char *pattern, const char *required_by) | | 295 | add_required_by(const char *pattern, const char *required_by) |
296 | { | | 296 | { |
297 | char *best_installed, *path; | | 297 | char *best_installed, *path; |
298 | int fd; | | 298 | int fd; |
299 | size_t len; | | 299 | size_t len; |
300 | | | 300 | |
301 | best_installed = find_best_matching_installed_pkg(pattern); | | 301 | best_installed = find_best_matching_installed_pkg(pattern); |
302 | if (best_installed == NULL) { | | 302 | if (best_installed == NULL) { |
303 | warnx("Dependency %s of %s unresolved", pattern, required_by); | | 303 | warnx("Dependency %s of %s unresolved", pattern, required_by); |
304 | return; | | 304 | return; |
305 | } | | 305 | } |
306 | | | 306 | |
307 | path = pkgdb_pkg_file(best_installed, REQUIRED_BY_FNAME); | | 307 | path = pkgdb_pkg_file(best_installed, REQUIRED_BY_FNAME); |
308 | free(best_installed); | | 308 | free(best_installed); |
309 | | | 309 | |
310 | if ((fd = open(path, O_WRONLY | O_APPEND | O_CREAT, 0644)) == -1) | | 310 | if ((fd = open(path, O_WRONLY | O_APPEND | O_CREAT, 0644)) == -1) |
311 | errx(EXIT_FAILURE, "Cannot write to %s", path); | | 311 | errx(EXIT_FAILURE, "Cannot write to %s", path); |
312 | free(path); | | 312 | free(path); |
313 | | | 313 | |
314 | len = strlen(required_by); | | 314 | len = strlen(required_by); |
315 | if (write(fd, required_by, len) != (ssize_t)len || | | 315 | if (write(fd, required_by, len) != (ssize_t)len || |
316 | write(fd, "\n", 1) != 1 || | | 316 | write(fd, "\n", 1) != 1 || |
317 | close(fd) == -1) | | 317 | close(fd) == -1) |
318 | errx(EXIT_FAILURE, "Cannot write to %s", path); | | 318 | errx(EXIT_FAILURE, "Cannot write to %s", path); |
319 | } | | 319 | } |
320 | | | 320 | |
321 | | | 321 | |
322 | static int | | 322 | static int |
323 | add_depends_of(const char *pkgname, void *cookie) | | 323 | add_depends_of(const char *pkgname, void *cookie) |
324 | { | | 324 | { |
325 | FILE *fp; | | 325 | FILE *fp; |
326 | plist_t *p; | | 326 | plist_t *p; |
327 | package_t plist; | | 327 | package_t plist; |
328 | char *path; | | 328 | char *path; |
329 | | | 329 | |
330 | path = pkgdb_pkg_file(pkgname, CONTENTS_FNAME); | | 330 | path = pkgdb_pkg_file(pkgname, CONTENTS_FNAME); |
331 | if ((fp = fopen(path, "r")) == NULL) | | 331 | if ((fp = fopen(path, "r")) == NULL) |
332 | errx(EXIT_FAILURE, "Cannot read %s of package %s", | | 332 | errx(EXIT_FAILURE, "Cannot read %s of package %s", |
333 | CONTENTS_FNAME, pkgname); | | 333 | CONTENTS_FNAME, pkgname); |
334 | free(path); | | 334 | free(path); |
335 | read_plist(&plist, fp); | | 335 | read_plist(&plist, fp); |
336 | fclose(fp); | | 336 | fclose(fp); |
337 | | | 337 | |
338 | for (p = plist.head; p; p = p->next) { | | 338 | for (p = plist.head; p; p = p->next) { |
339 | if (p->type == PLIST_PKGDEP) | | 339 | if (p->type == PLIST_PKGDEP) |
340 | add_required_by(p->name, pkgname); | | 340 | add_required_by(p->name, pkgname); |
341 | } | | 341 | } |
342 | | | 342 | |
343 | free_plist(&plist); | | 343 | free_plist(&plist); |
344 | | | 344 | |
345 | return 0; | | 345 | return 0; |
346 | } | | 346 | } |
347 | | | 347 | |
348 | static void | | 348 | static void |
349 | rebuild_tree(void) | | 349 | rebuild_tree(void) |
350 | { | | 350 | { |
351 | if (iterate_pkg_db(remove_required_by, NULL) == -1) | | 351 | if (iterate_pkg_db(remove_required_by, NULL) == -1) |
352 | errx(EXIT_FAILURE, "cannot iterate pkgdb"); | | 352 | errx(EXIT_FAILURE, "cannot iterate pkgdb"); |
353 | if (iterate_pkg_db(add_depends_of, NULL) == -1) | | 353 | if (iterate_pkg_db(add_depends_of, NULL) == -1) |
354 | errx(EXIT_FAILURE, "cannot iterate pkgdb"); | | 354 | errx(EXIT_FAILURE, "cannot iterate pkgdb"); |
355 | } | | 355 | } |
356 | | | 356 | |
357 | int | | 357 | int |
358 | main(int argc, char *argv[]) | | 358 | main(int argc, char *argv[]) |
359 | { | | 359 | { |
360 | Boolean use_default_sfx = TRUE; | | 360 | Boolean use_default_sfx = TRUE; |
361 | Boolean show_basename_only = FALSE; | | 361 | Boolean show_basename_only = FALSE; |
362 | char lsdir[MaxPathSize]; | | 362 | char lsdir[MaxPathSize]; |
363 | char sfx[MaxPathSize]; | | 363 | char sfx[MaxPathSize]; |
364 | char *lsdirp = NULL; | | 364 | char *lsdirp = NULL; |
365 | int ch; | | 365 | int ch; |
366 | | | 366 | |
367 | setprogname(argv[0]); | | 367 | setprogname(argv[0]); |
368 | | | 368 | |
369 | if (argc < 2) | | 369 | if (argc < 2) |
370 | usage(); | | 370 | usage(); |
371 | | | 371 | |
372 | while ((ch = getopt(argc, argv, Options)) != -1) | | 372 | while ((ch = getopt(argc, argv, Options)) != -1) |
373 | switch (ch) { | | 373 | switch (ch) { |
374 | case 'C': | | 374 | case 'C': |
375 | config_file = optarg; | | 375 | config_file = optarg; |
376 | break; | | 376 | break; |
377 | | | 377 | |
378 | case 'K': | | 378 | case 'K': |
379 | _pkgdb_setPKGDB_DIR(optarg); | | 379 | _pkgdb_setPKGDB_DIR(optarg); |
380 | break; | | 380 | break; |
381 | | | 381 | |
382 | case 'S': | | 382 | case 'S': |
383 | sfx[0] = 0x0; | | 383 | sfx[0] = 0x0; |
384 | use_default_sfx = FALSE; | | 384 | use_default_sfx = FALSE; |
385 | break; | | 385 | break; |
386 | | | 386 | |
387 | case 'V': | | 387 | case 'V': |
388 | show_version(); | | 388 | show_version(); |
389 | /* NOTREACHED */ | | 389 | /* NOTREACHED */ |
390 | | | 390 | |
391 | case 'b': | | 391 | case 'b': |
392 | show_basename_only = TRUE; | | 392 | show_basename_only = TRUE; |
393 | break; | | 393 | break; |
394 | | | 394 | |
395 | case 'd': | | 395 | case 'd': |
396 | (void) strlcpy(lsdir, optarg, sizeof(lsdir)); | | 396 | (void) strlcpy(lsdir, optarg, sizeof(lsdir)); |
397 | lsdirp = lsdir; | | 397 | lsdirp = lsdir; |
398 | break; | | 398 | break; |
399 | | | 399 | |
400 | case 'q': | | 400 | case 'q': |
401 | quiet = 1; | | 401 | quiet = 1; |
402 | break; | | 402 | break; |
403 | | | 403 | |
404 | case 's': | | 404 | case 's': |
405 | (void) strlcpy(sfx, optarg, sizeof(sfx)); | | 405 | (void) strlcpy(sfx, optarg, sizeof(sfx)); |
406 | use_default_sfx = FALSE; | | 406 | use_default_sfx = FALSE; |
407 | break; | | 407 | break; |
408 | | | 408 | |
409 | case 'v': | | 409 | case 'v': |
410 | ++verbose; | | 410 | ++verbose; |
411 | break; | | 411 | break; |
412 | | | 412 | |
413 | default: | | 413 | default: |
414 | usage(); | | 414 | usage(); |
415 | /* NOTREACHED */ | | 415 | /* NOTREACHED */ |
416 | } | | 416 | } |
417 | | | 417 | |
418 | argc -= optind; | | 418 | argc -= optind; |
419 | argv += optind; | | 419 | argv += optind; |
420 | | | 420 | |
421 | if (argc <= 0) { | | 421 | if (argc <= 0) { |
422 | usage(); | | 422 | usage(); |
423 | } | | 423 | } |
424 | | | 424 | |
425 | pkg_install_config(); | | 425 | pkg_install_config(); |
426 | | | 426 | |
427 | if (use_default_sfx) | | 427 | if (use_default_sfx) |
428 | (void) strlcpy(sfx, DEFAULT_SFX, sizeof(sfx)); | | 428 | (void) strlcpy(sfx, DEFAULT_SFX, sizeof(sfx)); |
429 | | | 429 | |
430 | if (strcasecmp(argv[0], "pmatch") == 0) { | | 430 | if (strcasecmp(argv[0], "pmatch") == 0) { |
431 | | | 431 | |
432 | char *pattern, *pkg; | | 432 | char *pattern, *pkg; |
433 | | | 433 | |
434 | argv++; /* "pmatch" */ | | 434 | argv++; /* "pmatch" */ |
435 | | | 435 | |
436 | if (argv[0] == NULL || argv[1] == NULL) { | | 436 | if (argv[0] == NULL || argv[1] == NULL) { |
437 | usage(); | | 437 | usage(); |
438 | } | | 438 | } |
439 | | | 439 | |
440 | pattern = argv[0]; | | 440 | pattern = argv[0]; |
441 | pkg = argv[1]; | | 441 | pkg = argv[1]; |
442 | | | 442 | |
443 | if (pkg_match(pattern, pkg)){ | | 443 | if (pkg_match(pattern, pkg)){ |
444 | return 0; | | 444 | return 0; |
445 | } else { | | 445 | } else { |
446 | return 1; | | 446 | return 1; |
447 | } | | 447 | } |
448 | | | 448 | |
449 | } else if (strcasecmp(argv[0], "rebuild") == 0) { | | 449 | } else if (strcasecmp(argv[0], "rebuild") == 0) { |
450 | | | 450 | |
451 | rebuild(); | | 451 | rebuild(); |
452 | printf("Done.\n"); | | 452 | printf("Done.\n"); |
453 | | | 453 | |
454 | | | 454 | |
455 | } else if (strcasecmp(argv[0], "rebuild-tree") == 0) { | | 455 | } else if (strcasecmp(argv[0], "rebuild-tree") == 0) { |
456 | | | 456 | |
457 | rebuild_tree(); | | 457 | rebuild_tree(); |
458 | printf("Done.\n"); | | 458 | printf("Done.\n"); |
459 | | | 459 | |
460 | } else if (strcasecmp(argv[0], "check") == 0) { | | 460 | } else if (strcasecmp(argv[0], "check") == 0) { |
461 | argv++; /* "check" */ | | 461 | argv++; /* "check" */ |
462 | | | 462 | |
463 | check(argv); | | 463 | check(argv); |
464 | | | 464 | |
465 | if (!quiet) { | | 465 | if (!quiet) { |
466 | printf("Done.\n"); | | 466 | printf("Done.\n"); |
467 | } | | 467 | } |
468 | | | 468 | |
469 | } else if (strcasecmp(argv[0], "lsall") == 0) { | | 469 | } else if (strcasecmp(argv[0], "lsall") == 0) { |
470 | argv++; /* "lsall" */ | | 470 | argv++; /* "lsall" */ |
471 | | | 471 | |
472 | while (*argv != NULL) { | | 472 | while (*argv != NULL) { |
473 | /* args specified */ | | 473 | /* args specified */ |
474 | int rc; | | 474 | int rc; |
475 | const char *basep, *dir; | | 475 | const char *basep, *dir; |
476 | | | 476 | |
477 | dir = lsdirp ? lsdirp : dirname_of(*argv); | | 477 | dir = lsdirp ? lsdirp : dirname_of(*argv); |
478 | basep = basename_of(*argv); | | 478 | basep = basename_of(*argv); |
479 | | | 479 | |
480 | if (show_basename_only) | | 480 | if (show_basename_only) |
481 | rc = match_local_files(dir, use_default_sfx, 1, basep, lsbasepattern, NULL); | | 481 | rc = match_local_files(dir, use_default_sfx, 1, basep, lsbasepattern, NULL); |
482 | else | | 482 | else |
483 | rc = match_local_files(dir, use_default_sfx, 1, basep, lspattern, __UNCONST(dir)); | | 483 | rc = match_local_files(dir, use_default_sfx, 1, basep, lspattern, __UNCONST(dir)); |
484 | if (rc == -1) | | 484 | if (rc == -1) |
485 | errx(EXIT_FAILURE, "Error from match_local_files(\"%s\", \"%s\", ...)", | | 485 | errx(EXIT_FAILURE, "Error from match_local_files(\"%s\", \"%s\", ...)", |
486 | dir, basep); | | 486 | dir, basep); |
487 | | | 487 | |
488 | argv++; | | 488 | argv++; |
489 | } | | 489 | } |
490 | | | 490 | |
491 | } else if (strcasecmp(argv[0], "lsbest") == 0) { | | 491 | } else if (strcasecmp(argv[0], "lsbest") == 0) { |
492 | argv++; /* "lsbest" */ | | 492 | argv++; /* "lsbest" */ |
493 | | | 493 | |
494 | while (*argv != NULL) { | | 494 | while (*argv != NULL) { |
495 | /* args specified */ | | 495 | /* args specified */ |
496 | const char *basep, *dir; | | 496 | const char *basep, *dir; |
497 | char *p; | | 497 | char *p; |
498 | | | 498 | |
499 | dir = lsdirp ? lsdirp : dirname_of(*argv); | | 499 | dir = lsdirp ? lsdirp : dirname_of(*argv); |
500 | basep = basename_of(*argv); | | 500 | basep = basename_of(*argv); |
501 | | | 501 | |
502 | p = find_best_matching_file(dir, basep, use_default_sfx, 1); | | 502 | p = find_best_matching_file(dir, basep, use_default_sfx, 1); |
503 | | | 503 | |
504 | if (p) { | | 504 | if (p) { |
505 | if (show_basename_only) | | 505 | if (show_basename_only) |
506 | printf("%s\n", p); | | 506 | printf("%s\n", p); |
507 | else | | 507 | else |
508 | printf("%s/%s\n", dir, p); | | 508 | printf("%s/%s\n", dir, p); |
509 | free(p); | | 509 | free(p); |
510 | } | | 510 | } |
511 | | | 511 | |
512 | argv++; | | 512 | argv++; |
513 | } | | 513 | } |
514 | } else if (strcasecmp(argv[0], "list") == 0 || | | 514 | } else if (strcasecmp(argv[0], "list") == 0 || |
515 | strcasecmp(argv[0], "dump") == 0) { | | 515 | strcasecmp(argv[0], "dump") == 0) { |
516 | | | 516 | |
517 | pkgdb_dump(); | | 517 | pkgdb_dump(); |
518 | | | 518 | |
519 | } else if (strcasecmp(argv[0], "add") == 0) { | | 519 | } else if (strcasecmp(argv[0], "add") == 0) { |
| | | 520 | struct pkgdb_count count; |
| | | 521 | |
| | | 522 | count.files = 0; |
| | | 523 | count.directories = 0; |
| | | 524 | count.packages = 0; |
| | | 525 | |
520 | for (++argv; *argv != NULL; ++argv) | | 526 | for (++argv; *argv != NULL; ++argv) |
521 | add_pkg(*argv, NULL); | | 527 | add_pkg(*argv, &count); |
522 | } else if (strcasecmp(argv[0], "delete") == 0) { | | 528 | } else if (strcasecmp(argv[0], "delete") == 0) { |
523 | argv++; /* "delete" */ | | 529 | argv++; /* "delete" */ |
524 | while (*argv != NULL) { | | 530 | while (*argv != NULL) { |
525 | delete1pkg(*argv); | | 531 | delete1pkg(*argv); |
526 | argv++; | | 532 | argv++; |
527 | } | | 533 | } |
528 | } else if (strcasecmp(argv[0], "set") == 0) { | | 534 | } else if (strcasecmp(argv[0], "set") == 0) { |
529 | argv++; /* "set" */ | | 535 | argv++; /* "set" */ |
530 | set_unset_variable(argv, FALSE); | | 536 | set_unset_variable(argv, FALSE); |
531 | } else if (strcasecmp(argv[0], "unset") == 0) { | | 537 | } else if (strcasecmp(argv[0], "unset") == 0) { |
532 | argv++; /* "unset" */ | | 538 | argv++; /* "unset" */ |
533 | set_unset_variable(argv, TRUE); | | 539 | set_unset_variable(argv, TRUE); |
534 | } else if (strcasecmp(argv[0], "config-var") == 0) { | | 540 | } else if (strcasecmp(argv[0], "config-var") == 0) { |
535 | argv++; | | 541 | argv++; |
536 | if (argv == NULL || argv[1] != NULL) | | 542 | if (argv == NULL || argv[1] != NULL) |
537 | errx(EXIT_FAILURE, "config-var takes exactly one argument"); | | 543 | errx(EXIT_FAILURE, "config-var takes exactly one argument"); |
538 | pkg_install_show_variable(argv[0]); | | 544 | pkg_install_show_variable(argv[0]); |
539 | } else if (strcasecmp(argv[0], "check-license") == 0) { | | 545 | } else if (strcasecmp(argv[0], "check-license") == 0) { |
540 | if (argv[1] == NULL) | | 546 | if (argv[1] == NULL) |
541 | errx(EXIT_FAILURE, "check-license takes exactly one argument"); | | 547 | errx(EXIT_FAILURE, "check-license takes exactly one argument"); |
542 | | | 548 | |
543 | load_license_lists(); | | 549 | load_license_lists(); |
544 | | | 550 | |
545 | switch (acceptable_pkg_license(argv[1])) { | | 551 | switch (acceptable_pkg_license(argv[1])) { |
546 | case 0: | | 552 | case 0: |
547 | puts("no"); | | 553 | puts("no"); |
548 | return 0; | | 554 | return 0; |
549 | case 1: | | 555 | case 1: |
550 | puts("yes"); | | 556 | puts("yes"); |
551 | return 0; | | 557 | return 0; |
552 | case -1: | | 558 | case -1: |
553 | errx(EXIT_FAILURE, "invalid license condition"); | | 559 | errx(EXIT_FAILURE, "invalid license condition"); |
554 | } | | 560 | } |
555 | } else if (strcasecmp(argv[0], "check-single-license") == 0) { | | 561 | } else if (strcasecmp(argv[0], "check-single-license") == 0) { |
556 | if (argv[1] == NULL) | | 562 | if (argv[1] == NULL) |
557 | errx(EXIT_FAILURE, "check-license takes exactly one argument"); | | 563 | errx(EXIT_FAILURE, "check-license takes exactly one argument"); |
558 | load_license_lists(); | | 564 | load_license_lists(); |
559 | | | 565 | |
560 | switch (acceptable_license(argv[1])) { | | 566 | switch (acceptable_license(argv[1])) { |
561 | case 0: | | 567 | case 0: |
562 | puts("no"); | | 568 | puts("no"); |
563 | return 0; | | 569 | return 0; |
564 | case 1: | | 570 | case 1: |
565 | puts("yes"); | | 571 | puts("yes"); |
566 | return 0; | | 572 | return 0; |
567 | case -1: | | 573 | case -1: |
568 | errx(EXIT_FAILURE, "invalid license"); | | 574 | errx(EXIT_FAILURE, "invalid license"); |
569 | } | | 575 | } |
570 | } | | 576 | } |
571 | #ifndef BOOTSTRAP | | 577 | #ifndef BOOTSTRAP |
572 | else if (strcasecmp(argv[0], "findbest") == 0) { | | 578 | else if (strcasecmp(argv[0], "findbest") == 0) { |
573 | struct url *url; | | 579 | struct url *url; |
574 | char *output; | | 580 | char *output; |
575 | int rc; | | 581 | int rc; |
576 | | | 582 | |
577 | process_pkg_path(); | | 583 | process_pkg_path(); |
578 | | | 584 | |
579 | rc = 0; | | 585 | rc = 0; |
580 | for (++argv; *argv != NULL; ++argv) { | | 586 | for (++argv; *argv != NULL; ++argv) { |
581 | url = find_best_package(NULL, *argv, 1); | | 587 | url = find_best_package(NULL, *argv, 1); |
582 | if (url == NULL) { | | 588 | if (url == NULL) { |
583 | rc = 1; | | 589 | rc = 1; |
584 | continue; | | 590 | continue; |
585 | } | | 591 | } |
586 | output = fetchStringifyURL(url); | | 592 | output = fetchStringifyURL(url); |
587 | puts(output); | | 593 | puts(output); |
588 | fetchFreeURL(url); | | 594 | fetchFreeURL(url); |
589 | free(output); | | 595 | free(output); |
590 | } | | 596 | } |
591 | | | 597 | |
592 | return rc; | | 598 | return rc; |
593 | } else if (strcasecmp(argv[0], "fetch-pkg-vulnerabilities") == 0) { | | 599 | } else if (strcasecmp(argv[0], "fetch-pkg-vulnerabilities") == 0) { |
594 | fetch_pkg_vulnerabilities(--argc, ++argv); | | 600 | fetch_pkg_vulnerabilities(--argc, ++argv); |
595 | } else if (strcasecmp(argv[0], "check-pkg-vulnerabilities") == 0) { | | 601 | } else if (strcasecmp(argv[0], "check-pkg-vulnerabilities") == 0) { |
596 | check_pkg_vulnerabilities(--argc, ++argv); | | 602 | check_pkg_vulnerabilities(--argc, ++argv); |
597 | } else if (strcasecmp(argv[0], "audit") == 0) { | | 603 | } else if (strcasecmp(argv[0], "audit") == 0) { |
598 | audit_pkgdb(--argc, ++argv); | | 604 | audit_pkgdb(--argc, ++argv); |
599 | } else if (strcasecmp(argv[0], "audit-pkg") == 0) { | | 605 | } else if (strcasecmp(argv[0], "audit-pkg") == 0) { |
600 | audit_pkg(--argc, ++argv); | | 606 | audit_pkg(--argc, ++argv); |
601 | } else if (strcasecmp(argv[0], "audit-batch") == 0) { | | 607 | } else if (strcasecmp(argv[0], "audit-batch") == 0) { |
602 | audit_batch(--argc, ++argv); | | 608 | audit_batch(--argc, ++argv); |
603 | } else if (strcasecmp(argv[0], "audit-history") == 0) { | | 609 | } else if (strcasecmp(argv[0], "audit-history") == 0) { |
604 | audit_history(--argc, ++argv); | | 610 | audit_history(--argc, ++argv); |
605 | } else if (strcasecmp(argv[0], "check-signature") == 0) { | | 611 | } else if (strcasecmp(argv[0], "check-signature") == 0) { |
606 | struct archive *pkg; | | 612 | struct archive *pkg; |
607 | int rc; | | 613 | int rc; |
608 | | | 614 | |
609 | rc = 0; | | 615 | rc = 0; |
610 | for (--argc, ++argv; argc > 0; --argc, ++argv) { | | 616 | for (--argc, ++argv; argc > 0; --argc, ++argv) { |
611 | pkg = open_archive(*argv); | | 617 | pkg = open_archive(*argv); |
612 | if (pkg == NULL) { | | 618 | if (pkg == NULL) { |
613 | warnx("%s could not be opened", *argv); | | 619 | warnx("%s could not be opened", *argv); |
614 | continue; | | 620 | continue; |
615 | } | | 621 | } |
616 | if (pkg_full_signature_check(&pkg)) | | 622 | if (pkg_full_signature_check(&pkg)) |
617 | rc = 1; | | 623 | rc = 1; |
618 | if (!pkg) | | 624 | if (!pkg) |
619 | archive_read_finish(pkg); | | 625 | archive_read_finish(pkg); |
620 | } | | 626 | } |
621 | return rc; | | 627 | return rc; |
622 | } else if (strcasecmp(argv[0], "x509-sign-package") == 0) { | | 628 | } else if (strcasecmp(argv[0], "x509-sign-package") == 0) { |
623 | #ifdef HAVE_SSL | | 629 | #ifdef HAVE_SSL |
624 | --argc; | | 630 | --argc; |
625 | ++argv; | | 631 | ++argv; |
626 | if (argc != 4) | | 632 | if (argc != 4) |
627 | errx(EXIT_FAILURE, "x509-sign-package takes exactly four arguments"); | | 633 | errx(EXIT_FAILURE, "x509-sign-package takes exactly four arguments"); |
628 | pkg_sign_x509(argv[0], argv[1], argv[2], argv[3]); | | 634 | pkg_sign_x509(argv[0], argv[1], argv[2], argv[3]); |
629 | #else | | 635 | #else |
630 | errx(EXIT_FAILURE, "OpenSSL support is not included"); | | 636 | errx(EXIT_FAILURE, "OpenSSL support is not included"); |
631 | #endif | | 637 | #endif |
632 | } else if (strcasecmp(argv[0], "gpg-sign-package") == 0) { | | 638 | } else if (strcasecmp(argv[0], "gpg-sign-package") == 0) { |
633 | --argc; | | 639 | --argc; |
634 | ++argv; | | 640 | ++argv; |
635 | if (argc != 2) | | 641 | if (argc != 2) |
636 | errx(EXIT_FAILURE, "gpg-sign-package takes exactly two arguments"); | | 642 | errx(EXIT_FAILURE, "gpg-sign-package takes exactly two arguments"); |
637 | pkg_sign_gpg(argv[0], argv[1]); | | 643 | pkg_sign_gpg(argv[0], argv[1]); |
638 | } | | 644 | } |
639 | #endif | | 645 | #endif |
640 | else { | | 646 | else { |
641 | usage(); | | 647 | usage(); |
642 | } | | 648 | } |
643 | | | 649 | |
644 | return 0; | | 650 | return 0; |
645 | } | | 651 | } |
646 | | | 652 | |
647 | struct set_installed_info_arg { | | 653 | struct set_installed_info_arg { |
648 | char *variable; | | 654 | char *variable; |
649 | char *value; | | 655 | char *value; |
650 | int got_match; | | 656 | int got_match; |
651 | }; | | 657 | }; |
652 | | | 658 | |
653 | static int | | 659 | static int |
654 | set_installed_info_var(const char *name, void *cookie) | | 660 | set_installed_info_var(const char *name, void *cookie) |
655 | { | | 661 | { |
656 | struct set_installed_info_arg *arg = cookie; | | 662 | struct set_installed_info_arg *arg = cookie; |
657 | char *filename; | | 663 | char *filename; |
658 | int retval; | | 664 | int retval; |
659 | | | 665 | |
660 | filename = pkgdb_pkg_file(name, INSTALLED_INFO_FNAME); | | 666 | filename = pkgdb_pkg_file(name, INSTALLED_INFO_FNAME); |
661 | | | 667 | |
662 | retval = var_set(filename, arg->variable, arg->value); | | 668 | retval = var_set(filename, arg->variable, arg->value); |
663 | | | 669 | |
664 | free(filename); | | 670 | free(filename); |
665 | arg->got_match = 1; | | 671 | arg->got_match = 1; |
666 | | | 672 | |
667 | return retval; | | 673 | return retval; |
668 | } | | 674 | } |
669 | | | 675 | |
670 | static void | | 676 | static void |
671 | set_unset_variable(char **argv, Boolean unset) | | 677 | set_unset_variable(char **argv, Boolean unset) |
672 | { | | 678 | { |
673 | struct set_installed_info_arg arg; | | 679 | struct set_installed_info_arg arg; |
674 | char *eq; | | 680 | char *eq; |
675 | char *variable; | | 681 | char *variable; |
676 | int ret = 0; | | 682 | int ret = 0; |
677 | | | 683 | |
678 | if (argv[0] == NULL || argv[1] == NULL) | | 684 | if (argv[0] == NULL || argv[1] == NULL) |
679 | usage(); | | 685 | usage(); |
680 | | | 686 | |
681 | variable = NULL; | | 687 | variable = NULL; |
682 | | | 688 | |
683 | if (unset) { | | 689 | if (unset) { |
684 | arg.variable = argv[0]; | | 690 | arg.variable = argv[0]; |
685 | arg.value = NULL; | | 691 | arg.value = NULL; |
686 | } else { | | 692 | } else { |
687 | eq = NULL; | | 693 | eq = NULL; |
688 | if ((eq=strchr(argv[0], '=')) == NULL) | | 694 | if ((eq=strchr(argv[0], '=')) == NULL) |
689 | usage(); | | 695 | usage(); |
690 | | | 696 | |
691 | variable = xmalloc(eq-argv[0]+1); | | 697 | variable = xmalloc(eq-argv[0]+1); |
692 | strlcpy(variable, argv[0], eq-argv[0]+1); | | 698 | strlcpy(variable, argv[0], eq-argv[0]+1); |
693 | | | 699 | |
694 | arg.variable = variable; | | 700 | arg.variable = variable; |
695 | arg.value = eq+1; | | 701 | arg.value = eq+1; |
696 | | | 702 | |
697 | if (strcmp(variable, AUTOMATIC_VARNAME) == 0 && | | 703 | if (strcmp(variable, AUTOMATIC_VARNAME) == 0 && |
698 | strcasecmp(arg.value, "yes") != 0 && | | 704 | strcasecmp(arg.value, "yes") != 0 && |
699 | strcasecmp(arg.value, "no") != 0) { | | 705 | strcasecmp(arg.value, "no") != 0) { |
700 | errx(EXIT_FAILURE, | | 706 | errx(EXIT_FAILURE, |
701 | "unknown value `%s' for " AUTOMATIC_VARNAME, | | 707 | "unknown value `%s' for " AUTOMATIC_VARNAME, |
702 | arg.value); | | 708 | arg.value); |
703 | } | | 709 | } |
704 | } | | 710 | } |
705 | if (strpbrk(arg.variable, "ABCDEFGHIJKLMNOPQRSTUVWXYZ") != NULL) { | | 711 | if (strpbrk(arg.variable, "ABCDEFGHIJKLMNOPQRSTUVWXYZ") != NULL) { |
706 | free(variable); | | 712 | free(variable); |
707 | errx(EXIT_FAILURE, | | 713 | errx(EXIT_FAILURE, |
708 | "variable name must not contain uppercase letters"); | | 714 | "variable name must not contain uppercase letters"); |
709 | } | | 715 | } |
710 | | | 716 | |
711 | argv++; | | 717 | argv++; |
712 | while (*argv != NULL) { | | 718 | while (*argv != NULL) { |
713 | arg.got_match = 0; | | 719 | arg.got_match = 0; |
714 | if (match_installed_pkgs(*argv, set_installed_info_var, &arg) == -1) | | 720 | if (match_installed_pkgs(*argv, set_installed_info_var, &arg) == -1) |
715 | errx(EXIT_FAILURE, "Cannot process pkdbdb"); | | 721 | errx(EXIT_FAILURE, "Cannot process pkdbdb"); |
716 | if (arg.got_match == 0) { | | 722 | if (arg.got_match == 0) { |
717 | char *pattern; | | 723 | char *pattern; |
718 | | | 724 | |
719 | if (ispkgpattern(*argv)) { | | 725 | if (ispkgpattern(*argv)) { |
720 | warnx("no matching pkg for `%s'", *argv); | | 726 | warnx("no matching pkg for `%s'", *argv); |
721 | ret++; | | 727 | ret++; |
722 | } else { | | 728 | } else { |
723 | pattern = xasprintf("%s-[0-9]*", *argv); | | 729 | pattern = xasprintf("%s-[0-9]*", *argv); |
724 | | | 730 | |
725 | if (match_installed_pkgs(pattern, set_installed_info_var, &arg) == -1) | | 731 | if (match_installed_pkgs(pattern, set_installed_info_var, &arg) == -1) |
726 | errx(EXIT_FAILURE, "Cannot process pkdbdb"); | | 732 | errx(EXIT_FAILURE, "Cannot process pkdbdb"); |
727 | | | 733 | |
728 | if (arg.got_match == 0) { | | 734 | if (arg.got_match == 0) { |
729 | warnx("cannot find package %s", *argv); | | 735 | warnx("cannot find package %s", *argv); |
730 | ++ret; | | 736 | ++ret; |
731 | } | | 737 | } |
732 | free(pattern); | | 738 | free(pattern); |
733 | } | | 739 | } |
734 | } | | 740 | } |
735 | | | 741 | |
736 | argv++; | | 742 | argv++; |
737 | } | | 743 | } |
738 | | | 744 | |
739 | if (ret > 0) | | 745 | if (ret > 0) |
740 | exit(EXIT_FAILURE); | | 746 | exit(EXIT_FAILURE); |
741 | | | 747 | |
742 | free(variable); | | 748 | free(variable); |
743 | | | 749 | |
744 | return; | | 750 | return; |
745 | } | | 751 | } |