Commit cb84afec authored by Jondy Zhao's avatar Jondy Zhao

support to switch user by slapos node command

parent a9a9707d
diff --git a/options.py~ b/options.py
old mode 100644
new mode 100755
index 3ccab60..e220c10
--- a/options.py~
+++ b/options.py
@@ -1197,7 +1197,7 @@ class ServerOptions(Options):
return
if current_uid != 0:
- return "Can't drop privilege as nonroot user"
+ pass # return "Can't drop privilege as nonroot user"
gid = pwrec[3]
if hasattr(os, 'setgroups'):
@@ -1219,7 +1219,7 @@ class ServerOptions(Options):
os.setgid(gid)
except OSError:
return 'Could not set group id of effective user'
- os.setuid(uid)
+ os.setreuid(-1, uid)
def waitpid(self):
# need pthread_sigmask here to avoid concurrent sigchild, but
#include <sys/unistd.h>
#include <sys/cygwin.h>
#include <stdio.h>
#include <errno.h>
int main(int argc, char *argv[])
{
const char *username = NULL;
const char *newpwd = NULL;
if (argc == 1 || argc > 3) {
fprintf(stderr, "Usage: regpwd username [password]\n");
return 1;
}
username = argv[1];
if (argc == 3)
newpwd = argv[2];
if (!strcmp (username, getlogin ()))
username = NULL;
if (cygwin_internal (CW_SET_PRIV_KEY, newpwd, username)) {
fprintf(stderr, "Storing password failed: %s", strerror (errno));
return 1;
}
return 0;
}
......@@ -38,6 +38,9 @@
# -s
# Shell used by user
#
# This script will set password for each new user, the password is
# same as the account, and will be saved in the registry.
#
export PATH=/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin:$PATH
if ! source /usr/share/csih/cygwin-service-installation-helper.sh ; then
echo "Error: Download the csih package at first, I need this file:"
......@@ -92,8 +95,8 @@ function create_unprivileged_user()
if [ "${unpriv_user_in_sam}" != "yes" ]
then
dos_var_empty=$(/usr/bin/cygpath -w ${2-${LOCALSTATEDIR}/empty})
csih_call_winsys32 net user "${unpriv_user}" /add /fullname:"${unpriv_user} nexedi slapos" \
"/homedir:${dos_var_empty}" /active:no > /dev/null 2>&1 && unpriv_user_in_sam=yes
csih_call_winsys32 net user "${unpriv_user}" "${unpriv_user}" /add \
/fullname:"${unpriv_user} Nexedi Slapos" > /dev/null 2>&1 && unpriv_user_in_sam=yes
if [ "${unpriv_user_in_sam}" != "yes" ]
then
csih_warning "Creation of user '${unpriv_user}' failed!"
......@@ -194,6 +197,9 @@ fi
create_unprivileged_user ${USER_NAME} $USER_HOME ||
(echo "Failed to create user ${USER_NAME}" ; exit 1)
regpwd ${USER_NAME} ${USER_NAME} ||
(echo "Save ${USER_NAME}'s password failed" ; exit 1)
for grpname in ${USER_INIT_GROUP} ${USER_OTHER_GROUP} ; do
[[ -z "$grpname" ]] && continue
add_member_to_group ${USER_NAME} $grpname ||
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment