memerror in uid-get. reinsert save config yang spec (removed for wrong reasons previously causing memleaks)
This commit is contained in:
parent
69b27f3280
commit
c4954f5c43
9 changed files with 83 additions and 15 deletions
|
|
@ -73,10 +73,11 @@
|
|||
#include "clixon_xpath.h"
|
||||
#include "clixon_data.h"
|
||||
|
||||
/*! Get YANG specification for application
|
||||
/*! Get YANG specification for application specs
|
||||
* Must use hash functions directly since they are not strings.
|
||||
* @param[in] h Clicon handle
|
||||
* @retval yspec Yang spec
|
||||
* @see clicon_config_yang for the configuration yang
|
||||
*/
|
||||
yang_stmt *
|
||||
clicon_dbspec_yang(clicon_handle h)
|
||||
|
|
@ -90,10 +91,10 @@ clicon_dbspec_yang(clicon_handle h)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/*! Set yang specification for application
|
||||
* ys must be a malloced pointer
|
||||
/*! Set yang specification for application specifications
|
||||
* @param[in] h Clicon handle
|
||||
* @param[in] yspec Yang spec
|
||||
* @param[in] yspec Yang spec (malloced pointer)
|
||||
* @see clicon_config_yang_set for the configuration yang
|
||||
*/
|
||||
int
|
||||
clicon_dbspec_yang_set(clicon_handle h,
|
||||
|
|
@ -109,6 +110,42 @@ clicon_dbspec_yang_set(clicon_handle h,
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*! Get YANG specification for clixon config (separate from application yangs)
|
||||
* @param[in] h Clicon handle
|
||||
* @retval yspec Yang spec
|
||||
* @see clicon_dbspec_yang for the application specs
|
||||
*/
|
||||
yang_stmt *
|
||||
clicon_config_yang(clicon_handle h)
|
||||
{
|
||||
clicon_hash_t *cdat = clicon_data(h);
|
||||
size_t len;
|
||||
void *p;
|
||||
|
||||
if ((p = clicon_hash_value(cdat, "control_yang", &len)) != NULL)
|
||||
return *(yang_stmt **)p;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*! Set yang specification for configuration
|
||||
* @param[in] h Clicon handle
|
||||
* @param[in] yspec Yang spec (malloced pointer)
|
||||
* @see clicon_dbspec_yang_set for the application specs
|
||||
*/
|
||||
int
|
||||
clicon_config_yang_set(clicon_handle h,
|
||||
yang_stmt *ys)
|
||||
{
|
||||
clicon_hash_t *cdat = clicon_data(h);
|
||||
|
||||
/* It is the pointer to ys that should be copied by hash,
|
||||
so we send a ptr to the ptr to indicate what to copy.
|
||||
*/
|
||||
if (clicon_hash_add(cdat, "control_yang", &ys, sizeof(ys)) == NULL)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*! Get Global "canonical" namespace context
|
||||
* Canonical: use prefix and namespace specified in the yang modules.
|
||||
* @param[in] h Clicon handle
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ name2uid(const char *name,
|
|||
|
||||
/*! Translate uid to user name
|
||||
* @param[in] uid User id
|
||||
* @param[out] name User name
|
||||
* @param[out] name User name (Malloced, need to be freed)
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error. or not found
|
||||
*/
|
||||
|
|
@ -131,7 +131,7 @@ uid2name(const uid_t uid,
|
|||
{
|
||||
int retval = -1;
|
||||
char buf[1024];
|
||||
struct passwd pwbuf;
|
||||
struct passwd pwbuf = {0,};
|
||||
struct passwd *pwbufp = NULL;
|
||||
|
||||
if (getpwuid_r(uid, &pwbuf, buf, sizeof(buf), &pwbufp) != 0){
|
||||
|
|
@ -139,17 +139,21 @@ uid2name(const uid_t uid,
|
|||
goto done;
|
||||
}
|
||||
if (pwbufp == NULL){
|
||||
clicon_err(OE_UNIX, 0, "No such user: %u", uid);
|
||||
clicon_err(OE_UNIX, ENOENT, "No such user: %u", uid);
|
||||
goto done;
|
||||
}
|
||||
if (name)
|
||||
*name = pwbufp->pw_name;
|
||||
|
||||
if (name){
|
||||
if ((*name = strdup(pwbufp->pw_name)) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "strdup");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
retval = 0;
|
||||
done:
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
/* Privileges drop perm, temp and restore
|
||||
* @see https://www.usenix.org/legacy/events/sec02/full_papers/chen/chen.pdf
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue