* Backend daemon drops privileges after initialization (to not run as root)

* New config option `CLICON_USER` with default value `clicon`
  * Can also be set with `-U <user>` clixon_backend command-line option
This commit is contained in:
Olof hagsand 2019-09-11 21:24:14 +02:00
parent 3806f7652e
commit 3d5abb77f9
60 changed files with 238 additions and 93 deletions

View file

@ -2,6 +2,11 @@
## 4.2.0 (Expected: October) ## 4.2.0 (Expected: October)
### Major New features
* Backend daemon drops privileges after initialization (to not run as root)
* New config option `CLICON_USER` with default value `clicon`
* Can also be set with `-U <user>` clixon_backend command-line option
### API changes on existing features (you may need to change your code) ### API changes on existing features (you may need to change your code)
* Restconf top-level operations GET root resource modified to comply with RFC 8040 Sec 3.1 * Restconf top-level operations GET root resource modified to comply with RFC 8040 Sec 3.1
* non-pretty print remove all spaces, eg `{"operations":{"clixon-example:client-rpc":[null]` * non-pretty print remove all spaces, eg `{"operations":{"clixon-example:client-rpc":[null]`
@ -67,6 +72,7 @@
* `204 No Content` for replaced resources. * `204 No Content` for replaced resources.
* RESTCONF PUT/POST `Content-Type` is enforced * RESTCONF PUT/POST `Content-Type` is enforced
* Before accepted JSON as default, now Content-Type must be explicit, such as `Content-Type: application/yang-data+json` * Before accepted JSON as default, now Content-Type must be explicit, such as `Content-Type: application/yang-data+json`
* If not, you will get 415 unsupported media type
* RESTCONF identities has changed to use module names instead of prefixes following RFC8040: * RESTCONF identities has changed to use module names instead of prefixes following RFC8040:
* Eg, `curl -X POST -d '{"type":"ex:eth"}` --> `curl -X POST -d '{"type":"ietf-interfaces:eth"`} * Eg, `curl -X POST -d '{"type":"ex:eth"}` --> `curl -X POST -d '{"type":"ietf-interfaces:eth"`}
* JSON changes * JSON changes

View file

