summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYunmi Ha <yunmi.ha@samsung.com>2017-09-13 11:59:52 +0900
committerYunmi Ha <yunmi.ha@samsung.com>2017-09-13 13:13:31 +0900
commit74408fbb9c59cece3d3d9a3f15d5420439551f84 (patch)
tree05d8693b5e07d60b714a2e6f4ad6f6fbd8f2cb80
parent1988080a89a9db8f70afaa12e07d8834fafb4394 (diff)
downloadtizen-platform-config-74408fbb9c59cece3d3d9a3f15d5420439551f84.tar.gz
tizen-platform-config-74408fbb9c59cece3d3d9a3f15d5420439551f84.tar.bz2
tizen-platform-config-74408fbb9c59cece3d3d9a3f15d5420439551f84.zip
Change-Id: I42260a881474ec2ede4e7ae52d041f1ef912bb49 Signed-off-by: Yunmi Ha <yunmi.ha@samsung.com>
-rw-r--r--src/buffer.c138
-rw-r--r--src/buffer.h18
-rw-r--r--src/context.c30
-rw-r--r--src/context.h22
-rw-r--r--src/foreign.c86
-rw-r--r--src/foreign.h36
-rw-r--r--src/global-api.c137
-rw-r--r--src/hashing.c44
-rw-r--r--src/hashing.h2
-rw-r--r--src/heap.c158
-rw-r--r--src/heap.h38
-rw-r--r--src/init.c518
-rw-r--r--src/init.h2
-rw-r--r--src/isadmin.c59
-rw-r--r--src/isadmin.h16
-rw-r--r--src/parser.c455
-rw-r--r--src/parser.h104
-rw-r--r--src/passwd.c398
-rw-r--r--src/passwd.h24
-rw-r--r--src/scratch.c283
-rw-r--r--src/scratch.h4
-rw-r--r--src/sha256sum.c364
-rw-r--r--src/sha256sum.h2
-rw-r--r--src/shared-api.c346
-rw-r--r--src/shared-api.h2
-rw-r--r--src/toolbox.c1204
-rw-r--r--src/tzplatform_config.h98
-rw-r--r--[-rwxr-xr-x]src/tzplatform_get.c106
28 files changed, 2325 insertions, 2369 deletions
diff --git a/src/buffer.c b/src/buffer.c
index 92e9bf3..a3422f1 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013-2014 Intel Corporation.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
@@ -16,9 +16,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors:
- * José Bollo <jose.bollo@open.eurogiciel.org>
- * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
- * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
+ * José Bollo <jose.bollo@open.eurogiciel.org>
+ * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
+ * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
*
*/
@@ -37,83 +37,75 @@
#include "buffer.h"
-static int buffread( struct buffer *buffer, int fd)
+static int buffread(struct buffer *buffer, int fd)
{
- const int size = 4096;
- void *p;
- char *memory = NULL;
- size_t length = 0;
- ssize_t status;
+ const int size = 4096;
+ void *p;
+ char *memory = NULL;
+ size_t length = 0;
+ ssize_t status;
- /* do read */
- for(;;) {
- p = realloc( memory, length + size);
- if (p == NULL) {
- free( memory);
- return -1;
- }
- memory = p;
- status = read( fd, memory+length, size);
- if (status == 0) {
- buffer->buffer = memory;
- buffer->length = length;
- buffer->mapped = 0;
- return 0;
- }
- if (status > 0) {
- length = length + (int)status;
- }
- else if (errno != EAGAIN && errno != EINTR) {
- free( memory);
- return -1;
- }
- }
+ /* do read */
+ for (;;) {
+ p = realloc(memory, length + size);
+ if (p == NULL) {
+ free(memory);
+ return -1;
+ }
+ memory = p;
+ status = read(fd, memory+length, size);
+ if (status == 0) {
+ buffer->buffer = memory;
+ buffer->length = length;
+ buffer->mapped = 0;
+ return 0;
+ }
+ if (status > 0) {
+ length = length + (int)status;
+ } else if (errno != EAGAIN && errno != EINTR) {
+ free(memory);
+ return -1;
+ }
+ }
}
-int buffer_create( struct buffer *buffer, const char *pathname)
+int buffer_create(struct buffer *buffer, const char *pathname)
{
- int fd, result;
- struct stat bstat;
- void *memory;
- size_t length;
+ int fd, result;
+ struct stat bstat;
+ void *memory;
+ size_t length;
- result = open(pathname, O_RDONLY);
- if (result >= 0)
- {
- fd = result;
- result = fstat(fd, &bstat);
- if (result == 0)
- {
- length = (size_t)bstat.st_size;
- if (bstat.st_size != (off_t)length)
- {
- errno = EOVERFLOW;
- result = -1;
- }
- else
- {
- memory = mmap(NULL,length,PROT_READ,MAP_PRIVATE,fd,0);
- if (memory != MAP_FAILED) {
- buffer->buffer = memory;
- buffer->length = length;
- buffer->mapped = 1;
- }
- else {
- result = buffread( buffer, fd);
- }
- }
- }
- close(fd);
- }
- return result;
+ result = open(pathname, O_RDONLY);
+ if (result >= 0) {
+ fd = result;
+ result = fstat(fd, &bstat);
+ if (result == 0) {
+ length = (size_t)bstat.st_size;
+ if (bstat.st_size != (off_t)length) {
+ errno = EOVERFLOW;
+ result = -1;
+ } else {
+ memory = mmap(NULL, length, PROT_READ, MAP_PRIVATE, fd, 0);
+ if (memory != MAP_FAILED) {
+ buffer->buffer = memory;
+ buffer->length = length;
+ buffer->mapped = 1;
+ } else {
+ result = buffread(buffer, fd);
+ }
+ }
+ }
+ close(fd);
+ }
+ return result;
}
-int buffer_destroy( struct buffer *buffer)
+int buffer_destroy(struct buffer *buffer)
{
- if (buffer->mapped)
- return munmap(buffer->buffer, buffer->length);
- free( buffer->buffer);
- return 0;
+ if (buffer->mapped)
+ return munmap(buffer->buffer, buffer->length);
+ free(buffer->buffer);
+ return 0;
}
-
diff --git a/src/buffer.h b/src/buffer.h
index 28b43be..704f51e 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013-2014 Intel Corporation.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
@@ -16,9 +16,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors:
- * José Bollo <jose.bollo@open.eurogiciel.org>
- * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
- * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
+ * José Bollo <jose.bollo@open.eurogiciel.org>
+ * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
+ * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
*
*/
#ifndef BUFFER_H
@@ -26,22 +26,22 @@
/* structure of the buffer */
struct buffer {
- char *buffer; /* start address */
- size_t length; /* length in byte */
- int mapped; /* is memory mapped */
+ char *buffer; /* start address */
+ size_t length; /* length in byte */
+ int mapped; /* is memory mapped */
};
/*
Create the 'buffer' from reading content of the file of 'pathname'.
Returns 0 if success, -1 if error occured (see then errno)
*/
-int buffer_create( struct buffer *buffer, const char *pathname);
+int buffer_create(struct buffer *buffer, const char *pathname);
/*
Destroy the 'buffer'.
Returns 0 if success, -1 if error occured (see then errno)
*/
-int buffer_destroy( struct buffer *buffer);
+int buffer_destroy(struct buffer *buffer);
#endif
diff --git a/src/context.c b/src/context.c
index 85c417b..a0e1bb3 100644
--- a/src/context.c
+++ b/src/context.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013-2014 Intel Corporation.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
@@ -16,9 +16,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors:
- * José Bollo <jose.bollo@open.eurogiciel.org>
- * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
- * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
+ * José Bollo <jose.bollo@open.eurogiciel.org>
+ * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
+ * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
*
*/
@@ -44,32 +44,32 @@
uid_t get_uid(struct tzplatform_context *context)
{
- uid_t result;
+ uid_t result;
- result = context->user;
- if (result == _USER_NOT_SET_)
- result = getuid();
+ result = context->user;
+ if (result == _USER_NOT_SET_)
+ result = getuid();
- return result;
+ return result;
}
#if _FOREIGN_HAS_(EUID)
uid_t get_euid(struct tzplatform_context *context)
{
- uid_t result;
+ uid_t result;
- result = context->user;
- if (result == _USER_NOT_SET_)
- result = geteuid();
+ result = context->user;
+ if (result == _USER_NOT_SET_)
+ result = geteuid();
- return result;
+ return result;
}
#endif
#if _FOREIGN_HAS_(GID)
gid_t get_gid(struct tzplatform_context *context)
{
- return getgid();
+ return getgid();
}
#endif
diff --git a/src/context.h b/src/context.h
index 9353168..fdf0b69 100644
--- a/src/context.h
+++ b/src/context.h
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013-2014 Intel Corporation.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
@@ -16,9 +16,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors:
- * José Bollo <jose.bollo@open.eurogiciel.org>
- * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
- * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
+ * José Bollo <jose.bollo@open.eurogiciel.org>
+ * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
+ * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
*
*/
#ifndef CONTEXT_H
@@ -32,18 +32,18 @@
#error "you should include foreign.h"
#endif
-enum STATE { RESET=0, ERROR, VALID };
+enum STATE { RESET = 0, ERROR, VALID };
-#define _USER_NOT_SET_ ((uid_t)-1)
+#define _USER_NOT_SET_ ((uid_t)-1)
struct tzplatform_context {
#ifndef NOT_MULTI_THREAD_SAFE
- pthread_mutex_t mutex;
+ pthread_mutex_t mutex;
#endif
- enum STATE state;
- uid_t user;
- struct heap heap;
- const char *values[_TZPLATFORM_VARIABLES_COUNT_];
+ enum STATE state;
+ uid_t user;
+ struct heap heap;
+ const char *values[_TZPLATFORM_VARIABLES_COUNT_];
};
uid_t get_uid(struct tzplatform_context *context);
diff --git a/src/foreign.c b/src/foreign.c
index a19f6ad..8d64de4 100644
--- a/src/foreign.c
+++ b/src/foreign.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013-2014 Intel Corporation.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
@@ -16,9 +16,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors:
- * José Bollo <jose.bollo@open.eurogiciel.org>
- * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
- * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
+ * José Bollo <jose.bollo@open.eurogiciel.org>
+ * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
+ * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
*
*/
#define _GNU_SOURCE
@@ -31,60 +31,58 @@
#include "foreign.h"
-enum fkey foreign( const char *name, size_t length)
+enum fkey foreign(const char *name, size_t length)
{
- if (length == 3) { /* UID */
- if (name[1]=='I' && name[2]=='D')
- switch (name[0]) {
+ if (length == 3) { /* UID */
+ if (name[1] == 'I' && name[2] == 'D')
+ switch (name[0]) {
#if _FOREIGN_HAS_(UID)
- case 'G': /* GID */ return GID;
+ case 'G': /* GID */ return GID;
#endif
#if _FOREIGN_HAS_(GID)
- case 'U': /* UID */ return UID;
+ case 'U': /* UID */ return UID;
#endif
- default: break;
- }
- }
- else if (length == 4) {
- switch (name[0]) {
+ default: break;
+ }
+ } else if (length == 4) {
+ switch (name[0]) {
#if _FOREIGN_HAS_(HOME)
- case 'H': /* HOME */
- if (name[1]=='O' && name[2]=='M' && name[3]=='E')
- return HOME;
- break;
+ case 'H': /* HOME */
+ if (name[1] == 'O' && name[2] == 'M' && name[3] == 'E')
+ return HOME;
+ break;
#endif
#if _FOREIGN_HAS_(EUID)
- case 'E': /* EUID */
- if (name[1]=='U' && name[2]=='I' && name[3]=='D')
- return EUID;
- break;
+ case 'E': /* EUID */
+ if (name[1] == 'U' && name[2] == 'I' && name[3] == 'D')
+ return EUID;
+ break;
#endif
#if _FOREIGN_HAS_(USER)
- case 'U': /* USER */
- if (name[1]=='S' && name[2]=='E' && name[3]=='R')
- return USER;
- break;
+ case 'U': /* USER */
+ if (name[1] == 'S' && name[2] == 'E' && name[3] == 'R')
+ return USER;
+ break;
#endif
- default: break;
- }
- }
- else if (length == 5 && name[0]=='E') {
- switch (name[1]) {
+ default: break;
+ }
+ } else if (length == 5 && name[0] == 'E') {
+ switch (name[1]) {
#if _FOREIGN_HAS_(EHOME)
- case 'H': /* EHOME */
- if (name[2]=='O' && name[3]=='M' && name[4]=='E')
- return EHOME;
- break;
+ case 'H': /* EHOME */
+ if (name[2] == 'O' && name[3] == 'M' && name[4] == 'E')
+ return EHOME;
+ break;
#endif
#if _FOREIGN_HAS_(EUSER)
- case 'U': /* EUSER */
- if (name[2]=='S' && name[3]=='E' && name[4]=='R')
- return EUSER;
- break;
+ case 'U': /* EUSER */
+ if (name[2] == 'S' && name[3] == 'E' && name[4] == 'R')
+ return EUSER;
+ break;
#endif
- default: break;
- }
- }
- return _FOREIGN_INVALID_;
+ default: break;
+ }
+ }
+ return _FOREIGN_INVALID_;
}
diff --git a/src/foreign.h b/src/foreign.h
index 646a41d..41407a0 100644
--- a/src/foreign.h
+++ b/src/foreign.h
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013-2014 Intel Corporation.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
@@ -16,55 +16,55 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors:
- * José Bollo <jose.bollo@open.eurogiciel.org>
- * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
- * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
+ * José Bollo <jose.bollo@open.eurogiciel.org>
+ * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
+ * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
*
*/
#ifndef FOREIGN_H
#define FOREIGN_H
#define _FOREIGN_MASK_HOME_ 1
-#define _FOREIGN_MASK_UID_ 2
+#define _FOREIGN_MASK_UID_ 2
#define _FOREIGN_MASK_USER_ 4
-#define _FOREIGN_MASK_GID_ 8
+#define _FOREIGN_MASK_GID_ 8
#define _FOREIGN_MASK_EHOME_ 16
#define _FOREIGN_MASK_EUID_ 32
#define _FOREIGN_MASK_EUSER_ 64
-#define _FOREIGNS_TO_USE_ ( _FOREIGN_MASK_HOME_ \
- | _FOREIGN_MASK_USER_ )
+#define _FOREIGNS_TO_USE_ (_FOREIGN_MASK_HOME_ \
+ | _FOREIGN_MASK_USER_)
#define _FOREIGN_HAS_(x) (0 != ((_FOREIGNS_TO_USE_) & (_FOREIGN_MASK_##x##_)))
enum fkey {
- _FOREIGN_INVALID_ = -1,
+ _FOREIGN_INVALID_ = -1,
#if _FOREIGN_HAS_(HOME)
- HOME,
+ HOME,
#endif
#if _FOREIGN_HAS_(UID)
- UID,
+ UID,
#endif
#if _FOREIGN_HAS_(USER)
- USER,
+ USER,
#endif
#if _FOREIGN_HAS_(GID)
- GID,
+ GID,
#endif
#if _FOREIGN_HAS_(EHOME)
- EHOME,
+ EHOME,
#endif
#if _FOREIGN_HAS_(EUID)
- EUID,
+ EUID,
#endif
#if _FOREIGN_HAS_(EUSER)
- EUSER,
+ EUSER,
#endif
- _FOREIGN_COUNT_
+ _FOREIGN_COUNT_
};
/* get the foreign key for the 'name' of 'length' */
-enum fkey foreign( const char *name, size_t length);
+enum fkey foreign(const char *name, size_t length);
#endif
diff --git a/src/global-api.c b/src/global-api.c
index f54410f..dd8ab83 100644
--- a/src/global-api.c
+++ b/src/global-api.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013-2014 Intel Corporation.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
@@ -16,9 +16,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors:
- * José Bollo <jose.bollo@open.eurogiciel.org>
- * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
- * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
+ * José Bollo <jose.bollo@open.eurogiciel.org>
+ * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
+ * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
*
*/
#define _GNU_SOURCE
@@ -38,97 +38,97 @@
int tzplatform_getcount()
{
- return _TZPLATFORM_VARIABLES_COUNT_;
+ return _TZPLATFORM_VARIABLES_COUNT_;
}
const char* tzplatform_getname(enum tzplatform_variable id)
{
- return _getname_tzplatform_(id, tizen_platform_config_signup);
+ return _getname_tzplatform_(id, tizen_platform_config_signup);
}
enum tzplatform_variable tzplatform_getid(const char *name)
{
- return _getid_tzplatform_(name, tizen_platform_config_signup);
+ return _getid_tzplatform_(name, tizen_platform_config_signup);
}
-const char* tzplatform_getenv(enum tzplatform_variable id)
+const char* tzplatform_getenv(enum tzplatform_variable id)
{
- return _getenv_tzplatform_(id, tizen_platform_config_signup);
+ return _getenv_tzplatform_(id, tizen_platform_config_signup);
}
const char* tzplatform_context_getenv(struct tzplatform_context *context, enum tzplatform_variable id)
{
- return _context_getenv_tzplatform_(id, tizen_platform_config_signup, context);
+ return _context_getenv_tzplatform_(id, tizen_platform_config_signup, context);
}
int tzplatform_getenv_int(enum tzplatform_variable id)
{
- return _getenv_int_tzplatform_(id, tizen_platform_config_signup);
+ return _getenv_int_tzplatform_(id, tizen_platform_config_signup);
}
int tzplatform_context_getenv_int(struct tzplatform_context *context, enum tzplatform_variable id)
{
- return _context_getenv_int_tzplatform_(id, tizen_platform_config_signup, context);
+ return _context_getenv_int_tzplatform_(id, tizen_platform_config_signup, context);
}
const char* tzplatform_mkstr(enum tzplatform_variable id, const char * str)
{
- return _mkstr_tzplatform_(id, str, tizen_platform_config_signup);
+ return _mkstr_tzplatform_(id, str, tizen_platform_config_signup);
}
const char* tzplatform_context_mkstr(struct tzplatform_context *context, enum tzplatform_variable id, const char *str)
{
- return _context_mkstr_tzplatform_(id, str, tizen_platform_config_signup, context);
+ return _context_mkstr_tzplatform_(id, str, tizen_platform_config_signup, context);
}
const char* tzplatform_mkpath(enum tzplatform_variable id, const char * path)
{
- return _mkpath_tzplatform_(id, path, tizen_platform_config_signup);
+ return _mkpath_tzplatform_(id, path, tizen_platform_config_signup);
}
const char* tzplatform_context_mkpath(struct tzplatform_context *context, enum tzplatform_variable id, const char *path)
{
- return _context_mkpath_tzplatform_(id, path, tizen_platform_config_signup, context);
+ return _context_mkpath_tzplatform_(id, path, tizen_platform_config_signup, context);
}
const char* tzplatform_mkpath3(enum tzplatform_variable id, const char * path, const char* path2)
{
- return _mkpath3_tzplatform_(id, path, path2, tizen_platform_config_signup);
+ return _mkpath3_tzplatform_(id, path, path2, tizen_platform_config_signup);
}
const char* tzplatform_context_mkpath3(struct tzplatform_context *context, enum tzplatform_variable id, const char *path, const char *path2)
{
- return _context_mkpath3_tzplatform_(id, path, path2, tizen_platform_config_signup, context);
+ return _context_mkpath3_tzplatform_(id, path, path2, tizen_platform_config_signup, context);
}
const char* tzplatform_mkpath4(enum tzplatform_variable id, const char * path, const char* path2, const char *path3)
{
- return _mkpath4_tzplatform_(id, path, path2, path3, tizen_platform_config_signup);
+ return _mkpath4_tzplatform_(id, path, path2, path3, tizen_platform_config_signup);
}
const char* tzplatform_context_mkpath4(struct tzplatform_context *context, enum tzplatform_variable id, const char *path, const char *path2, const char *path3)
{
- return _context_mkpath4_tzplatform_(id, path, path2, path3, tizen_platform_config_signup, context);
+ return _context_mkpath4_tzplatform_(id, path, path2, path3, tizen_platform_config_signup, context);
}
uid_t tzplatform_getuid(enum tzplatform_variable id)
{
- return _getuid_tzplatform_(id, tizen_platform_config_signup);
+ return _getuid_tzplatform_(id, tizen_platform_config_signup);
}
uid_t tzplatform_context_getuid(struct tzplatform_context *context, enum tzplatform_variable id)
{
- return _context_getuid_tzplatform_(id, tizen_platform_config_signup, context);
+ return _context_getuid_tzplatform_(id, tizen_platform_config_signup, context);
}
gid_t tzplatform_getgid(enum tzplatform_variable id)
{
- return _getgid_tzplatform_(id, tizen_platform_config_signup);
+ return _getgid_tzplatform_(id, tizen_platform_config_signup);
}
gid_t tzplatform_context_getgid(struct tzplatform_context *context, enum tzplatform_variable id)
{
- return _context_getgid_tzplatform_(id, tizen_platform_config_signup, context);
+ return _context_getgid_tzplatform_(id, tizen_platform_config_signup, context);
}
int tzplatform_has_system_group(uid_t uid)
@@ -140,50 +140,51 @@ int tzplatform_has_system_group(uid_t uid)
#include <stdlib.h>
#include <stdio.h>
-int main() {
- int i;
- struct tzplatform_context *context;
- enum tzplatform_variable id;
- const char *name;
- const char *value;
- int xid;
- uid_t uid;
-
- i = 0;
- while(i != tzplatform_getcount()) {
- id = (enum tzplatform_variable)i;
- name = tzplatform_getname(id);
- value = tzplatform_getenv(id);
- xid = (int)tzplatform_getid(name);
- printf("%d=%d\t%s=%s\n",i,xid,name,value?value:"<null>");
- i++;
- }
-
- printf("------------------------\n");
- i = tzplatform_context_create(&context);
- if (i) {
- printf("error while creating context %d\n",i);
- return 1;
- }
-
- uid = (uid_t)0;
- i = tzplatform_context_set_user(context, uid);
- if (i) {
- printf("error %d while switching to user %d\n",i,(int)uid);
- return 1;
- }
- i = 0;
- while(i != tzplatform_getcount()) {
- id = (enum tzplatform_variable)i;
- name = tzplatform_getname(id);
- value = tzplatform_context_getenv(context, id);
- xid = (int)tzplatform_getid(name);
- printf("%d=%d\t%s=%s\n",i,xid,name,value?value:"<null>");
- i++;
- }
- tzplatform_context_destroy(context);
-
- return 0;
+int main()
+{
+ int i;
+ struct tzplatform_context *context;
+ enum tzplatform_variable id;
+ const char *name;
+ const char *value;
+ int xid;
+ uid_t uid;
+
+ i = 0;
+ while (i != tzplatform_getcount()) {
+ id = (enum tzplatform_variable)i;
+ name = tzplatform_getname(id);
+ value = tzplatform_getenv(id);
+ xid = (int)tzplatform_getid(name);
+ printf("%d=%d\t%s=%s\n", i, xid, name, value ? value : "<null>");
+ i++;
+ }
+
+ printf("------------------------\n");
+ i = tzplatform_context_create(&context);
+ if (i) {
+ printf("error while creating context %d\n", i);
+ return 1;
+ }
+
+ uid = (uid_t)0;
+ i = tzplatform_context_set_user(context, uid);
+ if (i) {
+ printf("error %d while switching to user %d\n", i, (int)uid);
+ return 1;
+ }
+ i = 0;
+ while (i != tzplatform_getcount()) {
+ id = (enum tzplatform_variable)i;
+ name = tzplatform_getname(id);
+ value = tzplatform_context_getenv(context, id);
+ xid = (int)tzplatform_getid(name);
+ printf("%d=%d\t%s=%s\n", i, xid, name, value ? value : "<null>");
+ i++;
+ }
+ tzplatform_context_destroy(context);
+
+ return 0;
}
#endif
diff --git a/src/hashing.c b/src/hashing.c
index e74464d..181bed5 100644
--- a/src/hashing.c
+++ b/src/hashing.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013-2014 Intel Corporation.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
@@ -16,9 +16,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors:
- * José Bollo <jose.bollo@open.eurogiciel.org>
- * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
- * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
+ * José Bollo <jose.bollo@open.eurogiciel.org>
+ * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
+ * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
*
*/
#define _GNU_SOURCE
@@ -37,26 +37,26 @@ static const char *var_names[_TZPLATFORM_VARIABLES_COUNT_];
int hashid(const char *text, unsigned int len)
{
- const struct varassoc *vara = hashvar(text, len);
- return vara ? vara->id : -1;
+ const struct varassoc *vara = hashvar(text, len);
+ return vara ? vara->id : -1;
}
const char *keyname(int id)
{
- const struct varassoc *iter, *end;
-
- assert(0 <= id && id < _TZPLATFORM_VARIABLES_COUNT_);
- if (!var_names[0]) {
- iter = namassoc;
- end = iter + (sizeof namassoc / sizeof namassoc[0]);
- while (iter != end) {
- if (iter->offset >= 0) {
- assert(0 <= iter->id && iter->id < _TZPLATFORM_VARIABLES_COUNT_);
- var_names[iter->id] = varpool + iter->offset;
- }
- iter++;
- }
- }
- return var_names[id];
+ const struct varassoc *iter, *end;
+
+ assert(0 <= id && id < _TZPLATFORM_VARIABLES_COUNT_);
+ if (!var_names[0]) {
+ iter = namassoc;
+ end = iter + (sizeof namassoc / sizeof namassoc[0]);
+ while (iter != end) {
+ if (iter->offset >= 0) {
+ assert(0 <= iter->id && iter->id < _TZPLATFORM_VARIABLES_COUNT_);
+ var_names[iter->id] = varpool + iter->offset;
+ }
+ iter++;
+ }
+ }
+ return var_names[id];
}
-
+
diff --git a/src/hashing.h b/src/hashing.h
index f20f3e9..34372be 100644
--- a/src/hashing.h
+++ b/src/hashing.h
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013-2014 Intel Corporation.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
diff --git a/src/heap.c b/src/heap.c
index d091f51..ae15644 100644
--- a/src/heap.c
+++ b/src/heap.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013-2014 Intel Corporation.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
@@ -16,9 +16,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors:
- * José Bollo <jose.bollo@open.eurogiciel.org>
- * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
- * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
+ * José Bollo <jose.bollo@open.eurogiciel.org>
+ * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
+ * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
*
*/
#define _GNU_SOURCE
@@ -35,110 +35,108 @@
#include "heap.h"
/* align to a size_t size */
-inline static size_t align(size_t size)
+static inline size_t align(size_t size)
{
- /* we assume that sizeof(size_t) is a power of 2 */
- assert( (sizeof(size_t) & (sizeof(size_t)-1)) == 0 );
- return (size + (sizeof(size_t)-1)) & ~(sizeof(size_t)-1);
+ /* we assume that sizeof(size_t) is a power of 2 */
+ assert((sizeof(size_t) & (sizeof(size_t)-1)) == 0);
+ return (size + (sizeof(size_t)-1)) & ~(sizeof(size_t)-1);
}
/* align to a page size */
-inline static size_t pagealign( size_t size)
+static inline size_t pagealign(size_t size)
{
- static size_t pagemask = 0;
- /* we assume that pagesize is a power of 2 */
- if (!pagemask) {
- pagemask = (size_t)sysconf(_SC_PAGE_SIZE) - 1;
- assert( pagemask );
- assert( (pagemask & (pagemask+1)) == 0 );
- }
- return (size + pagemask) & ~pagemask;
+ static size_t pagemask = 0;
+ /* we assume that pagesize is a power of 2 */
+ if (!pagemask) {
+ pagemask = (size_t)sysconf(_SC_PAGE_SIZE) - 1;
+ assert(pagemask);
+ assert((pagemask & (pagemask+1)) == 0);
+ }
+ return (size + pagemask) & ~pagemask;
}
-int heap_create( struct heap *heap, size_t capacity)
+int heap_create(struct heap *heap, size_t capacity)
{
- char *data;
-
- /* allocation of the heap */
- capacity = pagealign(capacity ? capacity : 1);
- data = mmap(NULL, capacity, PROT_READ|PROT_WRITE,
- MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
-
- /* success of the allocation? */
- if (data == MAP_FAILED)
- return -1;
-
- /* yes. initialisae the heap */
- heap->data = data;
- heap->capacity = capacity;
- heap->size = 0;
- return 0;
+ char *data;
+
+ /* allocation of the heap */
+ capacity = pagealign(capacity ? capacity : 1);
+ data = mmap(NULL, capacity, PROT_READ|PROT_WRITE,
+ MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
+
+ /* success of the allocation? */
+ if (data == MAP_FAILED)
+ return -1;
+
+ /* yes. initialisae the heap */
+ heap->data = data;
+ heap->capacity = capacity;
+ heap->size = 0;
+ return 0;
}
-int heap_destroy( struct heap *heap)
+int heap_destroy(struct heap *heap)
{
- return munmap( heap->data, heap->capacity);
+ return munmap(heap->data, heap->capacity);
}
-int heap_resize( struct heap *heap, size_t size)
+int heap_resize(struct heap *heap, size_t size)
{
- /* has heap enought data? */
- if (size > heap->capacity) {
-
- /* no. resizing of the heap. */
- /* compute the sizes and realloc */
- size_t capa = pagealign(size);
- char *data = mremap(heap->data, heap->capacity, capa, MREMAP_MAYMOVE);
-
- /* error if failure */
- if (data == MAP_FAILED)
- return -1;
-
- /* record new parameters. */
- heap->data = data;
- heap->capacity = capa;
- }
- heap->size = size;
-
- return 0;
+ /* has heap enought data? */
+ if (size > heap->capacity) {
+
+ /* no. resizing of the heap. */
+ /* compute the sizes and realloc */
+ size_t capa = pagealign(size);
+ char *data = mremap(heap->data, heap->capacity, capa, MREMAP_MAYMOVE);
+
+ /* error if failure */
+ if (data == MAP_FAILED)
+ return -1;
+
+ /* record new parameters. */
+ heap->data = data;
+ heap->capacity = capa;
+ }
+ heap->size = size;
+
+ return 0;
}
-size_t heap_alloc( struct heap *heap, size_t count)
+size_t heap_alloc(struct heap *heap, size_t count)
{
- size_t result = heap->size;
- if( heap_resize( heap, align( result + count)) != 0)
- result = HNULL;
- return result;
+ size_t result = heap->size;
+ if (heap_resize(heap, align(result + count)) != 0)
+ result = HNULL;
+ return result;
}
-size_t heap_strndup( struct heap *heap, const char *value, size_t length)
+size_t heap_strndup(struct heap *heap, const char *value, size_t length)
{
- size_t offset;
- char *string;
-
- offset = heap_alloc( heap, length+1);
- if (offset != HNULL) {
- string = heap_address( heap, offset);
- memcpy( string, value, length);
- string[length] = 0;
- }
- return offset;
+ size_t offset;
+ char *string;
+
+ offset = heap_alloc(heap, length+1);
+ if (offset != HNULL) {
+ string = heap_address(heap, offset);
+ memcpy(string, value, length);
+ string[length] = 0;
+ }
+ return offset;
}
-size_t heap_strdup( struct heap *heap, const char *string)
+size_t heap_strdup(struct heap *heap, const char *string)
{
- return heap_strndup( heap, string, strlen(string));
+ return heap_strndup(heap, string, strlen(string));
}
-int heap_read_write( struct heap *heap)
+int heap_read_write(struct heap *heap)
{
- return mprotect(heap->data, heap->capacity, PROT_READ|PROT_WRITE);
+ return mprotect(heap->data, heap->capacity, PROT_READ|PROT_WRITE);
}
-int heap_read_only( struct heap *heap)
+int heap_read_only(struct heap *heap)
{
- return mprotect(heap->data, heap->capacity, PROT_READ);
+ return mprotect(heap->data, heap->capacity, PROT_READ);
}
-
-
diff --git a/src/heap.h b/src/heap.h
index 744e6c0..abb6c83 100644
--- a/src/heap.h
+++ b/src/heap.h
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013-2014 Intel Corporation.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
@@ -16,32 +16,32 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors:
- * José Bollo <jose.bollo@open.eurogiciel.org>
- * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
- * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
+ * José Bollo <jose.bollo@open.eurogiciel.org>
+ * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
+ * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
*
*/
#ifndef HEAP_H
#define HEAP_H
/* null offset value */
-#define HNULL ((size_t)-1)
+#define HNULL ((size_t)-1)
/* structure defining the heap */
struct heap {
- char *data; /* pointer to data of the heap */
- size_t size; /* count of used byte of the heap */
- size_t capacity; /* count of byte of the heap */
+ char *data; /* pointer to data of the heap */
+ size_t size; /* count of used byte of the heap */
+ size_t capacity; /* count of byte of the heap */
};
/*
Return the address of the 'heap' memory of 'offset'.
The returned pointer is only valid until
- a call to 'heap_destroy', 'heap_resize', 'heap_alloc'
+ a call to 'heap_destroy', 'heap_resize', 'heap_alloc'
*/
-inline static void *heap_address( struct heap *heap, size_t offset)
+static inline void *heap_address(struct heap *heap, size_t offset)
{
- return heap->data + offset;
+ return heap->data + offset;
}
@@ -50,50 +50,50 @@ inline static void *heap_address( struct heap *heap, size_t offset)
The allocated size will be zero.
Returns 0 if success, -1 if error occured (see then errno)
*/
-int heap_create( struct heap *heap, size_t capacity);
+int heap_create(struct heap *heap, size_t capacity);
/*
Resize the 'heap' to 'size'.
Returns 0 if success, -1 if error occured (see then errno)
*/
-int heap_resize( struct heap *heap, size_t size);
+int heap_resize(struct heap *heap, size_t size);
/*
Allocation of 'count' bytes from the 'heap'.
Returns the offset (in byte) from the start
of the heap. Return HNULL in case of error (see then errno).
*/
-size_t heap_alloc( struct heap *heap, size_t count);
+size_t heap_alloc(struct heap *heap, size_t count);
/*
Copy the 'string' of 'length' in the 'heap', appending a terminating null.
Return the offset or HNULL if error.
*/
-size_t heap_strndup( struct heap *heap, const char *string, size_t length);
+size_t heap_strndup(struct heap *heap, const char *string, size_t length);
/*
Copy the 'string' in the 'heap' with the terminating null.
Return the offset or HNULL if error.
*/
-size_t heap_strdup( struct heap *heap, const char *string);
+size_t heap_strdup(struct heap *heap, const char *string);
/*
Destroy the 'heap'.
Returns 0 if success, -1 if error occured (see then errno)
*/
-int heap_destroy( struct heap *heap);
+int heap_destroy(struct heap *heap);
/*
Set the heap as read/write
Returns 0 if success, -1 if error occured (see then errno)
*/
-int heap_read_write( struct heap *heap);
+int heap_read_write(struct heap *heap);
/*
Set the heap as read only
Returns 0 if success, -1 if error occured (see then errno)
*/
-int heap_read_only( struct heap *heap);
+int heap_read_only(struct heap *heap);
#endif
diff --git a/src/init.c b/src/init.c
index 4edf520..b431098 100644
--- a/src/init.c
+++ b/src/init.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013-2014 Intel Corporation.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
@@ -16,9 +16,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors:
- * José Bollo <jose.bollo@open.eurogiciel.org>
- * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
- * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
+ * José Bollo <jose.bollo@open.eurogiciel.org>
+ * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
+ * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
*
*/
#define _GNU_SOURCE
@@ -61,14 +61,14 @@
#include "hashing.h"
#include "init.h"
-#define _HAS_IDS_ ( _FOREIGN_HAS_(UID) \
- || _FOREIGN_HAS_(EUID) \
- || _FOREIGN_HAS_(GID) )
+#define _HAS_IDS_ (_FOREIGN_HAS_(UID) \
+ || _FOREIGN_HAS_(EUID) \
+ || _FOREIGN_HAS_(GID))
-#define _HAS_PWS_ ( _FOREIGN_HAS_(HOME) \
- || _FOREIGN_HAS_(USER) \
- || _FOREIGN_HAS_(EHOME) \
- || _FOREIGN_HAS_(EUSER) )
+#define _HAS_PWS_ (_FOREIGN_HAS_(HOME) \
+ || _FOREIGN_HAS_(USER) \
+ || _FOREIGN_HAS_(EHOME) \
+ || _FOREIGN_HAS_(EUSER))
/* local and static variables */
static const char metafilepath[] = CONFIGPATH;
@@ -76,356 +76,350 @@ static const char emptystring[] = "";
/* structure for reading config files */
struct reading {
- int errcount;
- struct tzplatform_context *context;
- size_t dynvars[_FOREIGN_COUNT_];
- size_t offsets[_TZPLATFORM_VARIABLES_COUNT_];
+ int errcount;
+ struct tzplatform_context *context;
+ size_t dynvars[_FOREIGN_COUNT_];
+ size_t offsets[_TZPLATFORM_VARIABLES_COUNT_];
};
/* write the error message */
-static void writerror( const char *format, ...)
+static void writerror(const char *format, ...)
{
- va_list ap;
- fprintf( stderr, "tzplatform_config ERROR: ");
- va_start(ap, format);
- vfprintf(stderr, format, ap);
- va_end(ap);
- fprintf( stderr, "\n");
+ va_list ap;
+ fprintf(stderr, "tzplatform_config ERROR: ");
+ va_start(ap, format);
+ vfprintf(stderr, format, ap);
+ va_end(ap);
+ fprintf(stderr, "\n");
}
#if _HAS_IDS_
/* fill the foreign variables for ids */
-static void foreignid( struct reading *reading)
+static void foreignid(struct reading *reading)
{
- int n;
- char buffer[50];
+ int n;
+ char buffer[50];
#if _FOREIGN_HAS_(UID)
- /* set the uid */
- if (reading->dynvars[UID] == HNULL) {
- n = snprintf( buffer, sizeof buffer, "%d", (int)get_uid(reading->context));
- if (0 < n && n < (int)(sizeof buffer))
- reading->dynvars[UID] = heap_strndup( &reading->context->heap, buffer, (size_t)n);
- }
+ /* set the uid */
+ if (reading->dynvars[UID] == HNULL) {
+ n = snprintf(buffer, sizeof buffer, "%d", (int)get_uid(reading->context));
+ if (0 < n && n < (int)(sizeof buffer))
+ reading->dynvars[UID] = heap_strndup(&reading->context->heap, buffer, (size_t)n);
+ }
#endif
#if _FOREIGN_HAS_(EUID)
- /* set the euid */
- if (reading->dynvars[EUID] == HNULL) {
- n = snprintf( buffer, sizeof buffer, "%d", (int)get_euid(reading->context));
- if (0 < n && n < (int)(sizeof buffer))
- reading->dynvars[EUID] = heap_strndup( &reading->context->heap, buffer, (size_t)n);
- }
+ /* set the euid */
+ if (reading->dynvars[EUID] == HNULL) {
+ n = snprintf(buffer, sizeof buffer, "%d", (int)get_euid(reading->context));
+ if (0 < n && n < (int)(sizeof buffer))
+ reading->dynvars[EUID] = heap_strndup(&reading->context->heap, buffer, (size_t)n);
+ }
#endif
#if _FOREIGN_HAS_(GID)
- /* set the gid */
- if (reading->dynvars[GID] == HNULL) {
- n = snprintf( buffer, sizeof buffer, "%d", (int)get_gid(reading->context));
- if (0 < n && n < (int)(sizeof buffer))
- reading->dynvars[GID] = heap_strndup( &reading->context->heap, buffer, (size_t)n);
- }
+ /* set the gid */
+ if (reading->dynvars[GID] == HNULL) {
+ n = snprintf(buffer, sizeof buffer, "%d", (int)get_gid(reading->context));
+ if (0 < n && n < (int)(sizeof buffer))
+ reading->dynvars[GID] = heap_strndup(&reading->context->heap, buffer, (size_t)n);
+ }
#endif
}
#endif
#if _HAS_PWS_
/* fill the foreign variables for home and user */
-static void foreignpw( struct reading *reading)
+static void foreignpw(struct reading *reading)
{
- int n = 0;
- struct pwget *array[3];
+ int n = 0;
+ struct pwget *array[3];
#if _FOREIGN_HAS_(HOME) || _FOREIGN_HAS_(USER)
- struct pwget uid;
- char suid[50];
+ struct pwget uid;
+ char suid[50];
#endif
#if _FOREIGN_HAS_(EHOME) || _FOREIGN_HAS_(EUSER)
- struct pwget euid;
- char seuid[50];
+ struct pwget euid;
+ char seuid[50];
#endif
#if _FOREIGN_HAS_(HOME) || _FOREIGN_HAS_(USER)
- if (
+ if (
#if _FOREIGN_HAS_(HOME)
- reading->dynvars[HOME] == HNULL
+ reading->dynvars[HOME] == HNULL
#endif
#if _FOREIGN_HAS_(HOME) && _FOREIGN_HAS_(USER)
- ||
+ ||
#endif
#if _FOREIGN_HAS_(USER)
- reading->dynvars[USER] == HNULL
+ reading->dynvars[USER] == HNULL
#endif
- ) {
- snprintf( suid, sizeof suid, "%u", (unsigned)get_uid(reading->context));
- uid.id = suid;
- array[n++] = &uid;
- }
- else {
- uid.set = 0;
- }
+ ) {
+ snprintf(suid, sizeof suid, "%u", (unsigned)get_uid(reading->context));
+ uid.id = suid;
+ array[n++] = &uid;
+ } else {
+ uid.set = 0;
+ }
#endif
#if _FOREIGN_HAS_(EHOME) || _FOREIGN_HAS_(EUSER)
- if (
+ if (
#if _FOREIGN_HAS_(EHOME)
- reading->dynvars[EHOME] == HNULL
+ reading->dynvars[EHOME] == HNULL
#endif
#if _FOREIGN_HAS_(EHOME) && _FOREIGN_HAS_(USER)
- ||
+ ||
#endif
#if _FOREIGN_HAS_(EUSER)
- reading->dynvars[EUSER] == HNULL
+ reading->dynvars[EUSER] == HNULL
#endif
- ) {
- snprintf( seuid, sizeof seuid, "%u", (unsigned)get_euid(reading->context));
- euid.id = seuid;
- array[n++] = &euid;
- }
- else {
- euid.set = 0;
- }
+ ) {
+ snprintf(seuid, sizeof seuid, "%u", (unsigned)get_euid(reading->context));
+ euid.id = seuid;
+ array[n++] = &euid;
+ } else {
+ euid.set = 0;
+ }
#endif
- if (n) {
- array[n] = NULL;
- if (pw_get( &reading->context->heap, array) == 0) {
+ if (n) {
+ array[n] = NULL;
+ if (pw_get(&reading->context->heap, array) == 0) {
#if _FOREIGN_HAS_(HOME)
- if (uid.set)
- reading->dynvars[HOME] = uid.home;
+ if (uid.set)
+ reading->dynvars[HOME] = uid.home;
#endif
#if _FOREIGN_HAS_(USER)
- if (uid.set)
- reading->dynvars[USER] = uid.user;
+ if (uid.set)
+ reading->dynvars[USER] = uid.user;
#endif
#if _FOREIGN_HAS_(EHOME)
- if (euid.set)
- reading->dynvars[EHOME] = euid.home;
+ if (euid.set)
+ reading->dynvars[EHOME] = euid.home;
#endif
#if _FOREIGN_HAS_(EUSER)
- if (euid.set)
- reading->dynvars[EUSER] = euid.user;
+ if (euid.set)
+ reading->dynvars[EUSER] = euid.user;
#endif
- }
- }
+ }
+ }
}
#endif
/* get the foreign variable */
-static const char *foreignvar( struct reading *reading,
- const char *name, size_t length)
+static const char *foreignvar(struct reading *reading,
+ const char *name, size_t length)
{
- enum fkey key = foreign( name, length);
- size_t offset;
+ enum fkey key = foreign(name, length);
+ size_t offset;
- switch (key) {
+ switch (key) {
#if _HAS_PWS_
#if _FOREIGN_HAS_(HOME)
- case HOME:
+ case HOME:
#endif
#if _FOREIGN_HAS_(USER)
- case USER:
+ case USER:
#endif
#if _FOREIGN_HAS_(EHOME)
- case EHOME:
+ case EHOME:
#endif
#if _FOREIGN_HAS_(EUSER)
- case EUSER:
+ case EUSER:
#endif
- foreignpw( reading);
- break;
+ foreignpw(reading);
+ break;
#endif
-
+
#if _HAS_IDS_
#if _FOREIGN_HAS_(UID)
- case UID:
+ case UID:
#endif
#if _FOREIGN_HAS_(GID)
- case GID:
+ case GID:
#endif
#if _FOREIGN_HAS_(EUID)
- case EUID:
+ case EUID:
#endif
- foreignid( reading);
- break;
+ foreignid(reading);
+ break;
#endif
- default:
- return NULL;
- }
- offset = reading->dynvars[key];
- return offset==HNULL ? NULL : heap_address( &reading->context->heap, offset);
+ default:
+ return NULL;
+ }
+ offset = reading->dynvars[key];
+ return (offset == HNULL) ? NULL : heap_address(&reading->context->heap, offset);
}
/* callback for parsing errors */
-static int errcb( struct parsing *parsing,
- size_t position, const char *message)
+static int errcb(struct parsing *parsing,
+ size_t position, const char *message)
{
- struct parsinfo info;
- struct reading *reading = parsing->data;
+ struct parsinfo info;
+ struct reading *reading = parsing->data;
- /* count the error */
- reading->errcount++;
+ /* count the error */
+ reading->errcount++;
- /* print the error */
- parse_utf8_info( parsing, &info, position);
- writerror( "%s (file %s line %d)", message, metafilepath, info.lino);
+ /* print the error */
+ parse_utf8_info(parsing, &info, position);
+ writerror("%s (file %s line %d)", message, metafilepath, info.lino);
- /* continue to parse */
- return 0;
+ /* continue to parse */
+ return 0;
}
/* callback for solving variables */
-static const char *getcb( struct parsing *parsing,
- const char *key, size_t length,
- size_t begin_pos, size_t end_pos)
+static const char *getcb(struct parsing *parsing,
+ const char *key, size_t length,
+ size_t begin_pos, size_t end_pos)
{
- struct parsinfo info;
- const char *result;
- size_t offset;
- struct reading *reading = parsing->data;
- int id;
-
- /* try to find a tzplatform variable */
- id = hashid(key, length);
- if (id >= 0) {
- /* found: try to use it */
- offset = reading->offsets[id];
- if (offset != HNULL)
- result = heap_address( &reading->context->heap, offset);
- else
- result = NULL;
- }
- else {
- /* that is a foreign variable */
- result = foreignvar( reading, key, length);
- }
-
- /* emit the error and then return */
- if (result == NULL) {
- reading->errcount++;
- parse_utf8_info( parsing, &info, begin_pos);
- writerror( "undefined value for %.*s (file %s line %d)",
- length, key, metafilepath, info.lino);
- result = emptystring; /* avoid error of the parser */
- }
- return result;
+ struct parsinfo info;
+ const char *result;
+ size_t offset;
+ struct reading *reading = parsing->data;
+ int id;
+
+ /* try to find a tzplatform variable */
+ id = hashid(key, length);
+ if (id >= 0) {
+ /* found: try to use it */
+ offset = reading->offsets[id];
+ if (offset != HNULL)
+ result = heap_address(&reading->context->heap, offset);
+ else
+ result = NULL;
+ } else {
+ /* that is a foreign variable */
+ result = foreignvar(reading, key, length);
+ }
+
+ /* emit the error and then return */
+ if (result == NULL) {
+ reading->errcount++;
+ parse_utf8_info(parsing, &info, begin_pos);
+ writerror("undefined value for %.*s (file %s line %d)",
+ length, key, metafilepath, info.lino);
+ result = emptystring; /* avoid error of the parser */
+ }
+ return result;
}
/* callback to define variables */
-static int putcb( struct parsing *parsing,
- const char *key, size_t key_length,
- const char *value, size_t value_length,
- size_t begin_pos, size_t end_pos)
+static int putcb(struct parsing *parsing,
+ const char *key, size_t key_length,
+ const char *value, size_t value_length,
+ size_t begin_pos, size_t end_pos)
{
- struct parsinfo info;
- size_t offset;
- char *string;
- struct reading *reading = parsing->data;
- int id;
-
- /* try to find a tzplatform variable */
- id = hashid( key, key_length);
- if (id >= 0) {
- /* check that the variable isn't already defined */
- offset = reading->offsets[id];
- if (offset != HNULL) {
- reading->errcount++;
- parse_utf8_info( parsing, &info, begin_pos);
- writerror( "redefinition of variable %.*s (file %s line %d)",
- key_length, key, metafilepath, info.lino);
- }
-
- /* allocate the variable value */
- offset = heap_alloc( &reading->context->heap, value_length+1);
- if (offset == HNULL) {
- /* error of allocation */
- reading->errcount++;
- writerror( "out of memory");
- }
- else {
- /* record the variable value */
- reading->offsets[id] = offset;
- string = heap_address( &reading->context->heap, offset);
- memcpy( string, value, value_length);
- string[value_length] = 0;
- }
- }
- else {
- /* forbidden variable */
- parse_utf8_info( parsing, &info, begin_pos);
- writerror( "forbidden variable name %.*s (file %s line %d)",
- key_length, key, metafilepath, info.lino);
-
- }
-
- /* continue to parse */
- return 0;
+ struct parsinfo info;
+ size_t offset;
+ char *string;
+ struct reading *reading = parsing->data;
+ int id;
+
+ /* try to find a tzplatform variable */
+ id = hashid(key, key_length);
+ if (id >= 0) {
+ /* check that the variable isn't already defined */
+ offset = reading->offsets[id];
+ if (offset != HNULL) {
+ reading->errcount++;
+ parse_utf8_info(parsing, &info, begin_pos);
+ writerror("redefinition of variable %.*s (file %s line %d)",
+ key_length, key, metafilepath, info.lino);
+ }
+
+ /* allocate the variable value */
+ offset = heap_alloc(&reading->context->heap, value_length+1);
+ if (offset == HNULL) {
+ /* error of allocation */
+ reading->errcount++;
+ writerror("out of memory");
+ } else {
+ /* record the variable value */
+ reading->offsets[id] = offset;
+ string = heap_address(&reading->context->heap, offset);
+ memcpy(string, value, value_length);
+ string[value_length] = 0;
+ }
+ } else {
+ /* forbidden variable */
+ parse_utf8_info(parsing, &info, begin_pos);
+ writerror("forbidden variable name %.*s (file %s line %d)",
+ key_length, key, metafilepath, info.lino);
+ }
+
+ /* continue to parse */
+ return 0;
}
/* initialize the environment */
void initialize(struct tzplatform_context *context)
{
- struct buffer buffer;
- struct parsing parsing;
- struct reading reading;
- size_t offset;
- int i, result;
-
- /* clear the variables */
- reading.errcount = 0;
- reading.context = context;
- for (i = 0 ; i < (int)_FOREIGN_COUNT_ ; i++) {
- reading.dynvars[i] = HNULL;
- }
- for (i = 0 ; i < (int)_TZPLATFORM_VARIABLES_COUNT_ ; i++) {
- context->values[i] = NULL;
- reading.offsets[i] = HNULL;
- }
-
- /* read the configuration file */
- result = buffer_create( &buffer, metafilepath);
- if (result != 0) {
- writerror( "can't read file %s",metafilepath);
- context->state = ERROR;
- return;
- }
-
- /* create the heap */
- result = heap_create( &context->heap, 1);
- if (result != 0) {
- buffer_destroy( &buffer);
- writerror( "out of memory");
- context->state = ERROR;
- return;
- }
-
- /* read the file */
- parsing.buffer = buffer.buffer;
- parsing.length = buffer.length;
- parsing.maximum_data_size = 0;
- parsing.should_escape = 0;
- parsing.data = &reading;
- parsing.get = getcb;
- parsing.put = putcb;
- parsing.error = errcb;
- result = parse_utf8_config( &parsing);
- buffer_destroy( &buffer);
- if (result != 0 || reading.errcount != 0) {
- writerror( "%d errors while parsing file %s",
- reading.errcount, metafilepath);
- }
-
- /* set the variables */
- heap_read_only( &context->heap);
- for (i = 0 ; i < (int)_TZPLATFORM_VARIABLES_COUNT_ ; i++) {
- offset = reading.offsets[i];
- if (offset != HNULL)
- context->values[i] = heap_address( &context->heap, offset);
- else
- writerror( "the variable %s isn't defined in file %s",
- keyname(i), metafilepath);
- /* TODO undefined variable */;
- }
- context->state = VALID;
+ struct buffer buffer;
+ struct parsing parsing;
+ struct reading reading;
+ size_t offset;
+ int i, result;
+
+ /* clear the variables */
+ reading.errcount = 0;
+ reading.context = context;
+ for (i = 0 ; i < (int)_FOREIGN_COUNT_ ; i++)
+ reading.dynvars[i] = HNULL;
+
+ for (i = 0 ; i < (int)_TZPLATFORM_VARIABLES_COUNT_ ; i++) {
+ context->values[i] = NULL;
+ reading.offsets[i] = HNULL;
+ }
+
+ /* read the configuration file */
+ result = buffer_create(&buffer, metafilepath);
+ if (result != 0) {
+ writerror("can't read file %s", metafilepath);
+ context->state = ERROR;
+ return;
+ }
+
+ /* create the heap */
+ result = heap_create(&context->heap, 1);
+ if (result != 0) {
+ buffer_destroy(&buffer);
+ writerror("out of memory");
+ context->state = ERROR;
+ return;
+ }
+
+ /* read the file */
+ parsing.buffer = buffer.buffer;
+ parsing.length = buffer.length;
+ parsing.maximum_data_size = 0;
+ parsing.should_escape = 0;
+ parsing.data = &reading;
+ parsing.get = getcb;
+ parsing.put = putcb;
+ parsing.error = errcb;
+ result = parse_utf8_config(&parsing);
+ buffer_destroy(&buffer);
+ if (result != 0 || reading.errcount != 0) {
+ writerror("%d errors while parsing file %s",
+ reading.errcount, metafilepath);
+ }
+
+ /* set the variables */
+ heap_read_only(&context->heap);
+ for (i = 0 ; i < (int)_TZPLATFORM_VARIABLES_COUNT_ ; i++) {
+ offset = reading.offsets[i];
+ if (offset != HNULL)
+ context->values[i] = heap_address(&context->heap, offset);
+ else
+ writerror("the variable %s isn't defined in file %s",
+ keyname(i), metafilepath);
+ /* TODO undefined variable */;
+ }
+ context->state = VALID;
}
diff --git a/src/init.h b/src/init.h
index 6ed0f15..fe626e2 100644
--- a/src/init.h
+++ b/src/init.h
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013-2014 Intel Corporation.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
diff --git a/src/isadmin.c b/src/isadmin.c
index f62a449..ebe98ad 100644
--- a/src/isadmin.c
+++ b/src/isadmin.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013 Intel Corporation.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
@@ -16,17 +16,17 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors:
- * Stephen Clymans <stephen.clymans@open.eurogiciel.org>
+ * Stephen Clymans <stephen.clymans@open.eurogiciel.org>
*/
-
+
/*
* DISCLAIMER :
- * This source file and its associated header are present to maintain a
+ * This source file and its associated header are present to maintain a
* temporary solution. We need to know if an user have the privilege for
* a particular action.
- *
+ *
* At the end, this feature will be managed by Cynara
- *
+ *
*/
#include <stdio.h>
@@ -40,8 +40,8 @@
#include "tzplatform_variables.h"
#include "tzplatform_config.h"
-int _has_system_group_static_(uid_t uid) {
-
+int _has_system_group_static_(uid_t uid)
+{
struct passwd pwd, *userinfo = NULL;
struct group grp, *systemgroupinfo = NULL;
const char *sysgrpname = NULL;
@@ -50,55 +50,54 @@ int _has_system_group_static_(uid_t uid) {
gid_t system_gid = 0;
gid_t *groups = NULL;
int i, nbgroups = 0;
-
-
- if(uid == -1)
+
+ if (uid == -1)
/* Get current uid */
myuid = getuid();
else
myuid = uid;
-
+
/* Get the gid of the group named "system" */
sysgrpname = tzplatform_getname(TZ_SYS_ADMIN_GROUP);
- if(sysgrpname == NULL) {
- fprintf( stderr, "isadmin ERROR: variable TZ_SYS_ADMIN_GROUP is NULL");
+ if (sysgrpname == NULL) {
+ fprintf(stderr, "isadmin ERROR: variable TZ_SYS_ADMIN_GROUP is NULL");
return -1;
}
getgrnam_r(sysgrpname, &grp, buf, sizeof(buf), &systemgroupinfo);
- if(systemgroupinfo == NULL) {
- fprintf( stderr, "isadmin ERROR: cannot find group named \"%s\"\n", sysgrpname);
+ if (systemgroupinfo == NULL) {
+ fprintf(stderr, "isadmin ERROR: cannot find group named \"%s\"\n", sysgrpname);
return -1;
}
-
+
system_gid = systemgroupinfo->gr_gid;
-
+
/* Get all the gid of the given uid */
-
+
getpwuid_r(myuid, &pwd, buf, sizeof(buf), &userinfo);
-
+
/* Need to call this function now to get the number of group to make the
malloc correctly sized */
if (getgrouplist(userinfo->pw_name, userinfo->pw_gid, groups, &nbgroups) != -1) {
- fprintf( stderr, "isadmin ERROR: cannot get number of groups\n");
+ fprintf(stderr, "isadmin ERROR: cannot get number of groups\n");
return -1;
}
-
- groups = malloc(nbgroups * sizeof (gid_t));
+
+ groups = malloc(nbgroups * sizeof(gid_t));
if (groups == NULL) {
- fprintf( stderr, "isadmin ERROR: malloc cannot allocate memory\n");
+ fprintf(stderr, "isadmin ERROR: malloc cannot allocate memory\n");
return -1;
}
-
+
if (getgrouplist(userinfo->pw_name, userinfo->pw_gid, groups, &nbgroups) == -1) {
free(groups);
- fprintf( stderr, "isadmin ERROR: cannot get groups\n");
+ fprintf(stderr, "isadmin ERROR: cannot get groups\n");
return -1;
}
-
+
/* Check if the given uid is in the system group */
-
- for(i = 0 ; i < nbgroups ; i++) {
- if(groups[i] == system_gid) {
+
+ for (i = 0 ; i < nbgroups ; i++) {
+ if (groups[i] == system_gid) {
free(groups);
return 1;
}
diff --git a/src/isadmin.h b/src/isadmin.h
index 25ebd75..c7c2525 100644
--- a/src/isadmin.h
+++ b/src/isadmin.h
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013 Intel Corporation.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
@@ -16,29 +16,29 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors:
- * Stephen Clymans <stephen.clymans@open.eurogiciel.org>
+ * Stephen Clymans <stephen.clymans@open.eurogiciel.org>
*/
#ifdef __cplusplus
extern "C" {
#endif
-
+
#ifndef TIZEN_PLATFORM_WRAPPER_ISADMIN_H
#define TIZEN_PLATFORM_WRAPPER_ISADMIN_H
/*
* DISCLAIMER :
- * This header and its associated source file are present to maintain a
+ * This header and its associated source file are present to maintain a
* temporary solution. We need to know if an user have the privilege for
* a particular action.
- *
+ *
* At the end, this feature will be managed by Cynara
- *
+ *
*/
/*
* Return 0 if the given uid is not in the admin group.
* Return 1 if the given uid is in the admin group.
- *
+ *
* If you pass the -1 value to this function it will take the current uid given
* by the POSIX function getuid();
*/
@@ -48,5 +48,5 @@ int _has_system_group_static_(uid_t uid);
}
#endif
-#endif /* TIZEN_PLATFORM_WRAPPER_ISADMIN_H */
+#endif /* TIZEN_PLATFORM_WRAPPER_ISADMIN_H */
diff --git a/src/parser.c b/src/parser.c
index fa8d94d..ff480b6 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013-2014 Intel Corporation.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
@@ -16,9 +16,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors:
- * José Bollo <jose.bollo@open.eurogiciel.org>
- * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
- * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
+ * José Bollo <jose.bollo@open.eurogiciel.org>
+ * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
+ * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
*
*/
#define _GNU_SOURCE
@@ -34,241 +34,240 @@
#include "parser.h"
#ifndef MINIMUM_DATA_SIZE
-# define MINIMUM_DATA_SIZE 128
+# define MINIMUM_DATA_SIZE 128
#endif
#ifndef DEFAULT_MAXIMUM_DATA_SIZE
-# define DEFAULT_MAXIMUM_DATA_SIZE 32768
+# define DEFAULT_MAXIMUM_DATA_SIZE 32768
#endif
#ifndef _
# define _(x) x
#endif
-int parse_utf8_config( struct parsing *parsing)
+int parse_utf8_config(struct parsing *parsing)
{
- char c, q, acc, overflow, escape;
- char *bdata;
- const char *value, *head, *end, *skey, *svar, *bvar;
- size_t lkey, lvar, ldata, datasz;
- int errors;
-
-#define iskeybeg(x) (isalpha(x)||(x)=='_')
-#define iskey(x) (isalnum(x)||(x)=='_')
-#define atend ((head-end) >= 0)
-
-#define pos(x) ((size_t)((x)-parsing->buffer))
-#define error(p,x) do{ errors++; \
- if(parsing->error \
- && !parsing->error(parsing,pos(p),x)) \
- goto stop; \
- }while(0)
-
- /* alloc data buffer */
- datasz = parsing->maximum_data_size;
- if (datasz == 0)
- datasz = DEFAULT_MAXIMUM_DATA_SIZE;
- else if (datasz < MINIMUM_DATA_SIZE)
- datasz = MINIMUM_DATA_SIZE;
- bdata = alloca(datasz);
-
- /* init */
- escape = parsing->should_escape ? 1 : 0;
- errors = 0;
- head = parsing->buffer;
- end = head + parsing->length;
- goto initial;
+ char c, q, acc, overflow, escape;
+ char *bdata;
+ const char *value, *head, *end, *skey, *svar, *bvar;
+ size_t lkey, lvar, ldata, datasz;
+ int errors;
+
+#define iskeybeg(x) (isalpha(x) || (x) == '_')
+#define iskey(x) (isalnum(x) || (x) == '_')
+#define atend ((head-end) >= 0)
+
+#define pos(x) ((size_t)((x)-parsing->buffer))
+#define error(p, x) do { errors++; \
+ if (parsing->error \
+ && !parsing->error(parsing, pos(p), x)) \
+ goto stop; \
+ } while (0)
+
+ /* alloc data buffer */
+ datasz = parsing->maximum_data_size;
+ if (datasz == 0)
+ datasz = DEFAULT_MAXIMUM_DATA_SIZE;
+ else if (datasz < MINIMUM_DATA_SIZE)
+ datasz = MINIMUM_DATA_SIZE;
+ bdata = alloca(datasz);
+
+ /* init */
+ escape = parsing->should_escape ? 1 : 0;
+ errors = 0;
+ head = parsing->buffer;
+ end = head + parsing->length;
+ goto initial;
next_initial:
- head++;
+ head++;
initial: /* expecting key, comment or ??? */
- if (atend)
- goto end_ok;
+ if (atend)
+ goto end_ok;
- c = *head;
+ c = *head;
- if (iskeybeg(c)) {
- skey = head;
- goto key;
- }
+ if (iskeybeg(c)) {
+ skey = head;
+ goto key;
+ }
- if (c == '#')
- goto comment;
+ if (c == '#')
+ goto comment;
- if (!isspace(c))
- error(head,_("unexpected character while looking to a key start"));
+ if (!isspace(c))
+ error(head, _("unexpected character while looking to a key start"));
- goto next_initial;
+ goto next_initial;
comment: /* skipping a comment */
- head++;
- if (atend)
- goto end_ok;
- c = *head;
- if (c == '\n')
- goto next_initial;
- goto comment;
+ head++;
+ if (atend)
+ goto end_ok;
+ c = *head;
+ if (c == '\n')
+ goto next_initial;
+ goto comment;
key: /* reading a key */
- head++;
- if (atend) {
- error(head,_("end in a key"));
- goto stop;
- }
- c = *head;
- if (iskey(c))
- goto key;
- if (c != '=') {
- error(head,_("unexpected character while looking to ="));
- goto next_initial;
- }
- lkey = head - skey;
- overflow = ldata = 0;
- q = 0;
- goto next_value;
+ head++;
+ if (atend) {
+ error(head, _("end in a key"));
+ goto stop;
+ }
+ c = *head;
+ if (iskey(c))
+ goto key;
+ if (c != '=') {
+ error(head, _("unexpected character while looking to ="));
+ goto next_initial;
+ }
+ lkey = head - skey;
+ overflow = ldata = 0;
+ q = 0;
+ goto next_value;
escapable:
- if (escape && ldata < datasz)
- bdata[ldata++] = '\\';
+ if (escape && ldata < datasz)
+ bdata[ldata++] = '\\';
add_value: /* add the current char to data */
- if (ldata < datasz)
- bdata[ldata++] = c;
- else
- overflow = 1;
+ if (ldata < datasz)
+ bdata[ldata++] = c;
+ else
+ overflow = 1;
next_value:
- head++;
+ head++;
value: /* reading the value */
- if (atend) {
- /* end in the value */
- if (!q)
- goto end_of_value;
-
- error(head,_("end in quoted value"));
- goto stop;
- }
-
- c = *head;
- switch (c) {
-
- case '\\':
- if (q == '\'')
- goto escapable;
- ++head;
- if (atend) {
- error(head,_("end after escape char"));
- goto stop;
- }
- c = *head;
- goto escapable;
-
- case '\'':
- if (q == '"')
- goto escapable;
- q = q ^ c;
- goto next_value;
-
- case '"':
- if (q == '\'')
- goto escapable;
- q = q ^ c;
- goto next_value;
-
- case '$':
- if (q == '\'')
- goto escapable;
-
- /* begin of a variable, just after $ */
- bvar = head++;
- if (atend) {
- error(head,_("end after $"));
- goto stop;
- }
- c = *head;
- acc = c;
- if (c == '{') {
- ++head;
- if (atend) {
- error(head,_("end after ${"));
- goto stop;
- }
- c = *head;
- }
- if (!iskeybeg(c)) {
- error(head,_("invalid character after $ or ${"));
- goto value;
- }
- svar = head;
- goto variable;
-
- default:
- if (q || !isspace(c))
- goto add_value;
-
- goto end_of_value;
- }
+ if (atend) {
+ /* end in the value */
+ if (!q)
+ goto end_of_value;
+
+ error(head, _("end in quoted value"));
+ goto stop;
+ }
+
+ c = *head;
+ switch (c) {
+
+ case '\\':
+ if (q == '\'')
+ goto escapable;
+ ++head;
+ if (atend) {
+ error(head, _("end after escape char"));
+ goto stop;
+ }
+ c = *head;
+ goto escapable;
+
+ case '\'':
+ if (q == '"')
+ goto escapable;
+ q = q ^ c;
+ goto next_value;
+
+ case '"':
+ if (q == '\'')
+ goto escapable;
+ q = q ^ c;
+ goto next_value;
+
+ case '$':
+ if (q == '\'')
+ goto escapable;
+
+ /* begin of a variable, just after $ */
+ bvar = head++;
+ if (atend) {
+ error(head, _("end after $"));
+ goto stop;
+ }
+ c = *head;
+ acc = c;
+ if (c == '{') {
+ ++head;
+ if (atend) {
+ error(head, _("end after ${"));
+ goto stop;
+ }
+ c = *head;
+ }
+ if (!iskeybeg(c)) {
+ error(head, _("invalid character after $ or ${"));
+ goto value;
+ }
+ svar = head;
+ goto variable;
+
+ default:
+ if (q || !isspace(c))
+ goto add_value;
+
+ goto end_of_value;
+ }
end_of_value: /* end of the value */
- if (overflow)
- error(head,_("value too big"));
- else if (parsing->put)
- parsing->put( parsing, skey, lkey, bdata, ldata, pos(skey), pos(head));
- if (atend)
- goto initial;
- goto next_initial;
+ if (overflow)
+ error(head, _("value too big"));
+ else if (parsing->put)
+ parsing->put(parsing, skey, lkey, bdata, ldata, pos(skey), pos(head));
+ if (atend)
+ goto initial;
+ goto next_initial;
variable: /* read a variable */
- ++head;
- if (atend) {
- if (acc == '{')
- error(head,_("unmatched pair { }"));
- lvar = head - svar;
- }
- else {
- c = *head;
- if (iskey(c))
- goto variable;
- lvar = head - svar;
- if (acc == '{') {
- if (c == '}')
- ++head;
- else
- error(head,_("unmatched pair { }"));
- }
- }
- if (parsing->get) {
- value = parsing->get( parsing, svar,lvar,pos(bvar),pos(head));
- if (value == NULL)
- error(bvar,_("no value for the variable"));
- else {
- while (*value) {
- if (ldata < datasz)
- bdata[ldata++] = *value++;
- else {
- overflow = 1;
- break;
- }
- }
- }
- }
- goto value;
+ ++head;
+ if (atend) {
+ if (acc == '{')
+ error(head, _("unmatched pair { }"));
+ lvar = head - svar;
+ } else {
+ c = *head;
+ if (iskey(c))
+ goto variable;
+ lvar = head - svar;
+ if (acc == '{') {
+ if (c == '}')
+ ++head;
+ else
+ error(head, _("unmatched pair { }"));
+ }
+ }
+ if (parsing->get) {
+ value = parsing->get(parsing, svar, lvar, pos(bvar), pos(head));
+ if (value == NULL)
+ error(bvar, _("no value for the variable"));
+ else {
+ while (*value) {
+ if (ldata < datasz)
+ bdata[ldata++] = *value++;
+ else {
+ overflow = 1;
+ break;
+ }
+ }
+ }
+ }
+ goto value;
stop:
end_ok:
- return -errors;
-
+ return -errors;
+
#undef error
#undef pos
#undef atend
@@ -277,43 +276,43 @@ end_ok:
}
void parse_utf8_info(
- struct parsing *parsing,
- struct parsinfo *info,
- size_t pos
+ struct parsing *parsing,
+ struct parsinfo *info,
+ size_t pos
)
{
- const char *buf, *begin, *end;
- size_t length;
- int lino, colno;
-
- /* init */
- lino = 1, colno = 1;
- buf = begin = end = parsing->buffer;
- length = parsing->length;
- if (length < pos)
- pos = length;
-
- /* search the begin of the line */
- while ((end - buf) != pos) {
- /* dealing utf8 */
- colno += ((*end & '\xc0') != '\x80');
- /* dealing with lines */
- if(*end++ == '\n') {
- begin = end;
- lino++;
- colno = 1;
- }
- }
-
- /* search the end of the line */
- while ((end - buf) < length && *end != '\n')
- end++;
-
- /* record computed values */
- info->begin = begin;
- info->end = end;
- info->length = end - begin;
- info->lino = lino;
- info->colno = colno;
+ const char *buf, *begin, *end;
+ size_t length;
+ int lino, colno;
+
+ /* init */
+ lino = 1, colno = 1;
+ buf = begin = end = parsing->buffer;
+ length = parsing->length;
+ if (length < pos)
+ pos = length;
+
+ /* search the begin of the line */
+ while ((end - buf) != pos) {
+ /* dealing utf8 */
+ colno += ((*end & '\xc0') != '\x80');
+ /* dealing with lines */
+ if (*end++ == '\n') {
+ begin = end;
+ lino++;
+ colno = 1;
+ }
+ }
+
+ /* search the end of the line */
+ while ((end - buf) < length && *end != '\n')
+ end++;
+
+ /* record computed values */
+ info->begin = begin;
+ info->end = end;
+ info->length = end - begin;
+ info->lino = lino;
+ info->colno = colno;
}
diff --git a/src/parser.h b/src/parser.h
index 0ee30e8..0665098 100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013-2014 Intel Corporation.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
@@ -16,9 +16,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors:
- * José Bollo <jose.bollo@open.eurogiciel.org>
- * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
- * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
+ * José Bollo <jose.bollo@open.eurogiciel.org>
+ * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
+ * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
*
*/
#ifndef TIZEN_PLATFORM_WRAPPER_PARSER_H
@@ -27,70 +27,70 @@
/* structure used for parsing config files */
struct parsing {
- /* The buffer to parse. */
- const char *buffer;
+ /* The buffer to parse. */
+ const char *buffer;
- /* The length of the buffer to parse. */
- size_t length;
+ /* The length of the buffer to parse. */
+ size_t length;
- /* The maximum data size allowed */
- size_t maximum_data_size;
+ /* The maximum data size allowed */
+ size_t maximum_data_size;
- /* Some user data, please use it as you wish. */
- void * data;
+ /* Some user data, please use it as you wish. */
+ void * data;
- /* Should escape the key values (inserting \ where needed) */
- int should_escape;
+ /* Should escape the key values (inserting \ where needed) */
+ int should_escape;
- /*
- Callback function to resolve the variables.
- Should return the value of the variable of 'key' that
- length is 'length' without terminating zero.
- */
- const char *(*get)( struct parsing *parsing,
- const char *key, size_t length,
- size_t begin_pos, size_t end_pos);
+ /*
+ Callback function to resolve the variables.
+ Should return the value of the variable of 'key' that
+ length is 'length' without terminating zero.
+ */
+ const char *(*get)(struct parsing *parsing,
+ const char *key, size_t length,
+ size_t begin_pos, size_t end_pos);
- /*
- Callback function to receive new values.
- Should add/insert/replace the key/value pair
- given. This values aren't zero terminated.
- The given length is the one without terminating nul.
- */
- int (*put)( struct parsing *parsing,
- const char *key, size_t key_length,
- const char *value, size_t value_length,
- size_t begin_pos, size_t end_pos);
+ /*
+ Callback function to receive new values.
+ Should add/insert/replace the key/value pair
+ given. This values aren't zero terminated.
+ The given length is the one without terminating nul.
+ */
+ int (*put)(struct parsing *parsing,
+ const char *key, size_t key_length,
+ const char *value, size_t value_length,
+ size_t begin_pos, size_t end_pos);
- /*
- Callback function to report errors.
- 'buffer' is the scanned buffer.
- 'position' is the position of the character raising the error.
- 'message' is a short explanation of the error.
- Should return 0 to stop parsing;
- */
- int (*error)( struct parsing *parsing,
- size_t position, const char *message);
+ /*
+ Callback function to report errors.
+ 'buffer' is the scanned buffer.
+ 'position' is the position of the character raising the error.
+ 'message' is a short explanation of the error.
+ Should return 0 to stop parsing;
+ */
+ int (*error)(struct parsing *parsing,
+ size_t position, const char *message);
};
/*
- Parse the config file using data of 'parsing'.
+ Parse the config file using data of 'parsing'.
Return 0 if not error found or a negative number
- corresponding to the opposite of the count of found errors
+ corresponding to the opposite of the count of found errors
(ex: -5 means 5 errors).
Note: works on utf8 data.
*/
int parse_utf8_config(
- struct parsing *parsing
+ struct parsing *parsing
);
/* Structure for getting information about a position. */
struct parsinfo {
- const char *begin; /* pointer to the first char of the line */
- const char *end; /* pointer to the char just after the end of the line */
- size_t length; /* length of the line (== end-begin) */
- int lino; /* number of the line within the buffer */
- int colno; /* number of the column within the line */
+ const char *begin; /* pointer to the first char of the line */
+ const char *end; /* pointer to the char just after the end of the line */
+ size_t length; /* length of the line (== end-begin) */
+ int lino; /* number of the line within the buffer */
+ int colno; /* number of the column within the line */
};
/*
@@ -102,9 +102,9 @@ struct parsinfo {
Note: works on utf8 data.
*/
void parse_utf8_info(
- struct parsing *parsing,
- struct parsinfo *info,
- size_t pos
+ struct parsing *parsing,
+ struct parsinfo *info,
+ size_t pos
);
diff --git a/src/passwd.c b/src/passwd.c
index 287d375..325cc30 100644
--- a/src/passwd.c
+++ b/src/passwd.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013-2014 Intel Corporation.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
@@ -16,9 +16,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors:
- * José Bollo <jose.bollo@open.eurogiciel.org>
- * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
- * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
+ * José Bollo <jose.bollo@open.eurogiciel.org>
+ * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
+ * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
*
*/
#define _GNU_SOURCE
@@ -47,139 +47,138 @@ static struct buffer buffer;
static size_t pos, lengths[7];
static const char *starts[7];
-#define is(s,i) (!strncmp(s,starts[i],lengths[i]) && !s[lengths[i]])
+#define is(s, i) (!strncmp(s, starts[i], lengths[i]) && !s[lengths[i]])
/* open the passwd file */
static int oppw()
{
- pos = 0;
- return buffer_create( &buffer, pwfile);
+ pos = 0;
+ return buffer_create(&buffer, pwfile);
}
/* close the passwd file */
static void clpw()
{
- buffer_destroy( &buffer);
+ buffer_destroy(&buffer);
}
/* read the passwd file */
static int rdpw()
{
- int col = 0;
- const char *head = buffer.buffer + pos;
- const char *end = buffer.buffer + buffer.length;
- while (head != end) {
- starts[col] = head;
- while(head!=end && *head!=':' && *head!='\n') head++;
- lengths[col] = head - starts[col];
- col++;
- if (col == 7) {
- if (head==end) {
- pos = head - buffer.buffer;
- return 1;
- }
- if (*head=='\n') {
- head++;
- pos = head - buffer.buffer;
- return 1;
- }
- while (head!=end && *head!='\n') head++;
- if (head!=end) head++;
- col = 0;
- }
- else {
- if (head != end) {
- if (*head++=='\n')
- col = 0;
- }
- }
- }
- pos = head - buffer.buffer;
- return 0;
+ int col = 0;
+ const char *head = buffer.buffer + pos;
+ const char *end = buffer.buffer + buffer.length;
+ while (head != end) {
+ starts[col] = head;
+ while (head != end && *head != ':' && *head != '\n') head++;
+ lengths[col] = head - starts[col];
+ col++;
+ if (col == 7) {
+ if (head == end) {
+ pos = head - buffer.buffer;
+ return 1;
+ }
+ if (*head == '\n') {
+ head++;
+ pos = head - buffer.buffer;
+ return 1;
+ }
+ while (head != end && *head != '\n') head++;
+ if (head != end) head++;
+ col = 0;
+ } else {
+ if (head != end) {
+ if (*head++ == '\n')
+ col = 0;
+ }
+ }
+ }
+ pos = head - buffer.buffer;
+ return 0;
}
-int pw_get( struct heap *heap, struct pwget **items)
+int pw_get(struct heap *heap, struct pwget **items)
{
- size_t user, home;
- int result;
- int i, n, s;
+ size_t user, home;
+ int result;
+ int i, n, s;
- for( n = 0 ; items[n] != NULL ; n++ )
- items[n]->set = 0;
+ for (n = 0 ; items[n] != NULL ; n++)
+ items[n]->set = 0;
- result = oppw();
- if (result == 0) {
- s = n;
- while (s && rdpw()) {
- user = home = HNULL;
- for( i = 0 ; i < n ; i++ ) {
- if (!items[i]->set && is(items[i]->id,iuid)) {
- if (user==HNULL) {
- user = heap_strndup( heap,
- starts[iname], lengths[iname]);
- home = heap_strndup( heap,
- starts[idir], lengths[idir]);
- }
- items[i]->set = 1;
- items[i]->user = user;
- items[i]->home = home;
- s--;
- }
- }
- }
- clpw();
- }
- return result;
+ result = oppw();
+ if (result == 0) {
+ s = n;
+ while (s && rdpw()) {
+ user = home = HNULL;
+ for (i = 0 ; i < n ; i++) {
+ if (!items[i]->set && is(items[i]->id, iuid)) {
+ if (user == HNULL) {
+ user = heap_strndup(heap,
+ starts[iname], lengths[iname]);
+ home = heap_strndup(heap,
+ starts[idir], lengths[idir]);
+ }
+ items[i]->set = 1;
+ items[i]->user = user;
+ items[i]->home = home;
+ s--;
+ }
+ }
+ }
+ clpw();
+ }
+ return result;
}
-int pw_has_uid( uid_t uid)
+int pw_has_uid(uid_t uid)
{
- if (oppw() == 0) {
- while (rdpw()) {
- if (lengths[iuid] && (int)uid == atoi(starts[iuid])) {
- clpw();
- return 1;
- }
- }
- clpw();
- }
- return 0;
+ if (oppw() == 0) {
+ while (rdpw()) {
+ if (lengths[iuid] && (int)uid == atoi(starts[iuid])) {
+ clpw();
+ return 1;
+ }
+ }
+ clpw();
+ }
+ return 0;
}
-int pw_get_uid( const char *name, uid_t *uid)
+int pw_get_uid(const char *name, uid_t *uid)
{
- int result = oppw();
- if (result == 0) {
- while (rdpw()) {
- if (is(name,iname)) {
- *uid = (uid_t)atoi(starts[iuid]);
- clpw();
- return 0;
- }
- }
- clpw();
- result = -1;
- errno = EEXIST;
- }
- return result;
+ int result = oppw();
+ if (result == 0) {
+ while (rdpw()) {
+ if (is(name, iname)) {
+ *uid = (uid_t)atoi(starts[iuid]);
+ clpw();
+ return 0;
+ }
+ }
+ clpw();
+ result = -1;
+ errno = EEXIST;
+ }
+ return result;
}
-int pw_get_gid( const char *name, gid_t *gid)
+int pw_get_gid(const char *name, gid_t *gid)
{
- int result = oppw();
- if (result == 0) {
- while (rdpw()) {
- if (is(name,iname)) {
- *gid = (gid_t)atoi(starts[igid]);
- clpw();
- return 0;
- }
- }
- clpw();
- result = -1;
- errno = EEXIST;
- }
- return result;
+ int result = oppw();
+ if (result == 0) {
+ while (rdpw()) {
+ if (is(name, iname)) {
+ *gid = (gid_t)atoi(starts[igid]);
+ clpw();
+ return 0;
+ }
+ }
+ clpw();
+ result = -1;
+ errno = EEXIST;
+ }
+ return result;
}
#else
@@ -188,116 +187,113 @@ int pw_get_gid( const char *name, gid_t *gid)
#define BUFSIZE 4096
-int pw_get( struct heap *heap, struct pwget **items)
+int pw_get(struct heap *heap, struct pwget **items)
{
- char buffer[BUFSIZE];
- struct passwd entry, *pe;
- int result;
- int n;
- uid_t id;
+ char buffer[BUFSIZE];
+ struct passwd entry, *pe;
+ int result;
+ int n;
+ uid_t id;
- for( n = 0 ; items[n] != NULL ; n++ ) {
- id = (uid_t)atoi(items[n]->id);
- result = getpwuid_r( id, &entry, buffer, sizeof buffer, &pe);
- if (result != 0) {
- while(items[n] != NULL) items[n++]->set = 0;
- return result;
- }
- if (pe == NULL)
- items[n]->set = 0;
- else {
- items[n]->set = 1;
- items[n]->user = heap_strdup( heap, pe->pw_name);
- items[n]->home = heap_strdup( heap, pe->pw_dir);
- }
- }
- return 0;
+ for (n = 0 ; items[n] != NULL ; n++) {
+ id = (uid_t)atoi(items[n]->id);
+ result = getpwuid_r(id, &entry, buffer, sizeof buffer, &pe);
+ if (result != 0) {
+ while (items[n] != NULL) items[n++]->set = 0;
+ return result;
+ }
+ if (pe == NULL)
+ items[n]->set = 0;
+ else {
+ items[n]->set = 1;
+ items[n]->user = heap_strdup(heap, pe->pw_name);
+ items[n]->home = heap_strdup(heap, pe->pw_dir);
+ }
+ }
+ return 0;
}
-int pw_has_uid( uid_t uid)
+int pw_has_uid(uid_t uid)
{
- char buffer[BUFSIZE];
- struct passwd entry, *pe;
- int result;
+ char buffer[BUFSIZE];
+ struct passwd entry, *pe;
+ int result;
- result = getpwuid_r( uid, &entry, buffer, sizeof buffer, &pe);
- return !result && pe;
+ result = getpwuid_r(uid, &entry, buffer, sizeof buffer, &pe);
+ return !result && pe;
}
-int pw_get_uid( const char *name, uid_t *uid)
+int pw_get_uid(const char *name, uid_t *uid)
{
- char buffer[BUFSIZE];
- struct passwd entry, *pe;
- int result = getpwnam_r( name, &entry, buffer, sizeof buffer, &pe);
- if (result == 0) {
- if (pe == NULL) {
- errno = EEXIST;
- result = -1;
- }
- else {
- *uid = entry.pw_uid;
- }
- }
- return result;
+ char buffer[BUFSIZE];
+ struct passwd entry, *pe;
+ int result = getpwnam_r(name, &entry, buffer, sizeof buffer, &pe);
+ if (result == 0) {
+ if (pe == NULL) {
+ errno = EEXIST;
+ result = -1;
+ } else {
+ *uid = entry.pw_uid;
+ }
+ }
+ return result;
}
-int pw_get_gid( const char *name, gid_t *gid)
+int pw_get_gid(const char *name, gid_t *gid)
{
- char buffer[BUFSIZE];
- struct passwd entry, *pe;
- int result = getpwnam_r( name, &entry, buffer, sizeof buffer, &pe);
- if (result == 0) {
- if (pe == NULL) {
- errno = EEXIST;
- result = -1;
- }
- else {
- *gid = entry.pw_gid;
- }
- }
- return result;
+ char buffer[BUFSIZE];
+ struct passwd entry, *pe;
+ int result = getpwnam_r(name, &entry, buffer, sizeof buffer, &pe);
+ if (result == 0) {
+ if (pe == NULL) {
+ errno = EEXIST;
+ result = -1;
+ } else {
+ *gid = entry.pw_gid;
+ }
+ }
+ return result;
}
#endif
#ifdef TEST_PASSWD
#include <stdio.h>
-int main(int argc,char**argv) {
- struct heap heap;
- enum { uid, gid, names } action = uid;
- heap_create(&heap,1000);
- while(*++argv) {
- if (!strcmp(*argv,"-u"))
- action = uid;
- else if (!strcmp(*argv,"-g"))
- action = gid;
- else if (!strcmp(*argv,"-n"))
- action = names;
- else if (action == uid) {
- uid_t u = 0;
- int sts = pw_get_uid( *argv, &u);
- printf("uid(%s)=%d [%d]\n",*argv,(int)u,sts);
- }
- else if (action == gid) {
- gid_t g = 0;
- int sts = pw_get_gid( *argv, &g);
- printf("gid(%s)=%d [%d]\n",*argv,(int)g,sts);
- }
- else if (action == names) {
- struct pwget pw = { .id=*argv }, *ppw[2] = { &pw, NULL };
- int sts = pw_get( &heap, ppw);
- printf("names(%s) set=%d",*argv,pw.set);
- if (pw.set) {
- printf(" name=%s home=%s",
- pw.user==HNULL ? "(null)"
- : (char*)heap_address( &heap, pw.user),
- pw.home==HNULL ? "(null)"
- : (char*)heap_address( &heap, pw.home));
- }
- printf(" [%d]\n",sts);
- }
- }
- return 0;
+int main(int argc, char**argv)
+{
+ struct heap heap;
+ enum { uid, gid, names } action = uid;
+ heap_create(&heap, 1000);
+ while (*++argv) {
+ if (!strcmp(*argv, "-u"))
+ action = uid;
+ else if (!strcmp(*argv, "-g"))
+ action = gid;
+ else if (!strcmp(*argv, "-n"))
+ action = names;
+ else if (action == uid) {
+ uid_t u = 0;
+ int sts = pw_get_uid(*argv, &u);
+ printf("uid(%s)=%d [%d]\n", *argv, (int)u, sts);
+ } else if (action == gid) {
+ gid_t g = 0;
+ int sts = pw_get_gid(*argv, &g);
+ printf("gid(%s)=%d [%d]\n", *argv, (int)g, sts);
+ } else if (action == names) {
+ struct pwget pw = { .id = *argv }, *ppw[2] = { &pw, NULL };
+ int sts = pw_get(&heap, ppw);
+ printf("names(%s) set=%d", *argv, pw.set);
+ if (pw.set) {
+ printf(" name=%s home=%s",
+ pw.user == HNULL ? "(null)"
+ : (char*)heap_address(&heap, pw.user),
+ pw.home == HNULL ? "(null)"
+ : (char*)heap_address(&heap, pw.home));
+ }
+ printf(" [%d]\n", sts);
+ }
+ }
+ return 0;
}
#endif
diff --git a/src/passwd.h b/src/passwd.h
index f9de75c..475ee10 100644
--- a/src/passwd.h
+++ b/src/passwd.h
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013-2014 Intel Corporation.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
@@ -16,25 +16,25 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors:
- * José Bollo <jose.bollo@open.eurogiciel.org>
- * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
- * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
+ * José Bollo <jose.bollo@open.eurogiciel.org>
+ * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
+ * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
*
*/
#ifndef TIZEN_PLATFORM_WRAPPER_PASSWD_H
#define TIZEN_PLATFORM_WRAPPER_PASSWD_H
struct pwget {
- int set;
- const char *id;
- size_t user;
- size_t home;
+ int set;
+ const char *id;
+ size_t user;
+ size_t home;
};
-int pw_get( struct heap *heap, struct pwget **items);
-int pw_get_uid( const char *name, uid_t *uid);
-int pw_get_gid( const char *name, gid_t *gid);
-int pw_has_uid( uid_t uid);
+int pw_get(struct heap *heap, struct pwget **items);
+int pw_get_uid(const char *name, uid_t *uid);
+int pw_get_gid(const char *name, gid_t *gid);
+int pw_has_uid(uid_t uid);
#endif
diff --git a/src/scratch.c b/src/scratch.c
index 6f25b54..0402c04 100644
--- a/src/scratch.c
+++ b/src/scratch.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013-2014 Intel Corporation.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
@@ -16,9 +16,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors:
- * José Bollo <jose.bollo@open.eurogiciel.org>
- * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
- * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
+ * José Bollo <jose.bollo@open.eurogiciel.org>
+ * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
+ * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
*
*/
#define _GNU_SOURCE
@@ -40,9 +40,9 @@
#define INSTANCIATE 1
#if INSTANCIATE
-#define SET_CAPACITY 97
-#define HASHCODE_INIT 5381
-#define HASHCODE_NEXT(H,C) (((H) << 5) + (H) + (C))
+#define SET_CAPACITY 97
+#define HASHCODE_INIT 5381
+#define HASHCODE_NEXT(H, C) (((H) << 5) + (H) + (C))
#endif
#ifndef NOT_MULTI_THREAD_SAFE
@@ -61,9 +61,9 @@ static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
#if INSTANCIATE
/* structure for recording items in the hash map */
struct set_item {
- struct set_item *next; /* chain to next item */
- size_t hashcode; /* hash of the string */
- size_t length; /* length of the string including null */
+ struct set_item *next; /* chain to next item */
+ size_t hashcode; /* hash of the string */
+ size_t length; /* length of the string including null */
};
/* the array of recorded strings */
@@ -74,165 +74,164 @@ is granted to have the 'length' including terminating null and a
hash code 'hashcode' */
static const char *instantiate(const char *string, size_t length, size_t hashcode)
{
- struct set_item **pp, *item;
- char *result;
-
- /* get first item in the table */
- pp = &global_path_set[hashcode % SET_CAPACITY];
- result = 0;
- do {
- /* inspect the item */
- item = *pp;
- if (!item) {
- /* no item: create it */
- item = malloc(length + sizeof * item);
- if (!item)
- return NULL;
- /* init it */
- item->next = 0;
- item->hashcode = hashcode;
- item->length = length;
- result = (char *)(item + 1);
- memcpy(result, string, length);
- /* record it */
- *pp = item;
- } else if (item->hashcode == hashcode
- && item->length == length
- && 0 == strcmp(string, (const char *)(item + 1))) {
- /* item found */
- result = (char *)(item + 1);
- } else {
- /* try the next */
- pp = &item->next;
- }
- } while (!result);
-
- return result;
+ struct set_item **pp, *item;
+ char *result;
+
+ /* get first item in the table */
+ pp = &global_path_set[hashcode % SET_CAPACITY];
+ result = 0;
+ do {
+ /* inspect the item */
+ item = *pp;
+ if (!item) {
+ /* no item: create it */
+ item = malloc(length + sizeof * item);
+ if (!item)
+ return NULL;
+ /* init it */
+ item->next = 0;
+ item->hashcode = hashcode;
+ item->length = length;
+ result = (char *)(item + 1);
+ memcpy(result, string, length);
+ /* record it */
+ *pp = item;
+ } else if (item->hashcode == hashcode
+ && item->length == length
+ && 0 == strcmp(string, (const char *)(item + 1))) {
+ /* item found */
+ result = (char *)(item + 1);
+ } else {
+ /* try the next */
+ pp = &item->next;
+ }
+ } while (!result);
+
+ return result;
}
#endif
/* CAUTION: in a multitheaded context, it is expected that
-=========== the function scratchcat is call under a mutex.
-If it is not the case please check for initializing 'tlskey'
+=========== the function scratchcat is call under a mutex.
+If it is not the case please check for initializing 'tlskey'
only one time before use of it. */
#if INSTANCIATE && !defined(NOT_MULTI_THREAD_SAFE)
-static const char *_scratchcat( int ispath, const char **strings);
+static const char *_scratchcat(int ispath, const char **strings);
-const char *scratchcat( int ispath, const char **strings)
+const char *scratchcat(int ispath, const char **strings)
{
- const char *result;
- pthread_mutex_lock(&mutex);
- result = _scratchcat( ispath, strings);
- pthread_mutex_unlock(&mutex);
- return result;
+ const char *result;
+ pthread_mutex_lock(&mutex);
+ result = _scratchcat(ispath, strings);
+ pthread_mutex_unlock(&mutex);
+ return result;
}
-static const char *_scratchcat( int ispath, const char **strings)
+static const char *_scratchcat(int ispath, const char **strings)
#else
-const char *scratchcat( int ispath, const char **strings)
+const char *scratchcat(int ispath, const char **strings)
#endif
{
- void *scratch, *p;
- char *result;
- size_t length, capacity;
- const char *instr;
- char c, pc;
+ void *scratch, *p;
+ char *result;
+ size_t length, capacity;
+ const char *instr;
+ char c, pc;
#if INSTANCIATE
- size_t hashcode = HASHCODE_INIT;
+ size_t hashcode = HASHCODE_INIT;
#endif
- /* get the recorded pointer on scrtch area */
- scratch = global_scratch;
-
- /* create the scratch area if needed */
- if (scratch == NULL) {
- capacity = INITIAL_SCRATCH_CAPACITY;
- p = malloc( capacity + sizeof(size_t));
- if (p == NULL)
- return NULL;
- *((size_t*)p) = capacity;
- scratch = p;
- global_scratch = p;
- }
-
- /* set local data for scratch area */
- capacity = *((size_t*)scratch);
- result = (char*)(1+((size_t*)scratch));
- length = 0;
-
- /* copy the strings */
- c = 0;
- pc = 1;
- while(pc) {
-
- if (c == 0) {
- instr = *strings++;
- if (instr != NULL) {
- c = *instr;
- if (c == 0)
- continue;
- if (!ispath)
- instr++;
- else if(c != '/' && pc != '/')
- c = '/';
- else if(c == '/' && pc == '/') {
- instr++;
- continue;
- }
- else
- instr++;
- }
- }
- else {
- c = *instr;
- if (c == 0)
- continue;
- instr++;
- }
-
- /* extend the scratch area if needed */
- if (length == capacity) {
- capacity = 2 * capacity;
- p = realloc( scratch, capacity + sizeof(size_t));
- if (p == NULL)
- return NULL;
- *((size_t*)p) = capacity;
- if (p != scratch) {
- scratch = p;
- global_scratch = p;
- result = (char*)(1+((size_t*)p));
- }
- }
-
- /* append the char */
- pc = result[length++] = c;
+ /* get the recorded pointer on scrtch area */
+ scratch = global_scratch;
+
+ /* create the scratch area if needed */
+ if (scratch == NULL) {
+ capacity = INITIAL_SCRATCH_CAPACITY;
+ p = malloc(capacity + sizeof(size_t));
+ if (p == NULL)
+ return NULL;
+ *((size_t*)p) = capacity;
+ scratch = p;
+ global_scratch = p;
+ }
+
+ /* set local data for scratch area */
+ capacity = *((size_t*)scratch);
+ result = (char*)(1+((size_t*)scratch));
+ length = 0;
+
+ /* copy the strings */
+ c = 0;
+ pc = 1;
+ while (pc) {
+
+ if (c == 0) {
+ instr = *strings++;
+ if (instr != NULL) {
+ c = *instr;
+ if (c == 0)
+ continue;
+ if (!ispath)
+ instr++;
+ else if (c != '/' && pc != '/')
+ c = '/';
+ else if (c == '/' && pc == '/') {
+ instr++;
+ continue;
+ } else
+ instr++;
+ }
+ } else {
+ c = *instr;
+ if (c == 0)
+ continue;
+ instr++;
+ }
+
+ /* extend the scratch area if needed */
+ if (length == capacity) {
+ capacity = 2 * capacity;
+ p = realloc(scratch, capacity + sizeof(size_t));
+ if (p == NULL)
+ return NULL;
+ *((size_t*)p) = capacity;
+ if (p != scratch) {
+ scratch = p;
+ global_scratch = p;
+ result = (char*)(1+((size_t*)p));
+ }
+ }
+
+ /* append the char */
+ pc = result[length++] = c;
#if INSTANCIATE
- hashcode = HASHCODE_NEXT(hashcode, (size_t)c);
+ hashcode = HASHCODE_NEXT(hashcode, (size_t)c);
#endif
- }
+ }
#if INSTANCIATE
- return instantiate(result, length, hashcode);
+ return instantiate(result, length, hashcode);
#else
- return result;
+ return result;
#endif
}
#ifdef TEST_SCRATCH
#include <stdio.h>
-int main(int argc, const char**argv) {
- int ispath, iter, i;
- argv++;
- ispath = argv[0] && argv[0][0] == '-' && argv[0][1] == 'p';
- for (i = 0 ; i < 2 ; i++) {
- iter = ispath;
- while (iter < argc) {
- const char *p = scratchcat(ispath,argv+iter++);
- printf("%p: %s\n",p,p);
- }
- }
- return 0;
+int main(int argc, const char**argv)
+{
+ int ispath, iter, i;
+ argv++;
+ ispath = argv[0] && argv[0][0] == '-' && argv[0][1] == 'p';
+ for (i = 0 ; i < 2 ; i++) {
+ iter = ispath;
+ while (iter < argc) {
+ const char *p = scratchcat(ispath, argv + iter++);
+ printf("%p: %s\n", p, p);
+ }
+ }
+ return 0;
}
#endif
diff --git a/src/scratch.h b/src/scratch.h
index 3b15bcb..d71e9bf 100644
--- a/src/scratch.h
+++ b/src/scratch.h
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013-2014 Intel Corporation.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
@@ -43,7 +43,7 @@
scratchcat( 1, array) will return "hello/ /world/!"
*/
-const char *scratchcat( int ispath, const char **strings);
+const char *scratchcat(int ispath, const char **strings);
#endif
diff --git a/src/sha256sum.c b/src/sha256sum.c
index 9b399d1..7c55b94 100644
--- a/src/sha256sum.c
+++ b/src/sha256sum.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013-2014 Intel Corporation.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
@@ -16,9 +16,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors:
- * José Bollo <jose.bollo@open.eurogiciel.org>
- * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
- * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
+ * José Bollo <jose.bollo@open.eurogiciel.org>
+ * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
+ * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
*
*/
#define _GNU_SOURCE
@@ -40,187 +40,187 @@
static const char *arg[2] = { "/usr/bin/sha256sum", NULL };
struct sha256sum {
- enum { RUNNING, FAILED, SUCCESSED } state;
- pid_t pid;
- int tofd;
- int fromfd;
- char result[32];
+ enum { RUNNING, FAILED, SUCCESSED } state;
+ pid_t pid;
+ int tofd;
+ int fromfd;
+ char result[32];
};
struct sha256sum *sha256sum_create()
{
- int fds1[2];
- int fds2[2];
- pid_t pid;
- int sts;
- struct sha256sum *result;
-
- result = malloc(sizeof * result);
- if (result == NULL)
- return NULL;
-
- sts = pipe(fds1);
- if (sts != 0) {
- free(result);
- return NULL;
- }
-
- sts = pipe(fds2);
- if (sts != 0) {
- close( fds1[0]);
- close( fds1[1]);
- free(result);
- return NULL;
- }
-
- pid = fork();
- if (pid == -1) {
- close( fds1[0]);
- close( fds1[1]);
- close( fds2[0]);
- close( fds2[1]);
- free(result);
- return NULL;
- }
-
- if (pid == 0) {
- dup2( fds1[0], 0);
- dup2( fds2[1], 1);
- close( fds1[0]);
- close( fds1[1]);
- close( fds2[0]);
- close( fds2[1]);
- execve( arg[0], (char**)arg, environ);
- exit(1);
- }
-
- close( fds1[0]);
- close( fds2[1]);
- result->state = RUNNING;
- result->pid = pid;
- result->tofd = fds1[1];
- result->fromfd = fds2[0];
- return result;
+ int fds1[2];
+ int fds2[2];
+ pid_t pid;
+ int sts;
+ struct sha256sum *result;
+
+ result = malloc(sizeof * result);
+ if (result == NULL)
+ return NULL;
+
+ sts = pipe(fds1);
+ if (sts != 0) {
+ free(result);
+ return NULL;
+ }
+
+ sts = pipe(fds2);
+ if (sts != 0) {
+ close(fds1[0]);
+ close(fds1[1]);
+ free(result);
+ return NULL;
+ }
+
+ pid = fork();
+ if (pid == -1) {
+ close(fds1[0]);
+ close(fds1[1]);
+ close(fds2[0]);
+ close(fds2[1]);
+ free(result);
+ return NULL;
+ }
+
+ if (pid == 0) {
+ dup2(fds1[0], 0);
+ dup2(fds2[1], 1);
+ close(fds1[0]);
+ close(fds1[1]);
+ close(fds2[0]);
+ close(fds2[1]);
+ execve(arg[0], (char**)arg, environ);
+ exit(1);
+ }
+
+ close(fds1[0]);
+ close(fds2[1]);
+ result->state = RUNNING;
+ result->pid = pid;
+ result->tofd = fds1[1];
+ result->fromfd = fds2[0];
+ return result;
}
void sha256sum_destroy(struct sha256sum *s)
{
- int sts;
-
- if (s->state == RUNNING) {
- close(s->fromfd);
- close(s->tofd);
- waitpid(s->pid, &sts, 0);
- }
- free(s);
+ int sts;
+
+ if (s->state == RUNNING) {
+ close(s->fromfd);
+ close(s->tofd);
+ waitpid(s->pid, &sts, 0);
+ }
+ free(s);
}
int sha256sum_add_data(struct sha256sum *s, const void *data, size_t length)
{
- ssize_t sl;
- int sts;
-
- if (s->state != RUNNING)
- return -1;
-
- while (length) {
- do {
- sl = write(s->tofd, data, length);
- } while (sl == -1 && (errno == EINTR || errno == EAGAIN));
- if (sl == -1) {
- s->state = FAILED;
- close(s->fromfd);
- close(s->tofd);
- waitpid(s->pid, &sts, 0);
- return -1;
- }
- length -= (size_t)sl;
- data = (const void*)((const char*)data + (size_t)sl);
- }
- return 0;
+ ssize_t sl;
+ int sts;
+
+ if (s->state != RUNNING)
+ return -1;
+
+ while (length) {
+ do {
+ sl = write(s->tofd, data, length);
+ } while (sl == -1 && (errno == EINTR || errno == EAGAIN));
+ if (sl == -1) {
+ s->state = FAILED;
+ close(s->fromfd);
+ close(s->tofd);
+ waitpid(s->pid, &sts, 0);
+ return -1;
+ }
+ length -= (size_t)sl;
+ data = (const void*)((const char*)data + (size_t)sl);
+ }
+ return 0;
}
int sha256sum_add_file(struct sha256sum *s, const char *filename)
{
- char buffer[16384];
- int fd;
- ssize_t rd;
-
- fd = open(filename, O_RDONLY);
- if (fd < 0)
- return -1;
-
- for (;;) {
- do {
- rd = read(fd, buffer, sizeof buffer);
- } while (rd == -1 && (errno == EINTR || errno == EAGAIN));
- if (rd == -1) {
- close(fd);
- return -1;
- }
- if (rd == 0) {
- close(fd);
- return 0;
- }
- if (sha256sum_add_data(s, buffer, (size_t)rd)) {
- close(fd);
- return -1;
- }
- }
+ char buffer[16384];
+ int fd;
+ ssize_t rd;
+
+ fd = open(filename, O_RDONLY);
+ if (fd < 0)
+ return -1;
+
+ for (;;) {
+ do {
+ rd = read(fd, buffer, sizeof buffer);
+ } while (rd == -1 && (errno == EINTR || errno == EAGAIN));
+ if (rd == -1) {
+ close(fd);
+ return -1;
+ }
+ if (rd == 0) {
+ close(fd);
+ return 0;
+ }
+ if (sha256sum_add_data(s, buffer, (size_t)rd)) {
+ close(fd);
+ return -1;
+ }
+ }
}
int sha256sum_get(struct sha256sum *s, char result[32])
{
- int sts;
- int j;
- char buffer[65];
- char c1;
- char c2;
-
- if (s->state == RUNNING) {
- s->state = FAILED;
- close(s->tofd);
- waitpid(s->pid, &sts, 0);
- if (WIFEXITED(sts) && WEXITSTATUS(sts) == 0) {
- sts = read(s->fromfd, buffer, 65);
- if (sts == 65 && buffer[64] == ' ') {
- s->state = SUCCESSED;
- for (j = 0 ; j < 32 ; j++) {
- c1 = buffer[j+j];
- if ('0' <= c1 && c1 <= '9')
- c1 = c1 - '0';
- else if ('a' <= c1 && c1 <= 'f')
- c1 = c1 - 'a' + '\012';
- else if ('A' <= c1 && c1 <= 'F')
- c1 = c1 - 'A' + '\012';
- else {
- s->state = FAILED;
- break;
- }
- c2 = buffer[j+j+1];
- if ('0' <= c2 && c2 <= '9')
- c2 = c2 - '0';
- else if ('a' <= c2 && c2 <= 'f')
- c2 = c2 - 'a' + '\012';
- else if ('A' <= c2 && c2 <= 'F')
- c2 = c2 - 'A' + '\012';
- else {
- s->state = FAILED;
- break;
- }
- s->result[j] = (c1 << 4) | c2;
- }
- }
- }
- close(s->fromfd);
- }
-
- if (s->state == FAILED)
- return -1;
-
- memcpy(result, s->result, 32);
-
- return 0;
+ int sts;
+ int j;
+ char buffer[65];
+ char c1;
+ char c2;
+
+ if (s->state == RUNNING) {
+ s->state = FAILED;
+ close(s->tofd);
+ waitpid(s->pid, &sts, 0);
+ if (WIFEXITED(sts) && WEXITSTATUS(sts) == 0) {
+ sts = read(s->fromfd, buffer, 65);
+ if (sts == 65 && buffer[64] == ' ') {
+ s->state = SUCCESSED;
+ for (j = 0 ; j < 32 ; j++) {
+ c1 = buffer[j+j];
+ if ('0' <= c1 && c1 <= '9')
+ c1 = c1 - '0';
+ else if ('a' <= c1 && c1 <= 'f')
+ c1 = c1 - 'a' + '\012';
+ else if ('A' <= c1 && c1 <= 'F')
+ c1 = c1 - 'A' + '\012';
+ else {
+ s->state = FAILED;
+ break;
+ }
+ c2 = buffer[j+j+1];
+ if ('0' <= c2 && c2 <= '9')
+ c2 = c2 - '0';
+ else if ('a' <= c2 && c2 <= 'f')
+ c2 = c2 - 'a' + '\012';
+ else if ('A' <= c2 && c2 <= 'F')
+ c2 = c2 - 'A' + '\012';
+ else {
+ s->state = FAILED;
+ break;
+ }
+ s->result[j] = (c1 << 4) | c2;
+ }
+ }
+ }
+ close(s->fromfd);
+ }
+
+ if (s->state == FAILED)
+ return -1;
+
+ memcpy(result, s->result, 32);
+
+ return 0;
}
#ifdef TEST
@@ -228,23 +228,23 @@ int sha256sum_get(struct sha256sum *s, char result[32])
#include <assert.h>
int main(int argc, char **argv)
{
- char sum[32];
- int j, r;
- struct sha256sum *s;
-
- while (*++argv) {
- s = sha256sum_create();
- assert(s != NULL);
- r = sha256sum_add_file(s, *argv);
- assert(r == 0);
- r = sha256sum_get(s, sum);
- assert(r == 0);
- sha256sum_destroy(s);
- for (j=0 ; j < 32 ; j++)
- printf("%02x", (int)(unsigned char)sum[j]);
- printf(" %s\n", *argv);
- }
- return 0;
+ char sum[32];
+ int j, r;
+ struct sha256sum *s;
+
+ while (*++argv) {
+ s = sha256sum_create();
+ assert(s != NULL);
+ r = sha256sum_add_file(s, *argv);
+ assert(r == 0);
+ r = sha256sum_get(s, sum);
+ assert(r == 0);
+ sha256sum_destroy(s);
+ for (j = 0 ; j < 32 ; j++)
+ printf("%02x", (int)(unsigned char)sum[j]);
+ printf(" %s\n", *argv);
+ }
+ return 0;
}
#endif
diff --git a/src/sha256sum.h b/src/sha256sum.h
index 9494594..a6b4027 100644
--- a/src/sha256sum.h
+++ b/src/sha256sum.h
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013-2014 Intel Corporation.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
diff --git a/src/shared-api.c b/src/shared-api.c
index 742e69a..9688d8b 100644
--- a/src/shared-api.c
+++ b/src/shared-api.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013-2014 Intel Corporation.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
@@ -16,9 +16,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors:
- * José Bollo <jose.bollo@open.eurogiciel.org>
- * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
- * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
+ * José Bollo <jose.bollo@open.eurogiciel.org>
+ * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
+ * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
*
*/
#define _GNU_SOURCE
@@ -52,10 +52,10 @@
/* the global context */
static struct tzplatform_context global_context = {
#ifndef NOT_MULTI_THREAD_SAFE
- .mutex = PTHREAD_MUTEX_INITIALIZER,
+ .mutex = PTHREAD_MUTEX_INITIALIZER,
#endif
- .state = RESET,
- .user = _USER_NOT_SET_
+ .state = RESET,
+ .user = _USER_NOT_SET_
};
/* the signup of names */
@@ -64,323 +64,323 @@ static struct tzplatform_context global_context = {
/* validate the signup */
static void validate_signup(char signup[33])
{
- if (memcmp(signup+1, tizen_platform_config_signup+1, 32)) {
- syslog(LOG_CRIT, "Bad signup of the client of tizen-platform-config");
- abort();
- }
- signup[0] = 1;
+ if (memcmp(signup+1, tizen_platform_config_signup+1, 32)) {
+ syslog(LOG_CRIT, "Bad signup of the client of tizen-platform-config");
+ abort();
+ }
+ signup[0] = 1;
}
/* check the signup */
static inline void check_signup(char signup[33])
{
- if (!signup[0])
- validate_signup(signup);
+ if (!signup[0])
+ validate_signup(signup);
}
/* locks the context */
-inline static void lock(struct tzplatform_context *context)
+static inline void lock(struct tzplatform_context *context)
{
#ifndef NOT_MULTI_THREAD_SAFE
- pthread_mutex_lock( &context->mutex);
+ pthread_mutex_lock(&context->mutex);
#endif
}
/* unlock the context */
-inline static void unlock(struct tzplatform_context *context)
+static inline void unlock(struct tzplatform_context *context)
{
#ifndef NOT_MULTI_THREAD_SAFE
- pthread_mutex_unlock( &context->mutex);
+ pthread_mutex_unlock(&context->mutex);
#endif
}
static inline const char *get_lock(int id, struct tzplatform_context *context)
{
- lock( context);
+ lock(context);
- if (id < 0 || (int)_TZPLATFORM_VARIABLES_COUNT_ <= id)
- return NULL;
+ if (id < 0 || (int)_TZPLATFORM_VARIABLES_COUNT_ <= id)
+ return NULL;
- if (context->state == RESET)
- initialize( context);
+ if (context->state == RESET)
+ initialize(context);
- return context->state == ERROR ? NULL : context->values[id];
+ return context->state == ERROR ? NULL : context->values[id];
}
/*************** PUBLIC API begins here **************/
int tzplatform_context_create(struct tzplatform_context **result)
{
- struct tzplatform_context *context;
+ struct tzplatform_context *context;
- context = malloc( sizeof * context);
- *result = context;
- if (context == NULL)
- return -1;
+ context = malloc(sizeof * context);
+ *result = context;
+ if (context == NULL)
+ return -1;
- context->state = RESET;
- context->user = _USER_NOT_SET_;
+ context->state = RESET;
+ context->user = _USER_NOT_SET_;
#ifndef NOT_MULTI_THREAD_SAFE
- pthread_mutex_init( &context->mutex, NULL);
+ pthread_mutex_init(&context->mutex, NULL);
#endif
- return 0;
+ return 0;
}
void tzplatform_context_destroy(struct tzplatform_context *context)
{
- if (context->state == VALID)
- heap_destroy( &context->heap);
- context->state = ERROR;
- free( context);
+ if (context->state == VALID)
+ heap_destroy(&context->heap);
+ context->state = ERROR;
+ free(context);
}
void tzplatform_reset()
{
- tzplatform_context_reset(&global_context);
+ tzplatform_context_reset(&global_context);
}
void tzplatform_context_reset(struct tzplatform_context *context)
{
- lock( context);
- if (context->state != RESET) {
- if (context->state == VALID)
- heap_destroy( &context->heap);
- context->state = RESET;
- }
- unlock( context);
+ lock(context);
+ if (context->state != RESET) {
+ if (context->state == VALID)
+ heap_destroy(&context->heap);
+ context->state = RESET;
+ }
+ unlock(context);
}
uid_t tzplatform_get_user(char signup[33])
{
- return tzplatform_context_get_user( &global_context);
+ return tzplatform_context_get_user(&global_context);
}
uid_t tzplatform_context_get_user(struct tzplatform_context *context)
{
- uid_t result;
+ uid_t result;
- lock( context);
- result = get_uid( context);
- unlock( context);
+ lock(context);
+ result = get_uid(context);
+ unlock(context);
- return result;
+ return result;
}
void tzplatform_reset_user()
{
- tzplatform_context_reset_user( &global_context);
+ tzplatform_context_reset_user(&global_context);
}
void tzplatform_context_reset_user(struct tzplatform_context *context)
{
- tzplatform_context_set_user( context, _USER_NOT_SET_);
+ tzplatform_context_set_user(context, _USER_NOT_SET_);
}
int tzplatform_set_user(uid_t uid)
{
- return tzplatform_context_set_user( &global_context, uid);
+ return tzplatform_context_set_user(&global_context, uid);
}
int tzplatform_context_set_user(struct tzplatform_context *context, uid_t uid)
{
- lock( context);
- if (context->user != uid) {
- if (uid != _USER_NOT_SET_ && !pw_has_uid( uid)) {
- unlock( context);
- return -1;
+ lock(context);
+ if (context->user != uid) {
+ if (uid != _USER_NOT_SET_ && !pw_has_uid(uid)) {
+ unlock(context);
+ return -1;
+ }
+ else {
+ if (context->state == VALID)
+ heap_destroy(&context->heap);
+ context->state = RESET;
+ context->user = uid;
+ }
}
- else {
- if (context->state == VALID)
- heap_destroy( &context->heap);
- context->state = RESET;
- context->user = uid;
- }
- }
- unlock( context);
+ unlock(context);
- return 0;
+ return 0;
}
/*************** PUBLIC INTERNAL API begins here **************/
const char* _getname_tzplatform_(int id, char signup[33])
{
- check_signup(signup);
- return 0 <= id && id < _TZPLATFORM_VARIABLES_COUNT_ ? keyname(id) : NULL;
+ check_signup(signup);
+ return 0 <= id && id < _TZPLATFORM_VARIABLES_COUNT_ ? keyname(id) : NULL;
}
int _getid_tzplatform_(const char *name, char signup[33])
{
- check_signup(signup);
- return hashid(name, strlen(name));
+ check_signup(signup);
+ return hashid(name, strlen(name));
}
-const char* _getenv_tzplatform_(int id, char signup[33])
+const char* _getenv_tzplatform_(int id, char signup[33])
{
- return _context_getenv_tzplatform_(id, signup, &global_context);
+ return _context_getenv_tzplatform_(id, signup, &global_context);
}
const char* _context_getenv_tzplatform_(int id, char signup[33], struct tzplatform_context *context)
{
- const char *array[2];
- const char *result;
+ const char *array[2];
+ const char *result;
- check_signup(signup);
- result = get_lock(id, context);
- if (result != NULL) {
- array[0] = result;
- array[1] = NULL;
- result = scratchcat( 0, array);
- }
- unlock( context);
- return result;
+ check_signup(signup);
+ result = get_lock(id, context);
+ if (result != NULL) {
+ array[0] = result;
+ array[1] = NULL;
+ result = scratchcat(0, array);
+ }
+ unlock(context);
+ return result;
}
int _getenv_int_tzplatform_(int id, char signup[33])
{
- return _context_getenv_int_tzplatform_(id, signup, &global_context);
+ return _context_getenv_int_tzplatform_(id, signup, &global_context);
}
int _context_getenv_int_tzplatform_(int id, char signup[33], struct tzplatform_context *context)
{
- const char *value;
- int result;
+ const char *value;
+ int result;
- check_signup(signup);
- value = get_lock(id, context);
- result = value==NULL ? -1 : atoi(value);
- unlock( context);
- return result;
+ check_signup(signup);
+ value = get_lock(id, context);
+ result = (value == NULL) ? -1 : atoi(value);
+ unlock(context);
+ return result;
}
const char* _mkstr_tzplatform_(int id, const char * str, char signup[33])
{
- return _context_mkstr_tzplatform_(id, str, signup, &global_context);
+ return _context_mkstr_tzplatform_(id, str, signup, &global_context);
}
const char* _context_mkstr_tzplatform_(int id, const char *str, char signup[33], struct tzplatform_context *context)
{
- const char *array[3];
- const char *result;
+ const char *array[3];
+ const char *result;
- check_signup(signup);
- result = get_lock(id, context);
- if (result != NULL) {
- array[0] = result;
- array[1] = str;
- array[2] = NULL;
- result = scratchcat( 0, array);
- }
- unlock( context);
- return result;
+ check_signup(signup);
+ result = get_lock(id, context);
+ if (result != NULL) {
+ array[0] = result;
+ array[1] = str;
+ array[2] = NULL;
+ result = scratchcat(0, array);
+ }
+ unlock(context);
+ return result;
}
const char* _mkpath_tzplatform_(int id, const char * path, char signup[33])
{
- return _context_mkpath_tzplatform_(id, path, signup, &global_context);
+ return _context_mkpath_tzplatform_(id, path, signup, &global_context);
}
const char* _context_mkpath_tzplatform_(int id, const char *path, char signup[33], struct tzplatform_context *context)
{
- const char *array[3];
- const char *result;
+ const char *array[3];
+ const char *result;
- check_signup(signup);
- result = get_lock(id, context);
- if (result != NULL) {
- array[0] = result;
- array[1] = path;
- array[2] = NULL;
- result = scratchcat( 1, array);
- }
- unlock( context);
- return result;
+ check_signup(signup);
+ result = get_lock(id, context);
+ if (result != NULL) {
+ array[0] = result;
+ array[1] = path;
+ array[2] = NULL;
+ result = scratchcat(1, array);
+ }
+ unlock(context);
+ return result;
}
const char* _mkpath3_tzplatform_(int id, const char * path, const char* path2, char signup[33])
{
- return _context_mkpath3_tzplatform_( id, path, path2, signup, &global_context);
+ return _context_mkpath3_tzplatform_(id, path, path2, signup, &global_context);
}
const char* _context_mkpath3_tzplatform_(int id, const char *path, const char *path2, char signup[33], struct tzplatform_context *context)
{
- const char *array[4];
- const char *result;
-
- check_signup(signup);
- result = get_lock(id, context);
- if (result != NULL) {
- array[0] = result;
- array[1] = path;
- array[2] = path2;
- array[3] = NULL;
- result = scratchcat( 1, array);
- }
- unlock( context);
- return result;
+ const char *array[4];
+ const char *result;
+
+ check_signup(signup);
+ result = get_lock(id, context);
+ if (result != NULL) {
+ array[0] = result;
+ array[1] = path;
+ array[2] = path2;
+ array[3] = NULL;
+ result = scratchcat(1, array);
+ }
+ unlock(context);
+ return result;
}
const char* _mkpath4_tzplatform_(int id, const char * path, const char* path2, const char *path3, char signup[33])
{
- return _context_mkpath4_tzplatform_( id, path, path2, path3, signup, &global_context);
+ return _context_mkpath4_tzplatform_(id, path, path2, path3, signup, &global_context);
}
const char* _context_mkpath4_tzplatform_(int id, const char *path, const char *path2, const char *path3, char signup[33], struct tzplatform_context *context)
{
- const char *array[5];
- const char *result;
-
- check_signup(signup);
- result = get_lock(id, context);
- if (result != NULL) {
- array[0] = result;
- array[1] = path;
- array[2] = path2;
- array[3] = path3;
- array[4] = NULL;
- result = scratchcat( 1, array);
- }
- unlock( context);
- return result;
+ const char *array[5];
+ const char *result;
+
+ check_signup(signup);
+ result = get_lock(id, context);
+ if (result != NULL) {
+ array[0] = result;
+ array[1] = path;
+ array[2] = path2;
+ array[3] = path3;
+ array[4] = NULL;
+ result = scratchcat(1, array);
+ }
+ unlock(context);
+ return result;
}
uid_t _getuid_tzplatform_(int id, char signup[33])
{
- return _context_getuid_tzplatform_( id, signup, &global_context);
+ return _context_getuid_tzplatform_(id, signup, &global_context);
}
uid_t _context_getuid_tzplatform_(int id, char signup[33], struct tzplatform_context *context)
{
- uid_t result;
- const char *value;
+ uid_t result;
+ const char *value;
- check_signup(signup);
- result = (uid_t)-1;
- value = get_lock(id, context);
- if (value != NULL) {
- pw_get_uid( value, &result);
- }
- unlock( context);
- return result;
+ check_signup(signup);
+ result = (uid_t)-1;
+ value = get_lock(id, context);
+ if (value != NULL)
+ pw_get_uid(value, &result);
+
+ unlock(context);
+ return result;
}
gid_t _getgid_tzplatform_(int id, char signup[33])
{
- return _context_getgid_tzplatform_( id, signup, &global_context);
+ return _context_getgid_tzplatform_(id, signup, &global_context);
}
gid_t _context_getgid_tzplatform_(int id, char signup[33], struct tzplatform_context *context)
{
- gid_t result;
- const char *value;
-
- check_signup(signup);
- result = (uid_t)-1;
- value = get_lock(id, context);
- if (value != NULL) {
- pw_get_gid( value, &result);
- }
- unlock( context);
- return result;
+ gid_t result;
+ const char *value;
+
+ check_signup(signup);
+ result = (uid_t)-1;
+ value = get_lock(id, context);
+ if (value != NULL)
+ pw_get_gid(value, &result);
+
+ unlock(context);
+ return result;
}
diff --git a/src/shared-api.h b/src/shared-api.h
index 8735026..6a0ee65 100644
--- a/src/shared-api.h
+++ b/src/shared-api.h
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013-2014 Intel Corporation.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
diff --git a/src/toolbox.c b/src/toolbox.c
index 35dfd3d..107f770 100644
--- a/src/toolbox.c
+++ b/src/toolbox.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013-2014 Intel Corporation.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
@@ -16,9 +16,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors:
- * José Bollo <jose.bollo@open.eurogiciel.org>
- * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
- * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
+ * José Bollo <jose.bollo@open.eurogiciel.org>
+ * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
+ * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
*
*/
#define _GNU_SOURCE
@@ -54,20 +54,20 @@
/* for recording read keys */
struct key {
- struct key *next; /* link to next */
- const char *name; /* name of the key */
- const char *value; /* value of the key */
- size_t begin; /* positions of begin (used by pretty) */
- size_t end; /* positions of end (used by pretty) */
- int dependant; /* is dependant (used by rpm) */
+ struct key *next; /* link to next */
+ const char *name; /* name of the key */
+ const char *value; /* value of the key */
+ size_t begin; /* positions of begin (used by pretty) */
+ size_t end; /* positions of end (used by pretty) */
+ int dependant; /* is dependant (used by rpm) */
};
/* for recording used variables */
struct var {
- struct var *next; /* link to next */
- const char *name; /* name of the variable */
- const char *normal; /* normalized value: "${name}" (for pretty) */
- int dependant; /* is dependant (used by rpm) */
+ struct var *next; /* link to next */
+ const char *name; /* name of the variable */
+ const char *normal; /* normalized value: "${name}" (for pretty) */
+ int dependant; /* is dependant (used by rpm) */
};
/*== STATIC DATA =======================================================*/
@@ -82,13 +82,13 @@ Specifying - mean the standard input.\n\
\n\
Commands:\n\
\n\
-help Display this help\n\
-check Check validity of 'file' (this is the default command)\n\
-pretty Pretty print of the 'file' (the normalized format)\n\
-h Produce the C header with the enumeration of the variables\n\
-c Produce the C code to hash the variable names\n\
-rpm Produce the macro file to use with RPM\n\
-signup Produce the signup data for the proxy linked statically\n\
+help Display this help\n\
+check Check validity of 'file' (this is the default command)\n\
+pretty Pretty print of the 'file' (the normalized format)\n\
+h Produce the C header with the enumeration of the variables\n\
+c Produce the C code to hash the variable names\n\
+rpm Produce the macro file to use with RPM\n\
+signup Produce the signup data for the proxy linked statically\n\
\n\
";
@@ -114,19 +114,19 @@ static char genh_tail[] = "\
static char gperf_head[] = "\
struct varassoc {\n\
- int offset;\n\
- int id;\n\
+ int offset;\n\
+ int id;\n\
};\n\
%%\n\
";
static char *gperf_command[] = {
- "/bin/sh",
- "-c",
- "gperf -r -m 100 --null-strings -C -P -L ANSI-C -c"
- " -t -N hashvar -Q varpool -K offset -G -W namassoc"
- " -F \", _TZPLATFORM_VARIABLES_INVALID_\"",
- NULL
+ "/bin/sh",
+ "-c",
+ "gperf -r -m 100 --null-strings -C -P -L ANSI-C -c"
+ " -t -N hashvar -Q varpool -K offset -G -W namassoc"
+ " -F \", _TZPLATFORM_VARIABLES_INVALID_\"",
+ NULL
};
static char rpm_head[] = "\
@@ -137,11 +137,11 @@ static char rpm_head[] = "\
static char signup_head[] = "\
/* I'm generated. Dont edit me! */\n\
static char tizen_platform_config_signup[33] = {\n\
- '\\x00',\n\
+ '\\x00',\n\
";
static char signup_tail[] = "\
- };\n\
+ };\n\
";
/*== GLOBALS VARIABLES =================================================*/
@@ -170,321 +170,317 @@ static int notstderr = 0;
/*======================================================================*/
/* write the error message */
-static void vwriterror( const char *format, va_list ap)
+static void vwriterror(const char *format, va_list ap)
{
- vfprintf(notstderr ? stdout : stderr, format, ap);
+ vfprintf(notstderr ? stdout : stderr, format, ap);
}
/* write the error message */
-static void writerror( const char *format, ...)
+static void writerror(const char *format, ...)
{
- va_list ap;
- va_start(ap, format);
- vwriterror( format, ap);
- va_end(ap);
+ va_list ap;
+ va_start(ap, format);
+ vwriterror(format, ap);
+ va_end(ap);
}
/* write error and exit */
-static void fatal( const char *format, ...)
+static void fatal(const char *format, ...)
{
- va_list ap;
+ va_list ap;
- writerror("Error, ");
- va_start(ap, format);
- vwriterror( format, ap);
- va_end(ap);
- writerror(".\n");
+ writerror("Error, ");
+ va_start(ap, format);
+ vwriterror(format, ap);
+ va_end(ap);
+ writerror(".\n");
- /* exit */
- exit(1);
+ /* exit */
+ exit(1);
}
/* error in the command line */
-static void argerror( const char *format, ...)
+static void argerror(const char *format, ...)
{
- va_list ap;
+ va_list ap;
- writerror("Error, ");
- va_start(ap, format);
- vwriterror( format, ap);
- va_end(ap);
- writerror(".\nType '"TOOLNAME" help' to get usage.\n");
+ writerror("Error, ");
+ va_start(ap, format);
+ vwriterror(format, ap);
+ va_end(ap);
+ writerror(".\nType '"TOOLNAME" help' to get usage.\n");
- /* exit */
- exit(1);
+ /* exit */
+ exit(1);
}
/*== MANAGEMENT OF THE LIST OF READ KEYS ===============================*/
/* search a key of 'name' and length 'lname' and return it or NULL */
-static struct key *key_search( const char *name, size_t lname)
+static struct key *key_search(const char *name, size_t lname)
{
- struct key *result = keys;
+ struct key *result = keys;
- while(result!=NULL && (strncmp( result->name, name, lname)!=0
- || result->name[lname]!=0))
- result = result->next;
+ while (result != NULL && (strncmp(result->name, name, lname) != 0
+ || result->name[lname] != 0))
+ result = result->next;
- return result;
+ return result;
}
/* append a new key to the list and return it or NULL if allocations failed */
-static struct key *key_add( const char *name, size_t lname,
- const char *value, size_t lvalue,
- size_t begin_pos, size_t end_pos)
+static struct key *key_add(const char *name, size_t lname,
+ const char *value, size_t lvalue,
+ size_t begin_pos, size_t end_pos)
{
- struct key *result, *prev;
- char *sname, *svalue;
-
- /* allocations */
- result = malloc(sizeof *result);
- sname = strndup( name, lname);
- svalue = strndup( value, lvalue);
- if (result == NULL || sname == NULL || svalue == NULL) {
- /* failure of allocations */
- free( result);
- free( sname);
- free( svalue);
- result = NULL;
- }
- else {
- /* success: init the structure */
- result->next = NULL;
- result->name = sname;
- result->value = svalue;
- result->begin = begin_pos;
- result->end = end_pos;
- result->dependant = dependant;
-
- /* link at end of the list */
- prev = keys;
- if (prev == NULL)
- keys = result;
- else {
- while(prev!=NULL && prev->next!=NULL)
- prev = prev->next;
- prev->next = result;
- }
- }
-
- return result;
+ struct key *result, *prev;
+ char *sname, *svalue;
+
+ /* allocations */
+ result = malloc(sizeof *result);
+ sname = strndup(name, lname);
+ svalue = strndup(value, lvalue);
+ if (result == NULL || sname == NULL || svalue == NULL) {
+ /* failure of allocations */
+ free(result);
+ free(sname);
+ free(svalue);
+ result = NULL;
+ } else {
+ /* success: init the structure */
+ result->next = NULL;
+ result->name = sname;
+ result->value = svalue;
+ result->begin = begin_pos;
+ result->end = end_pos;
+ result->dependant = dependant;
+
+ /* link at end of the list */
+ prev = keys;
+ if (prev == NULL)
+ keys = result;
+ else {
+ while (prev != NULL && prev->next != NULL)
+ prev = prev->next;
+ prev->next = result;
+ }
+ }
+
+ return result;
}
/*======================================================================*/
/* search a var of 'name' and length 'lname' and return it or NULL */
-static struct var *var_search( const char *name, size_t lname)
+static struct var *var_search(const char *name, size_t lname)
{
- struct var *result = vars;
- while(result!=NULL && (strncmp( result->name, name, lname)!=0
- || result->name[lname]!=0))
- result = result->next;
+ struct var *result = vars;
+ while (result != NULL && (strncmp(result->name, name, lname) != 0
+ || result->name[lname] != 0))
+ result = result->next;
- return result;
+ return result;
}
/* append a new var to the list and return it or NULL if allocations failed */
-static struct var *var_add( const char *name, size_t lname,
- int depend, const char *value)
+static struct var *var_add(const char *name, size_t lname,
+ int depend, const char *value)
{
- struct var *result, *prev;
- char *sname, *normal;
- size_t length;
-
- /* check for the value */
- if (action == RPM && value != NULL) {
- length = strlen( value) + 1;
- }
- else {
- value = NULL;
- length = lname + 4;
- }
- /* allocations */
- result = malloc(sizeof *result);
- sname = strndup( name, lname);
- normal = malloc( length);
- if (result == NULL || sname == NULL || normal == NULL) {
- /* failure of allocations */
- free( result);
- free( sname);
- free( normal);
- result = NULL;
- }
- else {
- /* success: init the structure */
- result->next = NULL;
- result->name = sname;
- result->normal = normal;
- result->dependant = depend;
- if (value) {
- memcpy( normal, value, length);
- }
- else {
- *normal++ = '$';
- *normal++ = '{';
- memcpy( normal, name, lname);
- normal += lname;
- *normal++ = '}';
- *normal = 0;
- }
-
- /* link at end of the list */
- prev = vars;
- if (prev == NULL)
- vars = result;
- else {
- while(prev!=NULL && prev->next!=NULL)
- prev = prev->next;
- prev->next = result;
- }
- }
-
- return result;
+ struct var *result, *prev;
+ char *sname, *normal;
+ size_t length;
+
+ /* check for the value */
+ if (action == RPM && value != NULL) {
+ length = strlen(value) + 1;
+ } else {
+ value = NULL;
+ length = lname + 4;
+ }
+ /* allocations */
+ result = malloc(sizeof *result);
+ sname = strndup(name, lname);
+ normal = malloc(length);
+ if (result == NULL || sname == NULL || normal == NULL) {
+ /* failure of allocations */
+ free(result);
+ free(sname);
+ free(normal);
+ result = NULL;
+ } else {
+ /* success: init the structure */
+ result->next = NULL;
+ result->name = sname;
+ result->normal = normal;
+ result->dependant = depend;
+ if (value) {
+ memcpy(normal, value, length);
+ } else {
+ *normal++ = '$';
+ *normal++ = '{';
+ memcpy(normal, name, lname);
+ normal += lname;
+ *normal++ = '}';
+ *normal = 0;
+ }
+
+ /* link at end of the list */
+ prev = vars;
+ if (prev == NULL)
+ vars = result;
+ else {
+ while (prev != NULL && prev->next != NULL)
+ prev = prev->next;
+ prev->next = result;
+ }
+ }
+
+ return result;
}
/*== CALLBACK OF PARSING OF THE META FILE ==============================*/
-static void conferr( const char *format, ...)
+static void conferr(const char *format, ...)
{
- va_list ap;
-
- notstderr = action == CHECK;
- writerror( "ERROR ");
- va_start(ap, format);
- vwriterror( format, ap);
- va_end(ap);
- notstderr = 0;
+ va_list ap;
+
+ notstderr = action == CHECK;
+ writerror("ERROR ");
+ va_start(ap, format);
+ vwriterror(format, ap);
+ va_end(ap);
+ notstderr = 0;
}
-static int errcb( struct parsing *parsing,
- size_t pos, const char *message)
+static int errcb(struct parsing *parsing,
+ size_t pos, const char *message)
{
- struct parsinfo info;
+ struct parsinfo info;
- /* get the info */
- parse_utf8_info( parsing, &info, pos);
+ /* get the info */
+ parse_utf8_info(parsing, &info, pos);
- /* emit the error */
- conferr("line %d: %s\n..: %.*s\n..: %*s\n",
- info.lino, message,
- (int)info.length, info.begin,
- info.colno, "^");
+ /* emit the error */
+ conferr("line %d: %s\n..: %.*s\n..: %*s\n",
+ info.lino, message,
+ (int)info.length, info.begin,
+ info.colno, "^");
- /* count it */
- errcount++;
+ /* count it */
+ errcount++;
- /* continue to parse */
- return 1;
+ /* continue to parse */
+ return 1;
}
-static int putcb( struct parsing *parsing,
- const char *name, size_t lname,
- const char *value, size_t lvalue,
- size_t begin_pos, size_t end_pos)
+static int putcb(struct parsing *parsing,
+ const char *name, size_t lname,
+ const char *value, size_t lvalue,
+ size_t begin_pos, size_t end_pos)
{
- enum fkey fkey;
- struct key *key;
- struct parsinfo here, there;
-
- /* check that it is not a foreign key */
- fkey = foreign( name, lname);
- if (fkey != _FOREIGN_INVALID_) {
- parse_utf8_info( parsing, &here, begin_pos);
- conferr("line %d: reserved variable name '%.*s'\n"
- "..: %.*s\n..: %*s\n",
- here.lino, (int)lname, name,
- here.lino, (int)here.length, here.begin, here.colno, "^");
-
- errcount++;
- dependant = 0;
- return 0;
- }
-
- /* search if already defined */
- key = key_search( name, lname);
- if (key != NULL) {
-
- /* yes! that's an error */
- parse_utf8_info( parsing, &here, begin_pos);
- parse_utf8_info( parsing, &there, key->begin);
- conferr("line %d: redefinition of '%s'\n"
- "...was defined line %d\n..: %.*s\n..: %*s\n"
- "...is redefined line %d\n..: %.*s\n..: %*s\n",
- here.lino, key->name,
- there.lino, (int)there.length, there.begin, there.colno, "^",
- here.lino, (int)here.length, here.begin, here.colno, "^");
-
- errcount++;
- dependant = 0;
- return 0;
- }
-
- /* create and record the key */
- key = key_add( name, lname, value, lvalue, begin_pos, end_pos);
- dependant = 0;
- if (key != NULL)
- return 0;
-
- /* no can't because of memory! */
- fatal("out of memory");
- errcount++;
- return -1;
+ enum fkey fkey;
+ struct key *key;
+ struct parsinfo here, there;
+
+ /* check that it is not a foreign key */
+ fkey = foreign(name, lname);
+ if (fkey != _FOREIGN_INVALID_) {
+ parse_utf8_info(parsing, &here, begin_pos);
+ conferr("line %d: reserved variable name '%.*s'\n"
+ "..: %.*s\n..: %*s\n",
+ here.lino, (int)lname, name,
+ here.lino, (int)here.length, here.begin, here.colno, "^");
+
+ errcount++;
+ dependant = 0;
+ return 0;
+ }
+
+ /* search if already defined */
+ key = key_search(name, lname);
+ if (key != NULL) {
+
+ /* yes! that's an error */
+ parse_utf8_info(parsing, &here, begin_pos);
+ parse_utf8_info(parsing, &there, key->begin);
+ conferr("line %d: redefinition of '%s'\n"
+ "...was defined line %d\n..: %.*s\n..: %*s\n"
+ "...is redefined line %d\n..: %.*s\n..: %*s\n",
+ here.lino, key->name,
+ there.lino, (int)there.length, there.begin, there.colno, "^",
+ here.lino, (int)here.length, here.begin, here.colno, "^");
+
+ errcount++;
+ dependant = 0;
+ return 0;
+ }
+
+ /* create and record the key */
+ key = key_add(name, lname, value, lvalue, begin_pos, end_pos);
+ dependant = 0;
+ if (key != NULL)
+ return 0;
+
+ /* no can't because of memory! */
+ fatal("out of memory");
+ errcount++;
+ return -1;
}
-static const char *getcb( struct parsing *parsing,
- const char *name, size_t length,
- size_t begin_pos, size_t end_pos)
+static const char *getcb(struct parsing *parsing,
+ const char *name, size_t length,
+ size_t begin_pos, size_t end_pos)
{
- struct parsinfo here;
- struct var *var;
- enum fkey fkey;
- struct key *key;
- int depend;
-
- /* search if already defined */
- var = var_search( name, length);
- if (var != NULL) {
- /* yes cool, return the normalized form */
- if (var->dependant)
- dependant = 1;
- return var->normal;
- }
-
- /* search the variable */
- fkey = foreign( name, length);
- key = key_search( name, length);
-
- if (fkey == _FOREIGN_INVALID_ && key == NULL) {
-
- /* not a valid variable, emit the error */
- parse_utf8_info( parsing, &here, begin_pos);
- conferr("line %d: use of unknown variable '%.*s'\n"
- "..: %.*s\n..: %*s\n",
- here.lino, (int)length, name,
- (int)here.length, here.begin, here.colno, "^");
- errcount++;
- dependant = 1; /* kind of invalidity */
- return "***error***"; /* avoid further error */
- }
-
- /* valid variables: those of foreign or the already defined keys */
-
- /* set dependant state */
- depend = fkey != _FOREIGN_INVALID_ || key->dependant;
- if (depend)
- dependant = 1;
-
- /* create and record the variable */
- var = var_add( name, length, depend, key==NULL ? NULL : key->value);
- if (var != NULL)
- /* created, return the normalized form */
- return var->normal;
-
- /* memory depletion */
- fatal("out of memory");
- dependant = 1; /* kind of invalidity */
- errcount++;
- return "***error***"; /* avoid further error */
+ struct parsinfo here;
+ struct var *var;
+ enum fkey fkey;
+ struct key *key;
+ int depend;
+
+ /* search if already defined */
+ var = var_search(name, length);
+ if (var != NULL) {
+ /* yes cool, return the normalized form */
+ if (var->dependant)
+ dependant = 1;
+ return var->normal;
+ }
+
+ /* search the variable */
+ fkey = foreign(name, length);
+ key = key_search(name, length);
+
+ if (fkey == _FOREIGN_INVALID_ && key == NULL) {
+
+ /* not a valid variable, emit the error */
+ parse_utf8_info(parsing, &here, begin_pos);
+ conferr("line %d: use of unknown variable '%.*s'\n"
+ "..: %.*s\n..: %*s\n",
+ here.lino, (int)length, name,
+ (int)here.length, here.begin, here.colno, "^");
+ errcount++;
+ dependant = 1; /* kind of invalidity */
+ return "***error***"; /* avoid further error */
+ }
+
+ /* valid variables: those of foreign or the already defined keys */
+
+ /* set dependant state */
+ depend = fkey != _FOREIGN_INVALID_ || key->dependant;
+ if (depend)
+ dependant = 1;
+
+ /* create and record the variable */
+ var = var_add(name, length, depend, key == NULL ? NULL : key->value);
+ if (var != NULL)
+ /* created, return the normalized form */
+ return var->normal;
+
+ /* memory depletion */
+ fatal("out of memory");
+ dependant = 1; /* kind of invalidity */
+ errcount++;
+ return "***error***"; /* avoid further error */
}
/*======================================================================*/
@@ -492,394 +488,380 @@ static const char *getcb( struct parsing *parsing,
/* compare two keys */
static int keycmp(const void *a, const void *b)
{
- const struct key *ka = *(const struct key **)a;
- const struct key *kb = *(const struct key **)b;
- return strcmp(ka->name, kb->name);
+ const struct key *ka = *(const struct key **)a;
+ const struct key *kb = *(const struct key **)b;
+ return strcmp(ka->name, kb->name);
}
/* sort the keys and return their count */
static int sortkeys()
{
- struct key *key = keys, **array;
- int count = 0, index;
+ struct key *key = keys, **array;
+ int count = 0, index;
+
+ while (key) {
+ key = key->next;
+ count++;
+ }
- while (key) {
- key = key->next;
- count++;
- }
+ array = malloc(count * sizeof * array);
+ if (array == NULL)
+ return -1;
- array = malloc( count * sizeof * array);
- if (array == NULL)
- return -1;
+ key = keys;
+ index = 0;
- key = keys;
- index = 0;
-
- while (key) {
- array[index++] = key;
- key = key->next;
- }
+ while (key) {
+ array[index++] = key;
+ key = key->next;
+ }
- qsort(array, count, sizeof * array, keycmp);
+ qsort(array, count, sizeof * array, keycmp);
- while (index) {
+ while (index) {
array[--index]->next = key;
- key = array[index];
- }
- keys = key;
- free( array);
+ key = array[index];
+ }
+ keys = key;
+ free(array);
- return count;
+ return count;
}
/*======================================================================*/
/* pretty print the read file */
-static int pretty( const char *buffer, size_t length, FILE *output)
+static int pretty(const char *buffer, size_t length, FILE *output)
{
- int status;
- struct key *key = keys;
- size_t pos = 0;
-
- while (pos < length && key != NULL) {
- if (pos < key->begin) {
- status = fprintf(output, "%.*s", (int)(key->begin-pos), buffer+pos);
- if (status < 0)
- return status;
- }
- status = fprintf( output, "%s=%s", key->name, key->value);
- if (status < 0)
- return status;
- pos = key->end;
- key = key->next;
- }
-
- if (pos < length) {
- status = fprintf( output, "%.*s", (int)(length-pos), buffer+pos);
- if (status < 0)
- return status;
- }
-
- return 0;
+ int status;
+ struct key *key = keys;
+ size_t pos = 0;
+
+ while (pos < length && key != NULL) {
+ if (pos < key->begin) {
+ status = fprintf(output, "%.*s", (int)(key->begin-pos), buffer+pos);
+ if (status < 0)
+ return status;
+ }
+ status = fprintf(output, "%s=%s", key->name, key->value);
+ if (status < 0)
+ return status;
+ pos = key->end;
+ key = key->next;
+ }
+
+ if (pos < length) {
+ status = fprintf(output, "%.*s", (int)(length-pos), buffer+pos);
+ if (status < 0)
+ return status;
+ }
+
+ return 0;
}
/* generate the header */
-static int genh( FILE *output)
+static int genh(FILE *output)
{
- struct key *key;
- int status;
+ struct key *key;
+ int status;
#ifndef NO_SORT_KEYS
- status = sortkeys();
- if (status < 0)
- return status;
+ status = sortkeys();
+ if (status < 0)
+ return status;
#endif
- status = fprintf( output, "%s", genh_head);
- if (status < 0)
- return status;
- for (key = keys ; key != NULL ; key = key->next) {
- status = fprintf( output, "\t%s,\n", key->name);
- if (status < 0)
- return status;
- }
- status = fprintf( output, "%s", genh_tail);
- if (status < 0)
- return status;
- return 0;
+ status = fprintf(output, "%s", genh_head);
+ if (status < 0)
+ return status;
+ for (key = keys ; key != NULL ; key = key->next) {
+ status = fprintf(output, "\t%s,\n", key->name);
+ if (status < 0)
+ return status;
+ }
+ status = fprintf(output, "%s", genh_tail);
+ if (status < 0)
+ return status;
+ return 0;
}
/* generate hash code using gperf */
static int genc(FILE *output)
{
- struct key *key;
- int fds[2];
- pid_t pid;
- int result, sts;
- size_t l;
+ struct key *key;
+ int fds[2];
+ pid_t pid;
+ int result, sts;
+ size_t l;
#ifndef NO_SORT_KEYS
- sts = sortkeys();
- if (sts < 0)
- return sts;
+ sts = sortkeys();
+ if (sts < 0)
+ return sts;
#endif
- result = pipe(fds);
- if (result != 0)
- return result;
-
- fflush( output);
- pid = fork();
- if (pid == -1) {
- close( fds[0]);
- close( fds[1]);
- fatal( "can't fork");
- result = -1;
- }
- else if (pid == 0) {
- dup2( fds[0], 0);
- close( fds[0]);
- close( fds[1]);
- if (fileno(output) != 1)
- dup2( fileno(output), 1);
- result = execve( gperf_command[0], gperf_command, environ);
- fatal("can't execute gperf");
- exit(1);
- }
- else {
- close( fds[0]);
- sts = write( fds[1], gperf_head, sizeof(gperf_head)-1);
- if (sts < 0)
- result = sts;
- for (key = keys ; key != NULL ; key = key->next) {
- l = strlen( key->name);
- sts = write( fds[1], key->name, l);
- if (sts < 0)
- result = sts;
- sts = write( fds[1], ", ", 2);
- if (sts < 0)
- result = sts;
- sts = write( fds[1], key->name, l);
- if (sts < 0)
- result = sts;
- sts = write( fds[1], "\n", 1);
- if (sts < 0)
- result = sts;
- }
- close( fds[1]);
- wait(&result);
- sts = WIFEXITED(result) && WEXITSTATUS(result)==0 ? 0 : -1;
- if (sts < 0)
- result = sts;
- }
- return result;
+ result = pipe(fds);
+ if (result != 0)
+ return result;
+
+ fflush(output);
+ pid = fork();
+ if (pid == -1) {
+ close(fds[0]);
+ close(fds[1]);
+ fatal("can't fork");
+ result = -1;
+ } else if (pid == 0) {
+ dup2(fds[0], 0);
+ close(fds[0]);
+ close(fds[1]);
+ if (fileno(output) != 1)
+ dup2(fileno(output), 1);
+ result = execve(gperf_command[0], gperf_command, environ);
+ fatal("can't execute gperf");
+ exit(1);
+ } else {
+ close(fds[0]);
+ sts = write(fds[1], gperf_head, sizeof(gperf_head)-1);
+ if (sts < 0)
+ result = sts;
+ for (key = keys ; key != NULL ; key = key->next) {
+ l = strlen(key->name);
+ sts = write(fds[1], key->name, l);
+ if (sts < 0)
+ result = sts;
+ sts = write(fds[1], ", ", 2);
+ if (sts < 0)
+ result = sts;
+ sts = write(fds[1], key->name, l);
+ if (sts < 0)
+ result = sts;
+ sts = write(fds[1], "\n", 1);
+ if (sts < 0)
+ result = sts;
+ }
+ close(fds[1]);
+ wait(&result);
+ sts = WIFEXITED(result) && WEXITSTATUS(result) == 0 ? 0 : -1;
+ if (sts < 0)
+ result = sts;
+ }
+ return result;
}
/* generate the rpm macros */
-static int rpm( FILE *output)
+static int rpm(FILE *output)
{
- struct key *key;
- int status;
+ struct key *key;
+ int status;
#ifndef NO_SORT_KEYS
- status = sortkeys();
- if (status < 0)
- return status;
+ status = sortkeys();
+ if (status < 0)
+ return status;
#endif
- status = fprintf( output, "%s", rpm_head);
- if (status < 0)
- return status;
- for (key = keys ; key != NULL ; key = key->next) {
- if (!key->dependant) {
- status = fprintf( output, "%%%-40s %s\n", key->name, key->value);
- if (status < 0)
- return status;
- }
- }
- return 0;
+ status = fprintf(output, "%s", rpm_head);
+ if (status < 0)
+ return status;
+ for (key = keys ; key != NULL ; key = key->next) {
+ if (!key->dependant) {
+ status = fprintf(output, "%%%-40s %s\n", key->name, key->value);
+ if (status < 0)
+ return status;
+ }
+ }
+ return 0;
}
/* generate the signup */
-static int signup( FILE *output)
+static int signup(FILE *output)
{
- struct key *key;
- int status;
- int i;
- struct sha256sum *sum;
- char term;
- char signup[32];
+ struct key *key;
+ int status;
+ int i;
+ struct sha256sum *sum;
+ char term;
+ char signup[32];
#ifndef NO_SORT_KEYS
- status = sortkeys();
- if (status < 0)
- return status;
+ status = sortkeys();
+ if (status < 0)
+ return status;
#endif
- sum = sha256sum_create();
- if (sum == NULL)
- return -1;
-
- term = ';';
- for (key = keys ; key != NULL ; key = key->next) {
- status = sha256sum_add_data(sum, key->name, strlen(key->name));
- if (status < 0) {
- sha256sum_destroy(sum);
- return status;
- }
- status = sha256sum_add_data(sum, &term, 1);
- if (status < 0) {
- sha256sum_destroy(sum);
- return status;
- }
- }
-
- status = sha256sum_get(sum, signup);
- sha256sum_destroy(sum);
- if (status < 0)
- return status;
-
- status = fprintf( output, "%s", signup_head);
- if (status < 0)
- return status;
-
- for (i=0 ; i<32 ; i++) {
- status = fprintf( output, "%s'\\x%02x'%s",
- (i & 7) ? " " : " ",
- (int)(unsigned char)signup[i],
- (i & 7) < 7 ? "," : i == 31 ? "\n" : ",\n");
- if (status < 0)
- return status;
- }
- status = fprintf( output, "%s", signup_tail);
- if (status < 0)
- return status;
- return 0;
+ sum = sha256sum_create();
+ if (sum == NULL)
+ return -1;
+
+ term = ';';
+ for (key = keys ; key != NULL ; key = key->next) {
+ status = sha256sum_add_data(sum, key->name, strlen(key->name));
+ if (status < 0) {
+ sha256sum_destroy(sum);
+ return status;
+ }
+ status = sha256sum_add_data(sum, &term, 1);
+ if (status < 0) {
+ sha256sum_destroy(sum);
+ return status;
+ }
+ }
+
+ status = sha256sum_get(sum, signup);
+ sha256sum_destroy(sum);
+ if (status < 0)
+ return status;
+
+ status = fprintf(output, "%s", signup_head);
+ if (status < 0)
+ return status;
+
+ for (i = 0 ; i < 32 ; i++) {
+ status = fprintf(output, "%s'\\x%02x'%s",
+ (i & 7) ? " " : " ",
+ (int)(unsigned char)signup[i],
+ (i & 7) < 7 ? "," : i == 31 ? "\n" : ",\n");
+ if (status < 0)
+ return status;
+ }
+ status = fprintf(output, "%s", signup_tail);
+ if (status < 0)
+ return status;
+ return 0;
}
/* main of processing */
static int process()
{
- struct parsing parsing;
- struct buffer buffer;
- int result;
-
- /* read the file */
- result = buffer_create( &buffer, metafilepath);
- if (result != 0) {
- fatal( "can't read file %s", metafilepath);
- return -1;
- }
-
- /* parse the file */
- parsing.buffer = buffer.buffer;
- parsing.length = buffer.length;
- parsing.maximum_data_size = 0;
- parsing.should_escape = action!=RPM;
- parsing.data = 0;
- parsing.get = getcb;
- parsing.put = putcb;
- parsing.error = errcb;
- dependant = 0;
- result = parse_utf8_config( &parsing);
- if (result != 0) {
- buffer_destroy( &buffer);
- fatal( "while parsing the file %s", metafilepath);
- return -1;
- }
- if (errcount != 0) {
- buffer_destroy( &buffer);
- fatal( "%d errors detected %s", errcount, metafilepath);
- return -1;
- }
-
- /* process */
- switch( action) {
- case CHECK:
- break;
- case PRETTY:
- pretty( buffer.buffer, buffer.length, stdout);
- break;
- case GENH:
- genh( stdout);
- break;
- case GENC:
- genc( stdout);
- break;
- case RPM:
- rpm( stdout);
- break;
- case SIGNUP:
- signup( stdout);
- break;
- }
-
- buffer_destroy( &buffer);
- return 0;
+ struct parsing parsing;
+ struct buffer buffer;
+ int result;
+
+ /* read the file */
+ result = buffer_create(&buffer, metafilepath);
+ if (result != 0) {
+ fatal("can't read file %s", metafilepath);
+ return -1;
+ }
+
+ /* parse the file */
+ parsing.buffer = buffer.buffer;
+ parsing.length = buffer.length;
+ parsing.maximum_data_size = 0;
+ parsing.should_escape = action != RPM;
+ parsing.data = 0;
+ parsing.get = getcb;
+ parsing.put = putcb;
+ parsing.error = errcb;
+ dependant = 0;
+ result = parse_utf8_config(&parsing);
+ if (result != 0) {
+ buffer_destroy(&buffer);
+ fatal("while parsing the file %s", metafilepath);
+ return -1;
+ }
+ if (errcount != 0) {
+ buffer_destroy(&buffer);
+ fatal("%d errors detected %s", errcount, metafilepath);
+ return -1;
+ }
+
+ /* process */
+ switch (action) {
+ case CHECK:
+ break;
+ case PRETTY:
+ pretty(buffer.buffer, buffer.length, stdout);
+ break;
+ case GENH:
+ genh(stdout);
+ break;
+ case GENC:
+ genc(stdout);
+ break;
+ case RPM:
+ rpm(stdout);
+ break;
+ case SIGNUP:
+ signup(stdout);
+ break;
+ }
+
+ buffer_destroy(&buffer);
+ return 0;
}
/*======================================================================*/
/* very simple argument parsing */
-static int arguments( char **argv)
+static int arguments(char **argv)
{
- /* skip the program name*/
- argv++;
-
- /* scan first arg */
- if (*argv == NULL) {
- /* no argument then default is to check */
- action = CHECK;
- }
- else {
- /* check if first argument is 'check', 'pretty', 'c', 'h', '-h',
- '--help' or 'help' */
- if (0 == strcmp( *argv, "check")) {
- action = CHECK;
- argv++;
- }
- else if (0 == strcmp( *argv, "pretty")) {
- action = PRETTY;
- argv++;
- }
- else if (0 == strcmp( *argv, "c")) {
- action = GENC;
- argv++;
- }
- else if (0 == strcmp( *argv, "h")) {
- action = GENH;
- argv++;
- }
- else if (0 == strcmp( *argv, "rpm")) {
- action = RPM;
- argv++;
- }
- else if (0 == strcmp( *argv, "signup")) {
- action = SIGNUP;
- argv++;
- }
- else if (0 == strcmp( *argv, "help") || 0 == strcmp( *argv, "--help")) {
- printf("%s", help);
- exit(0);
- return -1;
- }
- else if (**argv == '-') {
- if (0 == strcmp( *argv, "--") || 0 == strcmp( *argv, "-") ) {
- action = CHECK;
- }
- else {
- argerror( "unknown option '%s'", *argv);
- return -1;
- }
- }
- /* skip the -- arg if present */
- if (*argv != NULL && 0 == strcmp( *argv, "--")) {
- argv++;
- }
- /* get a meta file argument */
- if (*argv != NULL) {
- if (0 == strcmp( *argv, "-"))
- metafilepath = "/dev/stdin";
- else
- metafilepath = *argv;
- argv++;
- }
- /* check that there is no extra argument */
- if (*argv != NULL) {
- argerror("extra argument found '%s'",*argv);
- return -1;
- }
- }
- return 0;
+ /* skip the program name*/
+ argv++;
+
+ /* scan first arg */
+ if (*argv == NULL) {
+ /* no argument then default is to check */
+ action = CHECK;
+ } else {
+ /* check if first argument is 'check', 'pretty', 'c', 'h', '-h',
+ '--help' or 'help' */
+ if (0 == strcmp(*argv, "check")) {
+ action = CHECK;
+ argv++;
+ } else if (0 == strcmp(*argv, "pretty")) {
+ action = PRETTY;
+ argv++;
+ } else if (0 == strcmp(*argv, "c")) {
+ action = GENC;
+ argv++;
+ } else if (0 == strcmp(*argv, "h")) {
+ action = GENH;
+ argv++;
+ } else if (0 == strcmp(*argv, "rpm")) {
+ action = RPM;
+ argv++;
+ } else if (0 == strcmp(*argv, "signup")) {
+ action = SIGNUP;
+ argv++;
+ } else if (0 == strcmp(*argv, "help") || 0 == strcmp(*argv, "--help")) {
+ printf("%s", help);
+ exit(0);
+ return -1;
+ } else if (**argv == '-') {
+ if (0 == strcmp(*argv, "--") || 0 == strcmp(*argv, "-")) {
+ action = CHECK;
+ } else {
+ argerror("unknown option '%s'", *argv);
+ return -1;
+ }
+ }
+ /* skip the -- arg if present */
+ if (*argv != NULL && 0 == strcmp(*argv, "--"))
+ argv++;
+ /* get a meta file argument */
+ if (*argv != NULL) {
+ if (0 == strcmp(*argv, "-"))
+ metafilepath = "/dev/stdin";
+ else
+ metafilepath = *argv;
+ argv++;
+ }
+ /* check that there is no extra argument */
+ if (*argv != NULL) {
+ argerror("extra argument found '%s'", *argv);
+ return -1;
+ }
+ }
+ return 0;
}
int main(int argc, char **argv)
{
- if (arguments(argv) == 0)
- if (process() == 0)
- return 0;
+ if (arguments(argv) == 0)
+ if (process() == 0)
+ return 0;
- return 1;
+ return 1;
}
-
-
diff --git a/src/tzplatform_config.h b/src/tzplatform_config.h
index ab998b0..add6c12 100644
--- a/src/tzplatform_config.h
+++ b/src/tzplatform_config.h
@@ -16,9 +16,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors:
- * José Bollo <jose.bollo@open.eurogiciel.org>
- * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
- * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
+ * José Bollo <jose.bollo@open.eurogiciel.org>
+ * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
+ * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
*
*/
#ifndef LIBTIZEN_PLATFORM_WRAPPER
@@ -111,11 +111,11 @@ int tzplatform_getenv_int(enum tzplatform_variable id);
Can return NULL in case of internal error.
Example:
- if TZ_SYS_HOME == "/opt/home" then calling
+ if TZ_SYS_HOME == "/opt/home" then calling
- tzplatform_mkstr(TZ_SYS_HOME,"-yes")
+ tzplatform_mkstr(TZ_SYS_HOME,"-yes")
- will return "/opt/home-yes"
+ will return "/opt/home-yes"
*/
extern
const char* tzplatform_mkstr(enum tzplatform_variable id, const char *str);
@@ -131,11 +131,11 @@ const char* tzplatform_mkstr(enum tzplatform_variable id, const char *str);
Can return NULL in case of internal error.
Example:
- if TZ_SYS_HOME == "/opt/home" then calling
+ if TZ_SYS_HOME == "/opt/home" then calling
- tzplatform_mkpath(TZ_SYS_HOME,"yes")
+ tzplatform_mkpath(TZ_SYS_HOME,"yes")
- will return "/opt/home/yes"
+ will return "/opt/home/yes"
*/
extern
const char* tzplatform_mkpath(enum tzplatform_variable id, const char *path);
@@ -151,15 +151,15 @@ const char* tzplatform_mkpath(enum tzplatform_variable id, const char *path);
Can return NULL in case of internal error.
Example:
- if TZ_SYS_HOME == "/opt/home" then calling
+ if TZ_SYS_HOME == "/opt/home" then calling
- tzplatform_mkpath3(TZ_SYS_HOME,"yes","no")
+ tzplatform_mkpath3(TZ_SYS_HOME,"yes","no")
- will return "/opt/home/yes/no"
+ will return "/opt/home/yes/no"
*/
extern
const char* tzplatform_mkpath3(enum tzplatform_variable id, const char *path,
- const char *path2);
+ const char *path2);
/*
Return the string resulting of the path-concatenation of string value of the
@@ -172,26 +172,26 @@ const char* tzplatform_mkpath3(enum tzplatform_variable id, const char *path,
Can return NULL in case of internal error.
Example:
- if TZ_SYS_HOME == "/opt/home" then calling
+ if TZ_SYS_HOME == "/opt/home" then calling
- tzplatform_mkpath4(TZ_SYS_HOME,"yes","no","/maybe")
+ tzplatform_mkpath4(TZ_SYS_HOME,"yes","no","/maybe")
- will return "/opt/home/yes/no/maybe"
+ will return "/opt/home/yes/no/maybe"
*/
extern
const char* tzplatform_mkpath4(enum tzplatform_variable id, const char *path,
- const char *path2, const char *path3);
+ const char *path2, const char *path3);
/*
Return the uid for a given user name, stored in variable <id>
Retun -1 in case of error.
Example:
- if TZ_USER_NAME=="app" then calling:
+ if TZ_USER_NAME=="app" then calling:
- tzplatform_getuid(TZ_USER_NAME)
+ tzplatform_getuid(TZ_USER_NAME)
- will return the uid of the user 'app'
+ will return the uid of the user 'app'
*/
extern
uid_t tzplatform_getuid(enum tzplatform_variable id);
@@ -201,11 +201,11 @@ uid_t tzplatform_getuid(enum tzplatform_variable id);
Retun -1 in case of error.
Example:
- if TZ_USER_NAME=="app" then calling:
+ if TZ_USER_NAME=="app" then calling:
- tzplatform_getuid(TZ_USER_NAME)
+ tzplatform_getuid(TZ_USER_NAME)
- will return the gid of the user 'app'
+ will return the gid of the user 'app'
*/
extern
gid_t tzplatform_getgid(enum tzplatform_variable id);
@@ -282,11 +282,11 @@ int tzplatform_context_getenv_int(struct tzplatform_context *context, enum tzpla
Can return NULL in case of internal error.
Example:
- if TZ_SYS_HOME == "/opt/home" then calling
+ if TZ_SYS_HOME == "/opt/home" then calling
- tzplatform_context_mkstr(context, TZ_SYS_HOME,"-yes")
+ tzplatform_context_mkstr(context, TZ_SYS_HOME,"-yes")
- will return "/opt/home-yes"
+ will return "/opt/home-yes"
*/
extern
const char* tzplatform_context_mkstr(struct tzplatform_context *context, enum tzplatform_variable id, const char *str);
@@ -302,11 +302,11 @@ const char* tzplatform_context_mkstr(struct tzplatform_context *context, enum tz
Can return NULL in case of internal error.
Example:
- if TZ_SYS_HOME == "/opt/home" then calling
+ if TZ_SYS_HOME == "/opt/home" then calling
- tzplatform_context_mkpath(context, TZ_SYS_HOME,"yes")
+ tzplatform_context_mkpath(context, TZ_SYS_HOME,"yes")
- will return "/opt/home/yes"
+ will return "/opt/home/yes"
*/
extern
const char* tzplatform_context_mkpath(struct tzplatform_context *context, enum tzplatform_variable id, const char *path);
@@ -322,15 +322,15 @@ const char* tzplatform_context_mkpath(struct tzplatform_context *context, enum t
Can return NULL in case of internal error.
Example:
- if TZ_SYS_HOME == "/opt/home" then calling
+ if TZ_SYS_HOME == "/opt/home" then calling
- tzplatform_context_mkpath3(context, TZ_SYS_HOME,"yes","no")
+ tzplatform_context_mkpath3(context, TZ_SYS_HOME,"yes","no")
- will return "/opt/home/yes/no"
+ will return "/opt/home/yes/no"
*/
extern
const char* tzplatform_context_mkpath3(struct tzplatform_context *context, enum tzplatform_variable id, const char *path,
- const char *path2);
+ const char *path2);
/*
Return the string resulting of the path-concatenation of string value of the
@@ -343,26 +343,26 @@ const char* tzplatform_context_mkpath3(struct tzplatform_context *context, enum
Can return NULL in case of internal error.
Example:
- if TZ_SYS_HOME == "/opt/home" then calling
+ if TZ_SYS_HOME == "/opt/home" then calling
- tzplatform_context_mkpath4(context, TZ_SYS_HOME,"yes","no","/maybe")
+ tzplatform_context_mkpath4(context, TZ_SYS_HOME,"yes","no","/maybe")
- will return "/opt/home/yes/no/maybe"
+ will return "/opt/home/yes/no/maybe"
*/
extern
const char* tzplatform_context_mkpath4(struct tzplatform_context *context, enum tzplatform_variable id, const char *path,
- const char *path2, const char *path3);
+ const char *path2, const char *path3);
/*
Return the uid for a given user name, stored in variable <id>
Retun -1 in case of error.
Example:
- if TZ_USER_NAME=="app" then calling:
+ if TZ_USER_NAME=="app" then calling:
- tzplatform_context_getuid(context, TZ_USER_NAME)
+ tzplatform_context_getuid(context, TZ_USER_NAME)
- will return the uid of the user 'app'
+ will return the uid of the user 'app'
*/
extern
uid_t tzplatform_context_getuid(struct tzplatform_context *context, enum tzplatform_variable id);
@@ -372,11 +372,11 @@ uid_t tzplatform_context_getuid(struct tzplatform_context *context, enum tzplatf
Retun -1 in case of error.
Example:
- if TZ_USER_NAME=="app" then calling:
+ if TZ_USER_NAME=="app" then calling:
- tzplatform_context_getuid(context, TZ_USER_NAME)
+ tzplatform_context_getuid(context, TZ_USER_NAME)
- will return the gid of the user 'app'
+ will return the gid of the user 'app'
*/
extern
gid_t tzplatform_context_getgid(struct tzplatform_context *context, enum tzplatform_variable id);
@@ -388,18 +388,18 @@ gid_t tzplatform_context_getgid(struct tzplatform_context *context, enum tzplatf
Return -1 in case of error.
Example:
- tzplatform_has_system_group(1000)
+ tzplatform_has_system_group(1000)
+
+ will return 0 or 1 depends on right of given uid.
- will return 0 or 1 depends on right of given uid.
-
NOTE :
* If you pass the -1 value to this function it will take the current uid given
- * by the POSIX function getuid();
-
+ * by the POSIX function getuid();
+
*** WARNING : ***
* This is a temporary feature
* This will be managed by Cynara
-
+
*/
extern
int tzplatform_has_system_group(uid_t uid);
diff --git a/src/tzplatform_get.c b/src/tzplatform_get.c
index 1903fe5..33a9af9 100755..100644
--- a/src/tzplatform_get.c
+++ b/src/tzplatform_get.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2013-2014 Intel Corporation.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
@@ -16,9 +16,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors:
- * José Bollo <jose.bollo@open.eurogiciel.org>
- * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
- * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
+ * José Bollo <jose.bollo@open.eurogiciel.org>
+ * Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
+ * Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
*
*/
@@ -32,22 +32,22 @@
#define basename(x) (x)
-static const char usage [] = "type '%s --help' to get help.\n";
+static const char usage[] = "type '%s --help' to get help.\n";
-static const char help [] = "\
+static const char help[] = "\
\n\
usage: %s [options...] [keys...]\n\
\n\
options:\n\
\n\
--a --all all keys (must not be followed by keys)\n\
--n --not not in the keys\n\
--e --export prefix with export\n\
--l --list prints only the key names, not the values\n\
--s --space separate with spaces instead of new-lines\n\
--q --query silently check that given variables are existing\n\
--c --continue continue to process if error\n\
--u --user id set the user using its 'id' (name or numeric)\n\
+-a --all all keys (must not be followed by keys)\n\
+-n --not not in the keys\n\
+-e --export prefix with export\n\
+-l --list prints only the key names, not the values\n\
+-s --space separate with spaces instead of new-lines\n\
+-q --query silently check that given variables are existing\n\
+-c --continue continue to process if error\n\
+-u --user id set the user using its 'id' (name or numeric)\n\
\n\
";
@@ -63,33 +63,32 @@ int main(int argc, char **argv)
int ret = 0;
/* parse args */
- while(*argv && **argv=='-') {
- char c, *opt = 1+*argv++;
- while(opt) {
+ while (*argv && **argv == '-') {
+ char c, *opt = 1 + *argv++;
+ while (opt) {
if (*opt == '-') {
char *x = 0;
c = *++opt;
- switch(c) {
- case 'a': x = "all"; break;
- case 'n': x = "not"; break;
- case 'q': x = "query"; break;
- case 'e': x = "export"; break;
- case 's': x = "space"; break;
- case 'l': x = "list"; break;
- case 'c': x = "continue"; break;
- case 'h': x = "help"; break;
- case 'u': x = "user"; break;
+ switch (c) {
+ case 'a': x = "all"; break;
+ case 'n': x = "not"; break;
+ case 'q': x = "query"; break;
+ case 'e': x = "export"; break;
+ case 's': x = "space"; break;
+ case 'l': x = "list"; break;
+ case 'c': x = "continue"; break;
+ case 'h': x = "help"; break;
+ case 'u': x = "user"; break;
}
- if (!x || strcmp(x,opt))
+ if (!x || strcmp(x, opt))
c = 0;
opt = 0;
- }
- else {
+ } else {
c = *opt;
if (!*++opt)
opt = 0;
}
- switch(c) {
+ switch (c) {
case 'a': all = 1; break;
case 'n': not = 1; break;
case 'q': query = 1; break;
@@ -99,10 +98,10 @@ int main(int argc, char **argv)
case 'c': cont = 1; break;
case 'u': user = *argv; if (user) argv++; break;
case 'h':
- fprintf( stdout, help, basename(progname));
+ fprintf(stdout, help, basename(progname));
return 0;
default:
- fprintf( stderr, usage, basename(progname));
+ fprintf(stderr, usage, basename(progname));
return 1;
}
}
@@ -111,37 +110,37 @@ int main(int argc, char **argv)
/* some checks */
if (query) {
if (all) {
- fprintf( stderr,
+ fprintf(stderr,
"error! --all and --query aren't compatibles.\n");
return 1;
}
if (not) {
- fprintf( stderr,
+ fprintf(stderr,
"error! --not and --query aren't compatibles.\n");
return 1;
}
if (list) {
- fprintf( stderr,
+ fprintf(stderr,
"error! --list and --query aren't compatibles.\n");
return 1;
}
if (cont) {
- fprintf( stderr,
+ fprintf(stderr,
"error! --continue and --query aren't compatibles.\n");
return 1;
}
if (space) {
- fprintf( stderr,
+ fprintf(stderr,
"warning! --space option ignored for queries.\n");
}
if (export) {
- fprintf( stderr,
+ fprintf(stderr,
"warning! --export option ignored for queries.\n");
}
}
if (all) {
if (*argv) {
- fprintf( stderr,
+ fprintf(stderr,
"error! --all doesn't accept any key.\n");
return 1;
}
@@ -153,25 +152,24 @@ int main(int argc, char **argv)
n = tzplatform_getcount();
sel = calloc(sizeof(int), n);
if (sel == NULL) {
- fprintf( stderr, "error! out of memory!\n");
+ fprintf(stderr, "error! out of memory!\n");
return 1;
}
/* get the variables from the list */
while (*argv) {
- id = tzplatform_getid( *argv);
+ id = tzplatform_getid(*argv);
if (id == _TZPLATFORM_VARIABLES_INVALID_) {
if (query) {
ret = 1;
goto out;
}
- fprintf( stderr, "error! %s isn't a variable.\n", *argv);
+ fprintf(stderr, "error! %s isn't a variable.\n", *argv);
if (!cont) {
ret = 1;
goto out;
}
- }
- else {
+ } else {
sel[(int)id] = 1;
}
argv++;
@@ -185,13 +183,13 @@ int main(int argc, char **argv)
/* set the user */
if (user) {
- for (i=0 ; '0' <= user[i] && user[i] <= '9' ; i++);
+ for (i = 0 ; '0' <= user[i] && user[i] <= '9' ; i++);
if (user[i])
getpwnam_r(user, &pwd, buf, sizeof(buf), &spw);
else
getpwuid_r((uid_t)atoi(user), &pwd, buf, sizeof(buf), &spw);
if (!spw) {
- fprintf( stderr, "error! %s isn't standing for a valid user.\n", user);
+ fprintf(stderr, "error! %s isn't standing for a valid user.\n", user);
if (!cont) {
ret = 1;
goto out;
@@ -199,7 +197,7 @@ int main(int argc, char **argv)
} else {
i = tzplatform_set_user(spw->pw_uid);
if (i) {
- fprintf( stderr, "error! can't set the valid user %s.\n", user);
+ fprintf(stderr, "error! can't set the valid user %s.\n", user);
if (!cont) {
ret = 1;
goto out;
@@ -211,14 +209,14 @@ int main(int argc, char **argv)
/* emits the result */
for (p = i = 0 ; i < n ; i++) {
if (sel[i] != not) {
- if (p++)
- printf( space ? " " : export ? "\nexport " : "\n");
+ if (p++)
+ printf(space ? " " : export ? "\nexport " : "\n");
else if (export)
- printf( "export ");
+ printf("export ");
id = (enum tzplatform_variable) i;
- printf( "%s", tzplatform_getname(id));
- if (!list)
- printf( "=%s", tzplatform_getenv(id));
+ printf("%s", tzplatform_getname(id));
+ if (!list)
+ printf("=%s", tzplatform_getenv(id));
}
}
if (p)