/*
SSSD
Kerberos 5 Backend Module -- Utilities
Authors:
Sumit Bose <sbose@redhat.com>
Copyright (C) 2009 Red Hat
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grp.h>
{
int ret;
/* skip call if we already are the requested user */
return EOK;
}
/* drop supplmentary groups first */
if (ret == -1) {
return ret;
}
/* change gid so that root cannot be regained (changes saved gid too) */
if (ret == -1) {
return ret;
}
/* change uid so that root cannot be regained (changes saved uid too) */
/* this call also takes care of dropping CAP_SETUID, so this is a PNR */
if (ret == -1) {
return ret;
}
return EOK;
}
struct sss_creds {
int num_gids;
};
/* This is a reversible version of become_user, and returns the saved
* credentials so that creds can be switched back calling restore_creds */
struct sss_creds **saved_creds)
{
int size;
int ret;
if (saved_creds) {
/* save current user credentials */
if (size == -1) {
goto done;
}
if (!ssc) {
goto done;
}
if (size == -1) {
/* free ssc immediately otherwise the code will try to restore
* wrong creds */
goto done;
}
/* we care only about effective ids */
}
/* if we are regaining root set euid first so that we have CAP_SETUID back,
* ane the other calls work too, otherwise call it last so that we can
* change groups before we loose CAP_SETUID */
if (uid == 0) {
if (ret == -1) {
goto done;
}
}
return EOK;
}
/* try to setgroups first should always work if CAP_SETUID is set,
* otherwise it will always fail, failure is not critical though as
* generally we only really care about uid and at mot primary gid */
if (ret == -1) {
}
/* change gid now, (leaves saved gid to current, so we can restore) */
if (ret == -1) {
goto done;
}
if (uid != 0) {
/* change uid, (leaves saved uid to current, so we can restore) */
if (ret == -1) {
goto done;
}
}
ret = 0;
done:
if (ret) {
/* attempt to restore creds first */
} else if (saved_creds) {
*saved_creds = ssc;
}
return ret;
}
{
if (saved_creds == NULL) {
/* In case save_creds was saved with the UID already dropped */
return EOK;
}
return switch_creds(saved_creds,
}