@ -74,7 +74,7 @@
#include "backend_startup.h" #include "backend_startup.h"
/* Command line options to be passed to getopt(3) */ /* Command line options to be passed to getopt(3) */
#define BACKEND_OPTS "hD:f:l:d:p:b:Fza:u:P:1s:c:g:y:o:" #define BACKEND_OPTS "hD:f:l:d:p:b:Fza:u:P:1s:c:U:g:y:o:"
#define BACKEND_LOGFILE "/usr/local/var/clixon_backend.log" #define BACKEND_LOGFILE "/usr/local/var/clixon_backend.log"
@ -220,6 +220,72 @@ nacm_load_external(clicon_handle h)
return retval; return retval;
} }
static int
xmldb_drop_priv(clicon_handle h,
const char *db,
uid_t uid,
gid_t gid)
{
int retval = -1;
char *filename = NULL;
if (xmldb_db2file(h, db, &filename) < 0)
goto done;
if (chown(filename, uid, gid) < 0){
clicon_err(OE_UNIX, errno, "chown");
goto done;
}
retval = 0;
done:
if (filename)
free(filename);
return retval;
}
/*! Drop root privileges uid and gid to Clixon user/group
* @param[in] h Clicon handle
*/
static int
drop_priv(clicon_handle h,
uid_t uid,
gid_t gid)
{
int retval = -1;
if (xmldb_exists(h, "running") != 1)
if (xmldb_create(h, "running") < 0)
goto done;
if (xmldb_drop_priv(h, "running", uid, gid) < 0)
goto done;
if (xmldb_exists(h, "candidate") != 1)
if (xmldb_create(h, "candidate") < 0)
goto done;
if (xmldb_drop_priv(h, "candidate", uid, gid) < 0)
goto done;
if (xmldb_exists(h, "startup") != 1)
if (xmldb_create(h, "startup") < 0)
goto done;
if (xmldb_drop_priv(h, "startup", uid, gid) < 0)
goto done;
if (setgid(gid) == -1) {
clicon_err(OE_DEMON, errno, "setgid %d", gid);
goto done;
}
if (setuid(uid) == -1) {
clicon_err(OE_DEMON, errno, "setuid %d", uid);
goto done;
}
/* Verify you cannot regain root privileges */
if (setuid(0) != -1){
clicon_err(OE_DEMON, EPERM, "Could regain root privilieges");
goto done;
}
retval = 0;
done:
return retval;
}
/*! Given a retval, transform to status or fatal error /*! Given a retval, transform to status or fatal error
* *
* @param[in] ret Return value from xml validation function * @param[in] ret Return value from xml validation function
@ -290,6 +356,7 @@ usage(clicon_handle h,
"\t-1\t\tRun once and then quit (dont wait for events)\n" "\t-1\t\tRun once and then quit (dont wait for events)\n"
"\t-s <mode>\tSpecify backend startup mode: none|startup|running|init)\n" "\t-s <mode>\tSpecify backend startup mode: none|startup|running|init)\n"
"\t-c <file>\tLoad extra xml configuration, but don't commit.\n" "\t-c <file>\tLoad extra xml configuration, but don't commit.\n"
"\t-U <user>\tRun backend daemon as this user\n"
"\t-g <group>\tClient membership required to this group (default: %s)\n" "\t-g <group>\tClient membership required to this group (default: %s)\n"
"\t-y <file>\tLoad yang spec file (override yang main module)\n" "\t-y <file>\tLoad yang spec file (override yang main module)\n"
@ -303,6 +370,7 @@ usage(clicon_handle h,
exit(-1); exit(-1);
} }
int int
main(int argc, main(int argc,
char **argv) char **argv)
@ -314,7 +382,8 @@ main(int argc,
int once; int once;
enum startup_mode_t startup_mode; enum startup_mode_t startup_mode;
char *extraxml_file; char *extraxml_file;
char *config_group; char *backend_user = NULL;
char *backend_group = NULL;
char *argv0 = argv[0]; char *argv0 = argv[0];
struct stat st; struct stat st;
clicon_handle h; clicon_handle h;
@ -333,6 +402,8 @@ main(int argc,
enum startup_status status = STARTUP_ERR; /* Startup status */ enum startup_status status = STARTUP_ERR; /* Startup status */
int ret; int ret;
char *dir; char *dir;
gid_t gid = -1;
uid_t uid = -1;
/* In the startup, logs to stderr & syslog and debug flag set later */ /* In the startup, logs to stderr & syslog and debug flag set later */
clicon_log_init(__PROGRAM__, LOG_INFO, logdst); clicon_log_init(__PROGRAM__, LOG_INFO, logdst);
@ -464,6 +535,10 @@ main(int argc,
case 'c': /* Load application config */ case 'c': /* Load application config */
extraxml_file = optarg; extraxml_file = optarg;
break; break;
case 'U': /* config user (for socket and drop privileges) */
if (clicon_option_add(h, "CLICON_SOCK", optarg) < 0)
goto done;
break;
case 'g': /* config socket group */ case 'g': /* config socket group */
if (clicon_option_add(h, "CLICON_SOCK_GROUP", optarg) < 0) if (clicon_option_add(h, "CLICON_SOCK_GROUP", optarg) < 0)
goto done; goto done;
@ -541,22 +616,32 @@ main(int argc,
if (sockfamily==AF_UNIX && lstat(sock, &st) == 0) if (sockfamily==AF_UNIX && lstat(sock, &st) == 0)
unlink(sock); unlink(sock);
/* Sanity check: config group exists */ /* XXX maybe only if !foreground */
if ((config_group = clicon_sock_group(h)) == NULL){ /* Sanity check: backend user exists */
if ((backend_user = clicon_user(h)) == NULL){
clicon_err(OE_FATAL, 0, "clicon_user option not set");
return -1;
}
if (name2uid(backend_user, &uid) < 0){
clicon_log(LOG_ERR, "'%s' does not seem to be a valid user .\n", backend_user);
goto done;
}
/* Sanity check: backend group exists */
if ((backend_group = clicon_sock_group(h)) == NULL){
clicon_err(OE_FATAL, 0, "clicon_sock_group option not set"); clicon_err(OE_FATAL, 0, "clicon_sock_group option not set");
return -1; return -1;
} }
if (group_name2gid(backend_group, &gid) < 0){
if (group_name2gid(config_group, NULL) < 0){
clicon_log(LOG_ERR, "'%s' does not seem to be a valid user group.\n" /* \n required here due to multi-line log */ clicon_log(LOG_ERR, "'%s' does not seem to be a valid user group.\n" /* \n required here due to multi-line log */
"The config demon requires a valid group to create a server UNIX socket\n" "The config demon requires a valid group to create a server UNIX socket\n"
"Define a valid CLICON_SOCK_GROUP in %s or via the -g option\n" "Define a valid CLICON_SOCK_GROUP in %s or via the -g option\n"
"or create the group and add the user to it. On linux for example:" "or create the group and add the user to it. On linux for example:"
" sudo groupadd %s\n" " sudo groupadd %s\n"
" sudo usermod -a -G %s user\n", " sudo usermod -a -G %s user\n",
config_group, clicon_configfile(h), backend_group, clicon_configfile(h),
config_group, config_group); backend_group, backend_group);
return -1; goto done;
} }
/* Publish stream on pubsub channels. /* Publish stream on pubsub channels.
@ -737,6 +822,7 @@ main(int argc,
fprintf(stderr, "config: daemon"); fprintf(stderr, "config: daemon");
exit(-1); exit(-1);
} }
} }
/* Write pid-file */ /* Write pid-file */
if ((pid = pidfile_write(pidfile)) < 0) if ((pid = pidfile_write(pidfile)) < 0)
@ -751,6 +837,7 @@ main(int argc,
clicon_err(OE_DEMON, errno, "Setting signal"); clicon_err(OE_DEMON, errno, "Setting signal");
goto done; goto done;
} }
/* Initialize server socket and save it to handle */ /* Initialize server socket and save it to handle */
if ((ss = backend_server_socket(h)) < 0) if ((ss = backend_server_socket(h)) < 0)
goto done; goto done;
@ -758,6 +845,10 @@ main(int argc,
goto done; goto done;
if (debug) if (debug)
clicon_option_dump(h, debug); clicon_option_dump(h, debug);
/* Drop root privileges (unless root) */
if (uid != 0)
if (drop_priv(h, uid, gid) < 0)
goto done;
if (stream_timer_setup(0, h) < 0) if (stream_timer_setup(0, h) < 0)
goto done; goto done;

View file

@ -467,7 +467,7 @@ Each plugin is initiated with an API struct followed by a plugin init function a
return &api; /* Return NULL on error */ return &api; /* Return NULL on error */
} }
``` ```
For more info see [../example/main/README.md] For more info see [the main example](../example/main/README.md)
## How do I write a commit function? ## How do I write a commit function?
In the example, you write a commit function in example_backend.c. In the example, you write a commit function in example_backend.c.

View file

@ -8,16 +8,16 @@ NETCONF and RESTCONF interfaces, an embedded database and transaction
mechanism. mechanism.
* [Background](#background) * [Background](#background)
* [Frequently asked questions (FAQ)](doc/FAQ.md) * [Frequently asked questions (FAQ)](FAQ.md)
* [Hello world](example/hello/README.md) * [Hello world](example/hello/README.md)
* [Changelog](CHANGELOG.md) * [Changelog](CHANGELOG.md)
* [Installation](doc/INSTALL.md) * [Installation](INSTALL.md)
* [Licenses](#licenses) * [Licenses](#licenses)
* [Support](#support) * [Support](#support)
* [Dependencies](#dependencies) * [Dependencies](#dependencies)
* [Extending](#extending) * [Extending](#extending)
* [Yang](#yang) * [Yang](#yang)
* [CLI](doc/CLI.md) * [CLI](CLI.md)
* [XML and XPATH](#xml-and-xpath) * [XML and XPATH](#xml-and-xpath)
* [Netconf](#netconf) * [Netconf](#netconf)
* [Restconf](#restconf) * [Restconf](#restconf)
@ -28,9 +28,9 @@ mechanism.
* [Runtime](#runtime) * [Runtime](#runtime)
* [Clixon project page](http://www.clicon.org) * [Clixon project page](http://www.clicon.org)
* [Tests and CI](test/README.md) * [Tests and CI](test/README.md)
* [Scaling: large lists](doc/scaling/large-lists.md) * [Scaling: large lists](scaling/large-lists.md)
* [Containers](docker/README.md) * [Containers](docker/README.md)
* [Roadmap](doc/ROADMAP.md) * [Roadmap](ROADMAP.md)
* [Standard compliance](#standard-compliance) * [Standard compliance](#standard-compliance)
* [Reference manual](#reference) * [Reference manual](#reference)
@ -81,7 +81,7 @@ specialize functions. Clixon is extended by writing
plugins for cli, backend, netconf and restconf. plugins for cli, backend, netconf and restconf.
Plugins are written in C and easiest is to look at Plugins are written in C and easiest is to look at
[example](example/README.md) or consulting the [FAQ](doc/FAQ.md). [example](example/README.md) or consulting the [FAQ](FAQ.md).
## Yang ## Yang
@ -265,7 +265,7 @@ For CLI, login is typically made via SSH. For netconf, SSH netconf
subsystem can be used. subsystem can be used.
Restconf however needs credentials. This is done by writing a credentials callback in a restconf plugin. See: Restconf however needs credentials. This is done by writing a credentials callback in a restconf plugin. See:
* [FAQ](doc/FAQ.md#how-do-i-write-an-authentication-callback). * [FAQ](FAQ.md#how-do-i-write-an-authentication-callback).
* [Example](example/README.md) has an example how to do this with HTTP basic auth. * [Example](example/README.md) has an example how to do this with HTTP basic auth.
* It has been done for other projects using Oauth2 or (https://github.com/CESNET/Netopeer2/tree/master/server/configuration) * It has been done for other projects using Oauth2 or (https://github.com/CESNET/Netopeer2/tree/master/server/configuration)
@ -300,7 +300,7 @@ The functionality is as follows (references to sections in [RFC8341](https://too
## Runtime ## Runtime
<img src="doc/clixon_example_sdk.png" alt="clixon sdk" style="width: 180px;"/> <img src="clixon_example_sdk.png" alt="clixon sdk" style="width: 180px;"/>
The figure shows the SDK runtime of Clixon. The figure shows the SDK runtime of Clixon.

View file

@ -90,8 +90,8 @@ RUN apk add --update nginx
# Expose nginx port for restconf # Expose nginx port for restconf
EXPOSE 80 EXPOSE 80
# Create clicon group # Create clicon user and group
RUN addgroup clicon RUN adduser -D -H clicon
RUN adduser nginx clicon RUN adduser nginx clicon
RUN adduser www-data clicon RUN adduser www-data clicon

View file

@ -108,8 +108,8 @@ RUN apk add --update sudo curl procps grep make bash
# Expose nginx port for restconf # Expose nginx port for restconf
EXPOSE 80 EXPOSE 80
# Create clicon group # Create clicon user and group
RUN addgroup clicon RUN adduser -D -H clicon
RUN adduser nginx clicon RUN adduser nginx clicon
RUN adduser www-data clicon RUN adduser www-data clicon

View file

@ -43,6 +43,8 @@ int clicon_file_dirent(const char *dir, struct dirent **ent,
int clicon_file_copy(char *src, char *target); int clicon_file_copy(char *src, char *target);
int group_name2gid(char *name, gid_t *gid); int group_name2gid(const char *name, gid_t *gid);
int name2uid(const char *name, uid_t *uid);
#endif /* _CLIXON_FILE_H_ */ #endif /* _CLIXON_FILE_H_ */

View file

@ -167,6 +167,9 @@ static inline char *clicon_sock(clicon_handle h){
static inline char *clicon_sock_group(clicon_handle h){ static inline char *clicon_sock_group(clicon_handle h){
return clicon_option_str(h, "CLICON_SOCK_GROUP"); return clicon_option_str(h, "CLICON_SOCK_GROUP");
} }
static inline char *clicon_user(clicon_handle h){
return clicon_option_str(h, "CLICON_USER");
}
static inline char *clicon_backend_pidfile(clicon_handle h){ static inline char *clicon_backend_pidfile(clicon_handle h){
return clicon_option_str(h, "CLICON_BACKEND_PIDFILE"); return clicon_option_str(h, "CLICON_BACKEND_PIDFILE");
} }

View file

@ -398,8 +398,8 @@ xmldb_delete(clicon_handle h,
if (xmldb_db2file(h, db, &filename) < 0) if (xmldb_db2file(h, db, &filename) < 0)
goto done; goto done;
if (lstat(filename, &sb) == 0) if (lstat(filename, &sb) == 0)
if (unlink(filename) < 0){ if (truncate(filename, 0) < 0){
clicon_err(OE_DB, errno, "unlink %s", filename); clicon_err(OE_DB, errno, "truncate %s", filename);
goto done; goto done;
} }
retval = 0; retval = 0;

View file

@ -219,9 +219,10 @@ clicon_file_copy(char *src,
* @retval -1 Error. or not found * @retval -1 Error. or not found
*/ */
int int
group_name2gid(char *name, group_name2gid(const char *name,
gid_t *gid) gid_t *gid)
{ {
int retval = -1;
char buf[1024]; char buf[1024];
struct group g0; struct group g0;
struct group *gr = &g0; struct group *gr = &g0;
@ -231,14 +232,39 @@ group_name2gid(char *name,
/* This leaks memory in ubuntu */ /* This leaks memory in ubuntu */
if (getgrnam_r(name, gr, buf, sizeof(buf), &gtmp) < 0){ if (getgrnam_r(name, gr, buf, sizeof(buf), &gtmp) < 0){
clicon_err(OE_UNIX, errno, "getgrnam_r(%s)", name); clicon_err(OE_UNIX, errno, "getgrnam_r(%s)", name);
return -1; goto done;
} }
if (gtmp == NULL){ if (gtmp == NULL){
clicon_err(OE_UNIX, 0, "No such group: %s", name); clicon_err(OE_UNIX, 0, "No such group: %s", name);
fprintf(stderr, "No such group %s\n", name); goto done;
return -1;
} }
if (gid) if (gid)
*gid = gr->gr_gid; *gid = gr->gr_gid;
return 0; retval = 0;
done:
return retval;
}
int
name2uid(const char *name,
uid_t *uid)
{
int retval = -1;
char buf[1024];
struct passwd pwbuf;
struct passwd *pwbufp = NULL;
if (getpwnam_r(name, &pwbuf, buf, sizeof(buf), &pwbufp) != 0){
clicon_err(OE_UNIX, errno, "getpwnam_r(%s)", name);
goto done;
}
if (pwbufp == NULL){
clicon_err(OE_UNIX, 0, "No such user: %s", name);
goto done;
}
if (uid)
*uid = pwbufp->pw_uid;
retval = 0;
done:
return retval;
} }

View file

@ -91,6 +91,9 @@ testname=
: ${IETFRFC=../yang/standard} : ${IETFRFC=../yang/standard}
#: ${IETFRFC=$YANGMODELS/standard/ietf/RFC} #: ${IETFRFC=$YANGMODELS/standard/ietf/RFC}
# Backend user
BUSER=clicon
# Follow the binary programs that can be parametrized (eg with valgrind) # Follow the binary programs that can be parametrized (eg with valgrind)
: ${clixon_cli:=clixon_cli} : ${clixon_cli:=clixon_cli}
@ -170,6 +173,7 @@ stop_backend(){
sleep 1 sleep 1
checkvalgrind checkvalgrind
fi fi
sudo pkill -f clixon_backend # extra ($BUSER?)
} }
# Wait for restconf to stop sending 502 Bad Gateway # Wait for restconf to stop sending 502 Bad Gateway

View file

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
# yang augment and identityref tests in different modules # yang augment and identityref tests in different modules
# See RFC7950 Sec 7.17 # See RFC7950 Sec 7.17
# This test defines an example-augment module which augments an interface # This test defines an example-augment module which augments an interface
@ -218,12 +218,11 @@ fi
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi
# kill backend # kill backend
stop_backend -f $cfg stop_backend -f $cfg
sudo pkill -u root -f clixon_backend
rm -rf $dir rm -rf $dir

View file

@ -287,7 +287,7 @@ fi
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -126,7 +126,7 @@ fi
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -118,7 +118,7 @@ fi
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -132,7 +132,7 @@ fi
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -163,7 +163,7 @@ fi
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -191,7 +191,7 @@ fi
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -316,7 +316,7 @@ fi
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -194,7 +194,7 @@ fi
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -231,7 +231,7 @@ fi
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -188,7 +188,7 @@ fi
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -153,7 +153,7 @@ EOF
if [ $BE -ne 0 ]; then # Bring your own backend if [ $BE -ne 0 ]; then # Bring your own backend
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -216,7 +216,7 @@ fi
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -279,7 +279,7 @@ fi
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -258,7 +258,7 @@ fi
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -223,7 +223,7 @@ fi
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -211,7 +211,7 @@ fi
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -395,7 +395,7 @@ fi
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -743,7 +743,7 @@ expectfn "$clixon_cli -1f $cfg -l o set c threematch abcg" 255 '^CLI syntax erro
if [ $BE -ne 0 ]; then if [ $BE -ne 0 ]; then
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -237,7 +237,7 @@ fi
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -145,7 +145,7 @@ fi
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -278,7 +278,7 @@ fi
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -200,7 +200,7 @@ fi
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -116,7 +116,7 @@ fi
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -261,7 +261,7 @@ fi
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -157,7 +157,7 @@ fi
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -209,7 +209,7 @@ fi
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -89,7 +89,7 @@ testrun(){
if [ $BE -ne 0 ]; then if [ $BE -ne 0 ]; then
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi
@ -120,8 +120,11 @@ sudo rm -f $dir/startup_db;
new "Run without startup option, check running is copied" new "Run without startup option, check running is copied"
testrun "" testrun ""
new "Check startup should not exist" new "Check startup is empty"
if [ -f $dir/startup_db ]; then if [ ! -f $dir/startup_db ]; then
err "startup should not exist" err "startup does not exist"
fi
if [ -s $dir/startup_db ]; then
err "startup is not empty"
fi fi
rm -rf $dir rm -rf $dir

View file

@ -164,7 +164,7 @@ fi
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -102,7 +102,7 @@ testrun(){
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -291,7 +291,7 @@ fi
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -224,7 +224,7 @@ fi
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -311,7 +311,7 @@ fi
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -628,7 +628,7 @@ EOF
if [ $BE -ne 0 ]; then if [ $BE -ne 0 ]; then
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -306,7 +306,7 @@ testrange string "012" "01234567890" ""
if [ $BE -ne 0 ]; then if [ $BE -ne 0 ]; then
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -107,7 +107,7 @@ fi
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -216,7 +216,7 @@ fi
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -283,7 +283,7 @@ runtest(){
if [ $BE -ne 0 ]; then if [ $BE -ne 0 ]; then
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -274,7 +274,7 @@ stop_restconf
if [ $BE -ne 0 ]; then if [ $BE -ne 0 ]; then
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -285,7 +285,7 @@ testrun(){
if [ $BE -ne 0 ]; then if [ $BE -ne 0 ]; then
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -151,7 +151,7 @@ stop_restconf
if [ $BE -ne 0 ]; then if [ $BE -ne 0 ]; then
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -147,7 +147,7 @@ fi
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -112,7 +112,7 @@ fi
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -286,12 +286,11 @@ fi
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=$(pgrep -u root -f clixon_backend) pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi
# kill backend # kill backend
stop_backend -f "$cfg" stop_backend -f "$cfg"
sudo pkill -u root -f clixon_backend
rm -rf "$dir" rm -rf "$dir"

View file

@ -114,7 +114,7 @@ expecteof "$clixon_netconf -qf $cfg -D $DBG" 0 "<rpc><get-config><source><candid
if [ $BE -ne 0 ]; then if [ $BE -ne 0 ]; then
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -100,7 +100,7 @@ expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><edit-config><target><candidate/></
if [ $BE -ne 0 ]; then if [ $BE -ne 0 ]; then
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi
@ -149,7 +149,7 @@ expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><edit-config><target><candidate/></
if [ $BE -ne 0 ]; then if [ $BE -ne 0 ]; then
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi
@ -193,7 +193,7 @@ expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><edit-config><target><candidate/></
if [ $BE -ne 0 ]; then if [ $BE -ne 0 ]; then
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi
@ -237,7 +237,7 @@ expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><edit-config><target><candidate/></
if [ $BE -ne 0 ]; then if [ $BE -ne 0 ]; then
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi
@ -281,7 +281,7 @@ expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><edit-config><target><candidate/></
if [ $BE -ne 0 ]; then if [ $BE -ne 0 ]; then
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi
@ -326,7 +326,7 @@ expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><edit-config><target><candidate/></
if [ $BE -ne 0 ]; then if [ $BE -ne 0 ]; then
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi
@ -372,7 +372,7 @@ expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><edit-config><target><candidate/></
if [ $BE -ne 0 ]; then if [ $BE -ne 0 ]; then
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi
@ -418,7 +418,7 @@ expecteof "$clixon_netconf -qf $cfg" 0 '<rpc><edit-config><target><candidate/></
if [ $BE -ne 0 ]; then if [ $BE -ne 0 ]; then
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -137,7 +137,7 @@ if [ $BE -eq 0 ]; then
fi fi
new "Kill backend" new "Kill backend"
# Check if premature kill # Check if premature kill
pid=`pgrep -u root -f clixon_backend` pid=$(pgrep -u $BUSER -f clixon_backend)
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
err "backend already dead" err "backend already dead"
fi fi

View file

@ -41,7 +41,7 @@ datarootdir = @datarootdir@
# See also STD_YANG_INSTALLDIR for the standard yang files # See also STD_YANG_INSTALLDIR for the standard yang files
YANG_INSTALLDIR = @YANG_INSTALLDIR@ YANG_INSTALLDIR = @YANG_INSTALLDIR@
YANGSPECS = clixon-config@2019-06-05.yang YANGSPECS = clixon-config@2019-09-11.yang
YANGSPECS += clixon-lib@2019-08-13.yang YANGSPECS += clixon-lib@2019-08-13.yang
YANGSPECS += clixon-rfc5277@2008-07-01.yang YANGSPECS += clixon-rfc5277@2008-07-01.yang
YANGSPECS += clixon-xml-changelog@2019-03-21.yang YANGSPECS += clixon-xml-changelog@2019-03-21.yang

View file

@ -39,6 +39,10 @@ module clixon-config {
***** END LICENSE BLOCK *****"; ***** END LICENSE BLOCK *****";
revision 2019-09-11 {
description
"Added: CLICON_USER: user that backend daemon drops privileges to";
revision 2019-06-05 { revision 2019-06-05 {
description description
"Added: CLICON_YANG_REGEXP, CLICON_CLI_TAB_MODE, "Added: CLICON_YANG_REGEXP, CLICON_CLI_TAB_MODE,
@ -415,7 +419,15 @@ module clixon-config {
leaf CLICON_SOCK_GROUP { leaf CLICON_SOCK_GROUP {
type string; type string;
default "clicon"; default "clicon";
description "Group membership to access clixon_backend unix socket"; description
"Group membership to access clixon_backend unix socket and gid for
deamon";
}
leaf CLICON_USER {
type string;
default "clicon";
description
"User to access clixon_backend unix socket and uid for deamon";
} }
leaf CLICON_BACKEND_PIDFILE { leaf CLICON_BACKEND_PIDFILE {
type string; type string;