ifpsrv_util.c revision 1a546ae8250c6dbcff0ce775fc811529e02c360c
/*
Authors:
Jakub Hrozek <jhrozek@redhat.com>
Stephen Gallagher <sgallagh@redhat.com>
Copyright (C) 2013 Red Hat
InfoPipe responder: Utility functions
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "responder/ifp/ifp_private.h"
NULL}
{
return EINVAL;
}
return ENOMEM;
}
/* We got a sysbus message but couldn't identify the
* caller? Bail out! */
"BUG: Received a message without a known caller!\n");
goto done;
}
goto done;
goto done;
}
done:
}
return ret;
}
{
return sbus_request_fail_and_finish(dbus_req,
}
return sbus_request_fail_and_finish(dbus_req,
"Cannot create IFP request\n"));
}
{
}
return NULL;
}
/* The following path related functions are based on similar code in
* storaged, just tailored to use talloc instead of glib
*/
{
size_t n;
/* The path must be valid */
return NULL;
}
return NULL;
}
goto done;
}
/* Special case for an empty string */
/* the for loop would just fall through */
}
for (n = 0; path[n]; n++) {
int c = path[n];
/* D-Bus spec says:
* *
* * Each element must only contain the ASCII characters
* "[A-Z][a-z][0-9]_"
* */
if ((c >= 'A' && c <= 'Z')
|| (c >= 'a' && c <= 'z')
|| (c >= '0' && c <= '9')) {
goto done;
}
} else {
goto done;
}
}
}
done:
return safe_path;
}
static inline int unhexchar(char c)
{
if (c >= '0' && c <= '9') {
return c - '0';
}
if (c >= 'a' && c <= 'f') {
return c - 'a' + 10;
}
if (c >= 'A' && c <= 'F') {
return c - 'A' + 10;
}
return -1;
}
{
char *safe_path;
const char *p;
int a, b, c;
return NULL;
}
goto done;
}
/* Special case for the empty string */
goto done;
}
for (p = path; *p; p++) {
if (*p == '_') {
/* There must be at least two more chars after underscore */
if (p[1] == '\0' || p[2] == '\0') {
goto done;
}
if ((a = unhexchar(p[1])) < 0
|| (b = unhexchar(p[2])) < 0) {
/* Invalid escape code, let's take it literal then */
c = '_';
} else {
c = ((a << 4) | b);
p += 2;
}
} else {
c = *p;
}
goto done;
}
}
done:
return safe_path;
}
struct ldb_message_element *el)
{
unsigned int i;
return EINVAL;
}
if (!dbret) {
return ENOMEM;
}
/* Start by appending the key */
if (!dbret) {
return ENOMEM;
}
if (!dbret) {
return ENOMEM;
}
/* Open container for values */
&iter_array);
if (!dbret) {
return ENOMEM;
}
/* Now add all the values */
for (i = 0; i < el->num_values; i++) {
if (!dbret) {
return ENOMEM;
}
}
&iter_array);
if (!dbret) {
return ENOMEM;
}
if (!dbret) {
return ENOMEM;
}
if (!dbret) {
return ENOMEM;
}
return EOK;
}
static inline bool
{
size_t i;
for (i = 0; i < nlist; i++) {
break;
}
}
return (i < nlist) ? true : false;
}
const char **
{
int list_size;
int conf_list_size = 0;
int i;
const char *defaults[] = IFP_DEFAULT_ATTRS;
return NULL;
}
if (conf_str) {
&conf_list, &conf_list_size);
goto done;
}
goto done;
}
}
for (i = 0; i < conf_list_size; i++) {
switch (conf_list[i][0]) {
case '+':
ai++;
continue;
case '-':
di++;
continue;
default:
"either '+' (allow) or '-' (deny), got '%s'\n",
conf_list[i]);
goto done;
}
}
/* Assume the output will have to hold defauls and all the configured,
* values, resize later
*/
list_size = 0;
list_size++;
}
goto done;
}
/* Start by copying explicitly allowed attributes */
for (i = 0; i < ai; i++) {
/* if the attribute is explicitly denied, skip it */
continue;
}
goto done;
}
li++;
"Added allowed attr %s to whitelist\n", allow[i]);
}
/* Add defaults */
for (i = 0; defaults[i]; i++) {
/* if the attribute is explicitly denied, skip it */
continue;
}
goto done;
}
li++;
"Added default attr %s to whitelist\n", defaults[i]);
}
done:
return res;
}
bool
{
size_t i;
return false;
}
for (i = 0; whitelist[i]; i++) {
break;
}
}
return (whitelist[i]) ? true : false;
}