Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
HPCasCode
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hpc-team
HPCasCode
Commits
4854dbad
Commit
4854dbad
authored
8 years ago
by
Philip Chan
Browse files
Options
Downloads
Patches
Plain Diff
copy skel files into user home
Former-commit-id:
c09b07f6
parent
4268beb4
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
roles/provision_homedir/templates/provision_homedir.py.j2
+36
-8
36 additions, 8 deletions
roles/provision_homedir/templates/provision_homedir.py.j2
with
36 additions
and
8 deletions
roles/provision_homedir/templates/provision_homedir.py.j2
+
36
−
8
View file @
4854dbad
...
@@ -3,6 +3,7 @@ import ldap
...
@@ -3,6 +3,7 @@ import ldap
import
traceback
import
traceback
import
os
import
os
import
stat
import
stat
import
shutil
class
ldapSearchConfig
:
class
ldapSearchConfig
:
def
__init__
(
self
):
def
__init__
(
self
):
...
@@ -18,8 +19,7 @@ class genericUser:
...
@@ -18,8 +19,7 @@ class genericUser:
self
.
dn
=
""
self
.
dn
=
""
self
.
cn
=
""
self
.
cn
=
""
self
.
entry
=
""
self
.
entry
=
""
self
.
uid
=
""
self
.
uid
=
""
def
get_users
(
server
):
def
get_users
(
server
):
# ldap.set_option(ldap.OPT_X_TLS_CACERTFILE,server.cacertfile)
# ldap.set_option(ldap.OPT_X_TLS_CACERTFILE,server.cacertfile)
...
@@ -42,7 +42,6 @@ def get_users(server):
...
@@ -42,7 +42,6 @@ def get_users(server):
allusers
[
dn
].
entry
=
attrs
allusers
[
dn
].
entry
=
attrs
return
allusers
return
allusers
def
mk_homedir
(
path
,
uidNumber
,
gidNumber
):
def
mk_homedir
(
path
,
uidNumber
,
gidNumber
):
try
:
try
:
statinfo
=
os
.
stat
(
path
)
statinfo
=
os
.
stat
(
path
)
...
@@ -56,6 +55,35 @@ def mk_homedir(path,uidNumber,gidNumber):
...
@@ -56,6 +55,35 @@ def mk_homedir(path,uidNumber,gidNumber):
else
:
else
:
raise
Exception
(
"
users homedirectory is not a directory %s
"
%
path
)
raise
Exception
(
"
users homedirectory is not a directory %s
"
%
path
)
# adapted from http://stackoverflow.com/questions/5994840/how-to-change-the-user-and-group-permissions-for-a-directory-by-name
def
recursive_chown
(
path
,
uidNumber
,
gidNumber
):
si
=
os
.
stat
(
path
)
# just a precaution before we recursively apply uid/gid to a path
if
si
.
st_uid
!=
uidNumber
or
si
.
st_gid
!=
gidNumber
:
raise
Exception
(
"
user home %s uid %d != %d, gid %d != %d mismatch
"
%
(
path
,
si
.
st_uid
,
uidNumber
,
si
.
st_gid
,
gidNumber
))
for
root
,
dirs
,
files
in
os
.
walk
(
path
):
for
momo
in
dirs
:
os
.
chown
(
os
.
path
.
join
(
root
,
momo
),
uidNumber
,
gidNumber
)
for
momo
in
files
:
os
.
chown
(
os
.
path
.
join
(
root
,
momo
),
uidNumber
,
gidNumber
)
def
mk_home_cp_skel
(
skelroot
,
path
,
uidNumber
,
gidNumber
):
if
skelroot
is
None
:
# assumes NO trailing / on the home path or dead meat
skelroot
=
path
.
rsplit
(
"
/
"
,
1
)[
0
]
# fix this later if your common/skel is located elsewhere
skelpath
=
os
.
path
.
join
(
skelroot
,
'
common
'
,
'
skel
'
)
if
os
.
path
.
isdir
(
skelpath
):
# copy the skel into the user $HOME
os
.
system
(
"
/bin/cp -r %s/* %s
"
%
(
skelpath
,
path
))
os
.
system
(
"
/bin/cp %s/\.* %s
"
%
(
skelpath
,
path
))
# ideally use this, but it assumes 'path' does not exist
# shutil.copytree(skelpath, path)
# chown to user ownership
recursive_chown
(
path
,
uidNumber
,
gidNumber
)
else
:
raise
Exception
(
"
skel path is missing %s
"
%
skelpath
)
s
=
ldapSearchConfig
()
s
=
ldapSearchConfig
()
s
.
ldapserver
=
"
{{ ldapURI }}
"
s
.
ldapserver
=
"
{{ ldapURI }}
"
s
.
binddn
=
"
{{ ldapBindDN }}
"
s
.
binddn
=
"
{{ ldapBindDN }}
"
...
@@ -65,15 +93,15 @@ s.searchFilter = "{{ search_filter }}"
...
@@ -65,15 +93,15 @@ s.searchFilter = "{{ search_filter }}"
homeDirEntry
=
"
{{ homeDirEntry }}
"
homeDirEntry
=
"
{{ homeDirEntry }}
"
mnthome
=
"
{{ mnthome }}
"
mnthome
=
"
{{ mnthome }}
"
users
=
get_users
(
s
)
users
=
get_users
(
s
)
for
user
in
users
:
for
user
in
users
:
try
:
try
:
if
mnthome
!=
""
:
if
mnthome
!=
""
:
path
=
mnthome
+
"
/
"
+
users
[
user
].
entry
[
homeDirEntry
][
0
].
rsplit
(
"
/
"
,
1
)[
1
]
path
=
mnthome
+
"
/
"
+
users
[
user
].
entry
[
homeDirEntry
][
0
].
rsplit
(
"
/
"
,
1
)[
1
]
else
:
else
:
path
=
users
[
user
].
entry
[
homeDirEntry
][
0
]
path
=
users
[
user
].
entry
[
homeDirEntry
][
0
]
mk_homedir
(
path
,
int
(
users
[
user
].
entry
[
'
uidNumber
'
][
0
]),
int
(
users
[
user
].
entry
[
'
gidNumber
'
][
0
]))
mk_homedir
(
path
,
int
(
users
[
user
].
entry
[
'
uidNumber
'
][
0
]),
int
(
users
[
user
].
entry
[
'
gidNumber
'
][
0
]))
cp_skel
(
None
,
path
,
int
(
users
[
user
].
entry
[
'
uidNumber
'
][
0
]),
int
(
users
[
user
].
entry
[
'
gidNumber
'
][
0
]))
except
:
except
:
print
traceback
.
format_exc
()
print
traceback
.
format_exc
()
pass
pass
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment