Add functions for verifying database signature
[pacman-ng.git] / lib / libalpm / db.c
blob2c9b25f367ee77411650df684e9513c8e11cdf14
1 /*
2 * db.c
4 * Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>
5 * Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
6 * Copyright (c) 2005 by Aurelien Foret <orelien@chez.com>
7 * Copyright (c) 2005 by Christian Hamar <krics@linuxforum.hu>
8 * Copyright (c) 2006 by David Kimpe <dnaku@frugalware.org>
9 * Copyright (c) 2005, 2006 by Miklos Vajna <vmiklos@frugalware.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "config.h"
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <errno.h>
30 #include <string.h>
31 #include <sys/stat.h>
32 #include <regex.h>
33 #include <time.h>
35 /* libalpm */
36 #include "db.h"
37 #include "alpm_list.h"
38 #include "log.h"
39 #include "util.h"
40 #include "handle.h"
41 #include "alpm.h"
42 #include "package.h"
43 #include "group.h"
45 /** \addtogroup alpm_databases Database Functions
46 * @brief Functions to query and manipulate the database of libalpm
47 * @{
50 /** Register a sync database of packages.
51 * @param treename the name of the sync repository
52 * @return a pmdb_t* on success (the value), NULL on error
54 pmdb_t SYMEXPORT *alpm_db_register_sync(const char *treename)
56 ALPM_LOG_FUNC;
58 /* Sanity checks */
59 ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, NULL));
60 ASSERT(treename != NULL && strlen(treename) != 0, RET_ERR(PM_ERR_WRONG_ARGS, NULL));
61 /* Do not register a database if a transaction is on-going */
62 ASSERT(handle->trans == NULL, RET_ERR(PM_ERR_TRANS_NOT_NULL, NULL));
64 return _alpm_db_register_sync(treename);
67 /* Helper function for alpm_db_unregister{_all} */
68 void _alpm_db_unregister(pmdb_t *db)
70 if(db == NULL) {
71 return;
74 _alpm_log(PM_LOG_DEBUG, "unregistering database '%s'\n", db->treename);
75 _alpm_db_free(db);
78 /** Unregister all package databases
79 * @return 0 on success, -1 on error (pm_errno is set accordingly)
81 int SYMEXPORT alpm_db_unregister_all(void)
83 alpm_list_t *i;
84 pmdb_t *db;
86 ALPM_LOG_FUNC;
88 /* Sanity checks */
89 ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
90 /* Do not unregister a database if a transaction is on-going */
91 ASSERT(handle->trans == NULL, RET_ERR(PM_ERR_TRANS_NOT_NULL, -1));
93 /* close local database */
94 db = handle->db_local;
95 if(db) {
96 db->ops->unregister(db);
97 handle->db_local = NULL;
100 /* and also sync ones */
101 for(i = handle->dbs_sync; i; i = i->next) {
102 db = i->data;
103 db->ops->unregister(db);
104 i->data = NULL;
106 FREELIST(handle->dbs_sync);
107 return 0;
110 /** Unregister a package database
111 * @param db pointer to the package database to unregister
112 * @return 0 on success, -1 on error (pm_errno is set accordingly)
114 int SYMEXPORT alpm_db_unregister(pmdb_t *db)
116 int found = 0;
118 ALPM_LOG_FUNC;
120 /* Sanity checks */
121 ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
122 ASSERT(db != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
123 /* Do not unregister a database if a transaction is on-going */
124 ASSERT(handle->trans == NULL, RET_ERR(PM_ERR_TRANS_NOT_NULL, -1));
126 if(db == handle->db_local) {
127 handle->db_local = NULL;
128 found = 1;
129 } else {
130 /* Warning : this function shouldn't be used to unregister all sync
131 * databases by walking through the list returned by
132 * alpm_option_get_syncdbs, because the db is removed from that list here.
134 void *data;
135 handle->dbs_sync = alpm_list_remove(handle->dbs_sync,
136 db, _alpm_db_cmp, &data);
137 if(data) {
138 found = 1;
142 if(!found) {
143 RET_ERR(PM_ERR_DB_NOT_FOUND, -1);
146 db->ops->unregister(db);
147 return 0;
150 /** Set the serverlist of a database.
151 * @param db database pointer
152 * @param url url of the server
153 * @return 0 on success, -1 on error (pm_errno is set accordingly)
155 int SYMEXPORT alpm_db_setserver(pmdb_t *db, const char *url)
157 char *newurl;
158 size_t len = 0;
160 ALPM_LOG_FUNC;
162 /* Sanity checks */
163 ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
165 if(url) {
166 len = strlen(url);
168 if(len) {
169 newurl = strdup(url);
170 /* strip the trailing slash if one exists */
171 if(newurl[len - 1] == '/') {
172 newurl[len - 1] = '\0';
174 db->servers = alpm_list_add(db->servers, newurl);
175 _alpm_log(PM_LOG_DEBUG, "adding new server URL to database '%s': %s\n",
176 db->treename, newurl);
177 } else {
178 FREELIST(db->servers);
179 _alpm_log(PM_LOG_DEBUG, "serverlist flushed for '%s'\n", db->treename);
182 return 0;
184 /** Set the verify gpg signature option for a database.
185 * @param db database pointer
186 * @param verify enum pgp_verify_t
187 * @return 0 on success, -1 on error (pm_errno is set accordingly)
189 int SYMEXPORT alpm_db_set_pgp_verify(pmdb_t *db, pgp_verify_t verify)
191 ALPM_LOG_FUNC;
193 /* Sanity checks */
194 ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
196 db->pgp_verify = verify;
197 _alpm_log(PM_LOG_DEBUG, "adding VerifySig option to database '%s': %d\n",
198 db->treename, verify);
200 return(0);
203 /** Get the name of a package database
204 * @param db pointer to the package database
205 * @return the name of the package database, NULL on error
207 const char SYMEXPORT *alpm_db_get_name(const pmdb_t *db)
209 ALPM_LOG_FUNC;
211 /* Sanity checks */
212 ASSERT(handle != NULL, return NULL);
213 ASSERT(db != NULL, return NULL);
215 return db->treename;
218 /** Get a download URL for the package database
219 * @param db pointer to the package database
220 * @return a fully-specified download URL, NULL on error
222 const char SYMEXPORT *alpm_db_get_url(const pmdb_t *db)
224 char *url;
226 ALPM_LOG_FUNC;
228 /* Sanity checks */
229 ASSERT(handle != NULL, return NULL);
230 ASSERT(db != NULL, return NULL);
231 ASSERT(db->servers != NULL, return NULL);
233 url = (char*)db->servers->data;
235 return url;
239 /** Get a package entry from a package database
240 * @param db pointer to the package database to get the package from
241 * @param name of the package
242 * @return the package entry on success, NULL on error
244 pmpkg_t SYMEXPORT *alpm_db_get_pkg(pmdb_t *db, const char *name)
246 ALPM_LOG_FUNC;
248 /* Sanity checks */
249 ASSERT(handle != NULL, return NULL);
250 ASSERT(db != NULL, return NULL);
251 ASSERT(name != NULL && strlen(name) != 0, return NULL);
253 return _alpm_db_get_pkgfromcache(db, name);
256 /** Get the package cache of a package database
257 * @param db pointer to the package database to get the package from
258 * @return the list of packages on success, NULL on error
260 alpm_list_t SYMEXPORT *alpm_db_get_pkgcache(pmdb_t *db)
262 ALPM_LOG_FUNC;
264 /* Sanity checks */
265 ASSERT(handle != NULL, return NULL);
266 ASSERT(db != NULL, return NULL);
268 return _alpm_db_get_pkgcache(db);
271 /** Get a group entry from a package database
272 * @param db pointer to the package database to get the group from
273 * @param name of the group
274 * @return the groups entry on success, NULL on error
276 pmgrp_t SYMEXPORT *alpm_db_readgrp(pmdb_t *db, const char *name)
278 ALPM_LOG_FUNC;
280 /* Sanity checks */
281 ASSERT(handle != NULL, return NULL);
282 ASSERT(db != NULL, return NULL);
283 ASSERT(name != NULL && strlen(name) != 0, return NULL);
285 return _alpm_db_get_grpfromcache(db, name);
288 /** Get the group cache of a package database
289 * @param db pointer to the package database to get the group from
290 * @return the list of groups on success, NULL on error
292 alpm_list_t SYMEXPORT *alpm_db_get_grpcache(pmdb_t *db)
294 ALPM_LOG_FUNC;
296 /* Sanity checks */
297 ASSERT(handle != NULL, return NULL);
298 ASSERT(db != NULL, return NULL);
300 return _alpm_db_get_grpcache(db);
303 /** Searches a database
304 * @param db pointer to the package database to search in
305 * @param needles the list of strings to search for
306 * @return the list of packages on success, NULL on error
308 alpm_list_t SYMEXPORT *alpm_db_search(pmdb_t *db, const alpm_list_t* needles)
310 ALPM_LOG_FUNC;
312 /* Sanity checks */
313 ASSERT(handle != NULL, return NULL);
314 ASSERT(db != NULL, return NULL);
316 return _alpm_db_search(db, needles);
319 /** Set install reason for a package in db
320 * @param db pointer to the package database
321 * @param name the name of the package
322 * @param reason the new install reason
323 * @return 0 on success, -1 on error (pm_errno is set accordingly)
325 int SYMEXPORT alpm_db_set_pkgreason(pmdb_t *db, const char *name, pmpkgreason_t reason)
327 ALPM_LOG_FUNC;
329 /* Sanity checks */
330 ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
331 ASSERT(db != NULL && name != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
333 pmpkg_t *pkg = _alpm_db_get_pkgfromcache(db, name);
334 if(pkg == NULL) {
335 RET_ERR(PM_ERR_PKG_NOT_FOUND, -1);
338 _alpm_log(PM_LOG_DEBUG, "setting install reason %u for %s/%s\n", reason, db->treename, name);
339 if(alpm_pkg_get_reason(pkg) == reason) {
340 /* we are done */
341 return 0;
343 /* set reason (in pkgcache) */
344 pkg->reason = reason;
345 /* write DESC */
346 if(_alpm_local_db_write(db, pkg, INFRQ_DESC)) {
347 return -1;
350 return 0;
353 /** @} */
355 pmdb_t *_alpm_db_new(const char *treename, int is_local)
357 pmdb_t *db;
359 ALPM_LOG_FUNC;
361 CALLOC(db, 1, sizeof(pmdb_t), RET_ERR(PM_ERR_MEMORY, NULL));
362 STRDUP(db->treename, treename, RET_ERR(PM_ERR_MEMORY, NULL));
363 db->is_local = is_local;
365 return db;
368 static int load_pgpsig(pmdb_t *db) {
369 size_t len;
370 const char *dbfile;
371 char *sigfile;
373 dbfile = _alpm_db_path(db);
374 len = strlen(dbfile) + 5;
375 MALLOC(sigfile, len, RET_ERR(PM_ERR_MEMORY, -1));
376 sprintf(sigfile, "%s.sig", dbfile);
378 if(access(sigfile, R_OK) == 0) {
379 FILE *f;
380 long bytes;
381 size_t bytes_read;
382 f = fopen(sigfile, "rb");
383 fseek(f, 0L, SEEK_END);
384 bytes = ftell(f);
385 if(bytes == -1) {
386 _alpm_log(PM_LOG_WARNING, _("Failed reading PGP signature file for %s"),
387 dbfile);
388 goto cleanup;
390 fseek(f, 0L, SEEK_SET);
391 CALLOC(db->pgpsig.rawdata, bytes, sizeof(char),
392 goto error);
393 bytes_read = fread(db->pgpsig.rawdata, sizeof(char), bytes, f);
394 if(bytes_read == (size_t)bytes) {
395 db->pgpsig.rawlen = bytes;
396 _alpm_log(PM_LOG_DEBUG,
397 "loaded database .sig file, location %s\n", sigfile);
398 } else {
399 _alpm_log(PM_LOG_WARNING, _("Failed reading PGP signature file for %s"),
400 dbfile);
403 cleanup:
404 fclose(f);
405 } else {
406 _alpm_log(PM_LOG_DEBUG, "no database signature file found\n");
409 return(0);
411 error:
412 FREE(db->pgpsig.rawdata);
413 db->pgpsig.rawlen = 0;
414 return(1);
417 const pmpgpsig_t *_alpm_db_pgpsig(pmdb_t *db)
419 ALPM_LOG_FUNC;
421 /* Sanity checks */
422 ASSERT(db != NULL, return(NULL));
424 if(db->pgpsig.rawdata == NULL) {
425 load_pgpsig(db);
428 return &(db->pgpsig);
431 void _alpm_db_free(pmdb_t *db)
433 ALPM_LOG_FUNC;
435 /* cleanup pkgcache */
436 _alpm_db_free_pkgcache(db);
437 /* cleanup server list */
438 FREELIST(db->servers);
439 /* only need to free rawdata */
440 FREE(db->pgpsig.rawdata);
441 FREE(db->_path);
442 FREE(db->treename);
443 FREE(db);
445 return;
448 const char *_alpm_db_path(pmdb_t *db)
450 if(!db) {
451 return NULL;
453 if(!db->_path) {
454 const char *dbpath;
455 size_t pathsize;
457 dbpath = alpm_option_get_dbpath();
458 if(!dbpath) {
459 _alpm_log(PM_LOG_ERROR, _("database path is undefined\n"));
460 RET_ERR(PM_ERR_DB_OPEN, NULL);
463 if(db->is_local) {
464 pathsize = strlen(dbpath) + strlen(db->treename) + 2;
465 CALLOC(db->_path, 1, pathsize, RET_ERR(PM_ERR_MEMORY, NULL));
466 sprintf(db->_path, "%s%s/", dbpath, db->treename);
467 } else {
468 pathsize = strlen(dbpath) + 5 + strlen(db->treename) + 4;
469 CALLOC(db->_path, 1, pathsize, RET_ERR(PM_ERR_MEMORY, NULL));
470 /* all sync DBs now reside in the sync/ subdir of the dbpath */
471 sprintf(db->_path, "%ssync/%s.db", dbpath, db->treename);
473 _alpm_log(PM_LOG_DEBUG, "database path for tree %s set to %s\n",
474 db->treename, db->_path);
476 return db->_path;
479 int _alpm_db_version(pmdb_t *db)
481 if(!db) {
482 return -1;
484 return db->ops->version(db);
487 int _alpm_db_cmp(const void *d1, const void *d2)
489 pmdb_t *db1 = (pmdb_t *)d1;
490 pmdb_t *db2 = (pmdb_t *)d2;
491 return strcmp(db1->treename, db2->treename);
494 alpm_list_t *_alpm_db_search(pmdb_t *db, const alpm_list_t *needles)
496 const alpm_list_t *i, *j, *k;
497 alpm_list_t *ret = NULL;
498 /* copy the pkgcache- we will free the list var after each needle */
499 alpm_list_t *list = alpm_list_copy(_alpm_db_get_pkgcache(db));
501 ALPM_LOG_FUNC;
503 for(i = needles; i; i = i->next) {
504 char *targ;
505 regex_t reg;
507 if(i->data == NULL) {
508 continue;
510 ret = NULL;
511 targ = i->data;
512 _alpm_log(PM_LOG_DEBUG, "searching for target '%s'\n", targ);
514 if(regcomp(&reg, targ, REG_EXTENDED | REG_NOSUB | REG_ICASE | REG_NEWLINE) != 0) {
515 RET_ERR(PM_ERR_INVALID_REGEX, NULL);
518 for(j = list; j; j = j->next) {
519 pmpkg_t *pkg = j->data;
520 const char *matched = NULL;
521 const char *name = alpm_pkg_get_name(pkg);
522 const char *desc = alpm_pkg_get_desc(pkg);
524 /* check name as regex AND as plain text */
525 if(name && (regexec(&reg, name, 0, 0, 0) == 0 || strstr(name, targ))) {
526 matched = name;
528 /* check desc */
529 else if (desc && regexec(&reg, desc, 0, 0, 0) == 0) {
530 matched = desc;
532 /* TODO: should we be doing this, and should we print something
533 * differently when we do match it since it isn't currently printed? */
534 if(!matched) {
535 /* check provides */
536 for(k = alpm_pkg_get_provides(pkg); k; k = k->next) {
537 if (regexec(&reg, k->data, 0, 0, 0) == 0) {
538 matched = k->data;
539 break;
543 if(!matched) {
544 /* check groups */
545 for(k = alpm_pkg_get_groups(pkg); k; k = k->next) {
546 if (regexec(&reg, k->data, 0, 0, 0) == 0) {
547 matched = k->data;
548 break;
553 if(matched != NULL) {
554 _alpm_log(PM_LOG_DEBUG, " search target '%s' matched '%s'\n",
555 targ, matched);
556 ret = alpm_list_add(ret, pkg);
560 /* Free the existing search list, and use the returned list for the
561 * next needle. This allows for AND-based package searching. */
562 alpm_list_free(list);
563 list = ret;
564 regfree(&reg);
567 return ret;
570 /* Returns a new package cache from db.
571 * It frees the cache if it already exists.
573 int _alpm_db_load_pkgcache(pmdb_t *db)
575 ALPM_LOG_FUNC;
577 if(db == NULL) {
578 return -1;
580 _alpm_db_free_pkgcache(db);
582 _alpm_log(PM_LOG_DEBUG, "loading package cache for repository '%s'\n",
583 db->treename);
584 if(db->ops->populate(db) == -1) {
585 _alpm_log(PM_LOG_DEBUG,
586 "failed to load package cache for repository '%s'\n", db->treename);
587 return -1;
590 db->pkgcache_loaded = 1;
591 return 0;
594 void _alpm_db_free_pkgcache(pmdb_t *db)
596 ALPM_LOG_FUNC;
598 if(db == NULL || !db->pkgcache_loaded) {
599 return;
602 _alpm_log(PM_LOG_DEBUG, "freeing package cache for repository '%s'\n",
603 db->treename);
605 alpm_list_free_inner(_alpm_db_get_pkgcache(db),
606 (alpm_list_fn_free)_alpm_pkg_free);
607 _alpm_pkghash_free(db->pkgcache);
608 db->pkgcache_loaded = 0;
610 _alpm_db_free_grpcache(db);
613 pmpkghash_t *_alpm_db_get_pkgcache_hash(pmdb_t *db)
615 ALPM_LOG_FUNC;
617 if(db == NULL) {
618 return NULL;
621 if(!db->pkgcache_loaded) {
622 _alpm_db_load_pkgcache(db);
625 /* hmmm, still NULL ?*/
626 if(!db->pkgcache) {
627 _alpm_log(PM_LOG_DEBUG, "warning: pkgcache is NULL for db '%s'\n", db->treename);
630 return db->pkgcache;
633 alpm_list_t *_alpm_db_get_pkgcache(pmdb_t *db)
635 ALPM_LOG_FUNC;
637 pmpkghash_t *hash = _alpm_db_get_pkgcache_hash(db);
639 if(hash == NULL) {
640 return NULL;
643 return hash->list;
646 /* "duplicate" pkg then add it to pkgcache */
647 int _alpm_db_add_pkgincache(pmdb_t *db, pmpkg_t *pkg)
649 pmpkg_t *newpkg;
651 ALPM_LOG_FUNC;
653 if(db == NULL || !db->pkgcache_loaded || pkg == NULL) {
654 return -1;
657 newpkg = _alpm_pkg_dup(pkg);
658 if(newpkg == NULL) {
659 return -1;
662 _alpm_log(PM_LOG_DEBUG, "adding entry '%s' in '%s' cache\n",
663 alpm_pkg_get_name(newpkg), db->treename);
664 db->pkgcache = _alpm_pkghash_add_sorted(db->pkgcache, newpkg);
666 _alpm_db_free_grpcache(db);
668 return 0;
671 int _alpm_db_remove_pkgfromcache(pmdb_t *db, pmpkg_t *pkg)
673 pmpkg_t *data = NULL;
675 ALPM_LOG_FUNC;
677 if(db == NULL || !db->pkgcache_loaded || pkg == NULL) {
678 return -1;
681 _alpm_log(PM_LOG_DEBUG, "removing entry '%s' from '%s' cache\n",
682 alpm_pkg_get_name(pkg), db->treename);
684 db->pkgcache = _alpm_pkghash_remove(db->pkgcache, pkg, &data);
685 if(data == NULL) {
686 /* package not found */
687 _alpm_log(PM_LOG_DEBUG, "cannot remove entry '%s' from '%s' cache: not found\n",
688 alpm_pkg_get_name(pkg), db->treename);
689 return -1;
692 _alpm_pkg_free(data);
694 _alpm_db_free_grpcache(db);
696 return 0;
699 pmpkg_t *_alpm_db_get_pkgfromcache(pmdb_t *db, const char *target)
701 ALPM_LOG_FUNC;
703 if(db == NULL) {
704 return NULL;
707 pmpkghash_t *pkgcache = _alpm_db_get_pkgcache_hash(db);
708 if(!pkgcache) {
709 _alpm_log(PM_LOG_DEBUG, "warning: failed to get '%s' from NULL pkgcache\n",
710 target);
711 return NULL;
714 return _alpm_pkghash_find(pkgcache, target);
717 /* Returns a new group cache from db.
719 int _alpm_db_load_grpcache(pmdb_t *db)
721 alpm_list_t *lp;
723 ALPM_LOG_FUNC;
725 if(db == NULL) {
726 return -1;
729 _alpm_log(PM_LOG_DEBUG, "loading group cache for repository '%s'\n",
730 db->treename);
732 for(lp = _alpm_db_get_pkgcache(db); lp; lp = lp->next) {
733 const alpm_list_t *i;
734 pmpkg_t *pkg = lp->data;
736 for(i = alpm_pkg_get_groups(pkg); i; i = i->next) {
737 const char *grpname = i->data;
738 alpm_list_t *j;
739 pmgrp_t *grp = NULL;
740 int found = 0;
742 /* first look through the group cache for a group with this name */
743 for(j = db->grpcache; j; j = j->next) {
744 grp = j->data;
746 if(strcmp(grp->name, grpname) == 0
747 && !alpm_list_find_ptr(grp->packages, pkg)) {
748 grp->packages = alpm_list_add(grp->packages, pkg);
749 found = 1;
750 break;
753 if(found) {
754 continue;
756 /* we didn't find the group, so create a new one with this name */
757 grp = _alpm_grp_new(grpname);
758 grp->packages = alpm_list_add(grp->packages, pkg);
759 db->grpcache = alpm_list_add(db->grpcache, grp);
763 db->grpcache_loaded = 1;
764 return 0;
767 void _alpm_db_free_grpcache(pmdb_t *db)
769 alpm_list_t *lg;
771 ALPM_LOG_FUNC;
773 if(db == NULL || !db->grpcache_loaded) {
774 return;
777 _alpm_log(PM_LOG_DEBUG, "freeing group cache for repository '%s'\n",
778 db->treename);
780 for(lg = db->grpcache; lg; lg = lg->next) {
781 _alpm_grp_free(lg->data);
782 lg->data = NULL;
784 FREELIST(db->grpcache);
785 db->grpcache_loaded = 0;
788 alpm_list_t *_alpm_db_get_grpcache(pmdb_t *db)
790 ALPM_LOG_FUNC;
792 if(db == NULL) {
793 return NULL;
796 if(!db->grpcache_loaded) {
797 _alpm_db_load_grpcache(db);
800 return db->grpcache;
803 pmgrp_t *_alpm_db_get_grpfromcache(pmdb_t *db, const char *target)
805 alpm_list_t *i;
807 ALPM_LOG_FUNC;
809 if(db == NULL || target == NULL || strlen(target) == 0) {
810 return NULL;
813 for(i = _alpm_db_get_grpcache(db); i; i = i->next) {
814 pmgrp_t *info = i->data;
816 if(strcmp(info->name, target) == 0) {
817 return info;
821 return NULL;
824 /* vim: set ts=2 sw=2 noet: */