Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F56615394
ext_epfl_roaming.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Mar 29, 12:10
Size
1 KB
Mime Type
text/x-python
Expires
Sun, Mar 31, 13:10 (2 d)
Engine
blob
Format
Raw Data
Handle
16741874
Attached To
R8811 EPFL Roaming
ext_epfl_roaming.py
View Options
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
epfl_roaming extension for manage_cred
It has to implement :
+ FLAG_FILE : the file that flags it's epfl_roaming that sent USR2 signal to manage_cred
+ run(username, password) method that does the job
"""
import
os
import
sys
import
pwd
import
subprocess
FLAG_FILE
=
"/var/run/epfl_roaming/manage_cred.flag"
EPFL_ROAMING_FOLDER
=
"/usr/local/bin"
sys
.
path
.
append
(
EPFL_ROAMING_FOLDER
)
from
epfl_roaming
import
IO
,
LOG_PAM
,
read_user
,
read_config
,
run_cmd
,
NameSpace
,
UserIdentity
def
run
(
username
,
password
):
"""
Performs all mount for epfl_roaming
"""
with
IO
(
LOG_PAM
):
IO
.
write
(
"Running epfl_roaming extension from manage_cred for user
%s
."
%
username
)
options
=
NameSpace
()
options
.
context
=
"pam"
user
=
read_user
(
options
,
username
)
config
=
read_config
(
options
,
user
)
for
mount_point
,
mount_instruction
in
config
[
"mounts"
]
.
items
():
if
not
os
.
path
.
exists
(
mount_point
):
user
=
NameSpace
()
user
.
username
=
username
pw
=
pwd
.
getpwnam
(
user
.
username
)
user
.
uid
=
str
(
pw
.
pw_uid
)
user
.
gid
=
str
(
pw
.
pw_gid
)
with
UserIdentity
(
user
):
run_cmd
(
cmd
=
[
"mkdir"
,
"-p"
,
mount_point
]
)
# Mount
os
.
environ
[
'PASSWD'
]
=
password
run_cmd
(
cmd
=
mount_instruction
,
shell
=
True
,
)
del
os
.
environ
[
'PASSWD'
]
IO
.
write
(
"Done running epfl_roaming extension from manage_cred for user
%s
."
%
username
)
if
__name__
==
"__main__"
:
print
>>
sys
.
stderr
,
"This is not to be run this way!"
sys
.
exit
(
1
)
Event Timeline
Log In to Comment