X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fwgtpkg-permissions.c;h=6aed31f3aab2e111449aaad621c5d65c91a08cc9;hb=8afd46f28a677c40a482ccd18ca5568cf6c0f6aa;hp=ee38988858fc704c661b1f26b7fd53d5b3b1af78;hpb=e2de563d1ecb4585ce68521bd42f3ef45ac79f16;p=src%2Fapp-framework-main.git diff --git a/src/wgtpkg-permissions.c b/src/wgtpkg-permissions.c index ee38988..6aed31f 100644 --- a/src/wgtpkg-permissions.c +++ b/src/wgtpkg-permissions.c @@ -1,6 +1,8 @@ /* Copyright 2015 IoT.bzh + author: José Bollo + Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at @@ -17,11 +19,11 @@ #define _GNU_SOURCE #include -#include #include +#include #include "verbose.h" -#include "wgtpkg.h" +#include "wgtpkg-permissions.h" struct permission { char *name; @@ -30,11 +32,11 @@ struct permission { unsigned level: 3; }; -static const char prefix_of_permissions[] = PREFIXPERMISSION; +static const char prefix_of_permissions[] = FWK_PREFIX_PERMISSION; -static int nrpermissions = 0; +static unsigned int nrpermissions = 0; static struct permission *permissions = NULL; -static int indexiter = 0; +static unsigned int indexiter = 0; /* check is the name has the correct prefix for permissions */ int is_standard_permission(const char *name) @@ -45,7 +47,7 @@ int is_standard_permission(const char *name) /* retrieves the permission of name */ static struct permission *get_permission(const char *name) { - int i; + unsigned int i; for (i = 0 ; i < nrpermissions ; i++) if (0 == strcmp(permissions[i].name, name)) @@ -58,7 +60,8 @@ static struct permission *add_permission(const char *name) { struct permission *p = get_permission(name); if (!p) { - p = realloc(permissions, ((nrpermissions + 8) & ~7) * sizeof(*p)); + p = realloc(permissions, + ((nrpermissions + 8) & ~(unsigned)7) * sizeof(*p)); if (p) { permissions = p; p = permissions + nrpermissions; @@ -66,6 +69,8 @@ static struct permission *add_permission(const char *name) p->name = strdup(name); if (!p->name) p = NULL; + else + nrpermissions++; } } return p; @@ -74,7 +79,7 @@ static struct permission *add_permission(const char *name) /* remove any granting */ void reset_permissions() { - int i; + unsigned int i; for (i = 0 ; i < nrpermissions ; i++) permissions[i].granted = 0; } @@ -82,36 +87,37 @@ void reset_permissions() /* remove any granting */ void crop_permissions(unsigned level) { - int i; + unsigned int i; for (i = 0 ; i < nrpermissions ; i++) if (permissions[i].level < level) permissions[i].granted = 0; } /* add permissions granted for installation */ -void grant_permission_list(const char *list) +int grant_permission_list(const char *list) { struct permission *p; char *iter, c; - int n; + unsigned int n; static const char separators[] = " \t\n\r,"; iter = strdupa(list); iter += strspn(iter, separators); while(*iter) { - n = strcspn(iter, separators); + n = (unsigned)strcspn(iter, separators); c = iter[n]; iter[n] = 0; p = add_permission(iter); if (!p) { - ERROR("Can't allocate permission"); - exit(1); + errno = ENOMEM; + return -1; } p->granted = 1; iter += n; *iter =c; iter += strspn(iter, separators); } + return 0; } /* checks if the permission 'name' is recorded */