Restructured error,debug anf log API
Renamed functions clicon->clixon, replaced global variables w access functions Unified clicon_netconf_error with clixon_err()
This commit is contained in:
parent
261469be16
commit
24a4991ec8
199 changed files with 4668 additions and 4158 deletions
|
|
@ -59,8 +59,12 @@
|
|||
#include <cligen/cligen.h>
|
||||
|
||||
/* clixon */
|
||||
#include "clixon_queue.h"
|
||||
#include "clixon_hash.h"
|
||||
#include "clixon_handle.h"
|
||||
#include "clixon_err.h"
|
||||
#include "clixon_log.h"
|
||||
#include "clixon_debug.h"
|
||||
#include "clixon_uid.h"
|
||||
|
||||
/*! Translate group name to gid. Return -1 if error or not found.
|
||||
|
|
@ -83,11 +87,11 @@ group_name2gid(const char *name,
|
|||
gr = &g0;
|
||||
/* This leaks memory in ubuntu */
|
||||
if (getgrnam_r(name, gr, buf, sizeof(buf), >mp) < 0){
|
||||
clicon_err(OE_UNIX, errno, "getgrnam_r(%s)", name);
|
||||
clixon_err(OE_UNIX, errno, "getgrnam_r(%s)", name);
|
||||
goto done;
|
||||
}
|
||||
if (gtmp == NULL){
|
||||
clicon_err(OE_UNIX, 0, "No such group: %s", name);
|
||||
clixon_err(OE_UNIX, 0, "No such group: %s", name);
|
||||
goto done;
|
||||
}
|
||||
if (gid)
|
||||
|
|
@ -114,11 +118,11 @@ name2uid(const char *name,
|
|||
struct passwd *pwbufp = NULL;
|
||||
|
||||
if (getpwnam_r(name, &pwbuf, buf, sizeof(buf), &pwbufp) != 0){
|
||||
clicon_err(OE_UNIX, errno, "getpwnam_r(%s)", name);
|
||||
clixon_err(OE_UNIX, errno, "getpwnam_r(%s)", name);
|
||||
goto done;
|
||||
}
|
||||
if (pwbufp == NULL){
|
||||
clicon_err(OE_UNIX, 0, "No such user: %s", name);
|
||||
clixon_err(OE_UNIX, 0, "No such user: %s", name);
|
||||
goto done;
|
||||
}
|
||||
if (uid)
|
||||
|
|
@ -145,17 +149,17 @@ uid2name(const uid_t uid,
|
|||
struct passwd *pwbufp = NULL;
|
||||
|
||||
if (getpwuid_r(uid, &pwbuf, buf, sizeof(buf), &pwbufp) != 0){
|
||||
clicon_err(OE_UNIX, errno, "getpwuid_r(%u)", uid);
|
||||
clixon_err(OE_UNIX, errno, "getpwuid_r(%u)", uid);
|
||||
goto done;
|
||||
}
|
||||
if (pwbufp == NULL){
|
||||
clicon_err(OE_UNIX, ENOENT, "No such user: %u", uid);
|
||||
clixon_err(OE_UNIX, ENOENT, "No such user: %u", uid);
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (name){
|
||||
if ((*name = strdup(pwbufp->pw_name)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
clixon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
@ -182,11 +186,11 @@ drop_priv_temp(uid_t new_uid)
|
|||
clixon_debug(CLIXON_DBG_DEFAULT, "%s uid:%u", __FUNCTION__, new_uid);
|
||||
/* XXX: implicit declaration of function 'setresuid' on travis */
|
||||
if (setresuid(-1, new_uid, geteuid()) < 0){
|
||||
clicon_err(OE_UNIX, errno, "setresuid");
|
||||
clixon_err(OE_UNIX, errno, "setresuid");
|
||||
goto done;
|
||||
}
|
||||
if (geteuid() != new_uid){
|
||||
clicon_err(OE_UNIX, errno, "geteuid");
|
||||
clixon_err(OE_UNIX, errno, "geteuid");
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -216,17 +220,17 @@ drop_priv_perm(uid_t new_uid)
|
|||
clixon_debug(CLIXON_DBG_DEFAULT, "%s uid:%u", __FUNCTION__, new_uid);
|
||||
|
||||
if (setresuid(new_uid, new_uid, new_uid) < 0){
|
||||
clicon_err(OE_UNIX, errno, "setresuid");
|
||||
clixon_err(OE_UNIX, errno, "setresuid");
|
||||
goto done;
|
||||
}
|
||||
if (getresuid(&ruid, &euid, &suid) < 0){
|
||||
clicon_err(OE_UNIX, errno, "getresuid");
|
||||
clixon_err(OE_UNIX, errno, "getresuid");
|
||||
goto done;
|
||||
}
|
||||
if (ruid != new_uid ||
|
||||
euid != new_uid ||
|
||||
suid != new_uid){
|
||||
clicon_err(OE_UNIX, EINVAL, "Non-matching uid");
|
||||
clixon_err(OE_UNIX, EINVAL, "Non-matching uid");
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -251,15 +255,15 @@ restore_priv(void)
|
|||
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
|
||||
|
||||
if (getresuid(&ruid, &euid, &suid) < 0){
|
||||
clicon_err(OE_UNIX, errno, "setresuid");
|
||||
clixon_err(OE_UNIX, errno, "setresuid");
|
||||
goto done;
|
||||
}
|
||||
if (setresuid(-1, suid, -1) < 0){
|
||||
clicon_err(OE_UNIX, errno, "setresuid");
|
||||
clixon_err(OE_UNIX, errno, "setresuid");
|
||||
goto done;
|
||||
}
|
||||
if (geteuid() != suid){
|
||||
clicon_err(OE_UNIX, EINVAL, "Non-matching uid");
|
||||
clixon_err(OE_UNIX, EINVAL, "Non-matching uid");
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue