diff --git a/CHANGELOG.md b/CHANGELOG.md index 94345350..2ba84e79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -77,6 +77,8 @@ Users may have to change how they access the system ### Minor features +* Added autotool check for getresuid (+ related functions) necessary for lowering of priviliges for backend and restconf + * If getresuid is not available, CLICON_RESTCONF_PRIVILEGES must be set to 'none' * Added new startup-mode: `running-startup`: First try running db, if it is empty try startup db. * See [Can startup mode to be extended to support running-startup mode? #234](https://github.com/clicon/clixon/issues/234) * Restconf: added inline configuration using `-R ` command line as an alternative to making advanced restconf configuration diff --git a/configure b/configure index 4f64102e..b542f5ba 100755 --- a/configure +++ b/configure @@ -5564,7 +5564,7 @@ fi fi # -for ac_func in inet_aton sigaction sigvec strlcpy strsep strndup alphasort versionsort getpeereid setns +for ac_func in inet_aton sigaction sigvec strlcpy strsep strndup alphasort versionsort getpeereid setns getresuid do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" diff --git a/configure.ac b/configure.ac index 7de5fec5..280dd7cc 100644 --- a/configure.ac +++ b/configure.ac @@ -296,7 +296,7 @@ if test "${with_libxml2}"; then fi # -AC_CHECK_FUNCS(inet_aton sigaction sigvec strlcpy strsep strndup alphasort versionsort getpeereid setns) +AC_CHECK_FUNCS(inet_aton sigaction sigvec strlcpy strsep strndup alphasort versionsort getpeereid setns getresuid) # Checks for getsockopt options for getting unix socket peer credentials on # Linux diff --git a/include/clixon_config.h.in b/include/clixon_config.h.in index ae1ae28a..2820bd59 100644 --- a/include/clixon_config.h.in +++ b/include/clixon_config.h.in @@ -30,6 +30,9 @@ /* Define to 1 if you have the `getpeereid' function. */ #undef HAVE_GETPEEREID +/* Define to 1 if you have the `getresuid' function. */ +#undef HAVE_GETRESUID + /* Define to 1 if you have the `inet_aton' function. */ #undef HAVE_INET_ATON diff --git a/lib/src/clixon_uid.c b/lib/src/clixon_uid.c index f9f4a2aa..f28b14ea 100644 --- a/lib/src/clixon_uid.c +++ b/lib/src/clixon_uid.c @@ -170,6 +170,7 @@ uid2name(const uid_t uid, int drop_priv_temp(uid_t new_uid) { +#ifdef HAVE_GETRESUID int retval = -1; /* XXX: implicit declaration of function 'setresuid' on travis */ @@ -184,6 +185,10 @@ drop_priv_temp(uid_t new_uid) retval = 0; done: return retval; +#else + clicon_debug(1, "%s Drop privileges not implemented on this platform since getresuid is not available", __FUNCTION__); + return 0; +#endif } /*! Permanently drop privileges @@ -192,6 +197,7 @@ drop_priv_temp(uid_t new_uid) int drop_priv_perm(uid_t new_uid) { +#ifdef HAVE_GETRESUID int retval = -1; uid_t ruid; uid_t euid; @@ -214,12 +220,17 @@ drop_priv_perm(uid_t new_uid) retval = 0; done: return retval; +#else + clicon_debug(1, "%s Drop privileges not implemented on this platform since getresuid is not available", __FUNCTION__); + return 0; +#endif } /*! Restore privileges to saved level */ int restore_priv(void) { +#ifdef HAVE_GETRESUID int retval = -1; uid_t ruid; uid_t euid; @@ -240,4 +251,8 @@ restore_priv(void) retval = 0; done: return retval; +#else + clicon_debug(1, "%s Drop privileges not implemented on this platform since getresuid is not available", __FUNCTION__); + return 0; +#endif } diff --git a/yang/clixon/clixon-config@2021-05-20.yang b/yang/clixon/clixon-config@2021-05-20.yang index 7dafd4bf..4a8cca7b 100644 --- a/yang/clixon/clixon-config@2021-05-20.yang +++ b/yang/clixon/clixon-config@2021-05-20.yang @@ -536,7 +536,10 @@ module clixon-config { default drop_perm; description "Restconf privileges mode. - If drop_perm or drop_temp then drop privileges to CLICON_RESTCONF_USER."; + If drop_perm or drop_temp then drop privileges to CLICON_RESTCONF_USER. + If the platform does not support getresuid and accompanying functions, the mode + must be set to 'none'. + "; } leaf CLICON_CLI_DIR { type string;