mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
[enh] Catch unknown uid/gid in utils.filesystem.chown
This commit is contained in:
parent
79e46a5160
commit
a092370710
2 changed files with 16 additions and 3 deletions
|
@ -38,5 +38,8 @@
|
|||
"logged_out" : "Logged out",
|
||||
"not_logged_in" : "You are not logged in",
|
||||
"server_already_running" : "A server is already running on that port",
|
||||
"websocket_request_expected" : "Expected a WebSocket request"
|
||||
"websocket_request_expected" : "Expected a WebSocket request",
|
||||
|
||||
"unknown_user" : "Unknown '{user}' user",
|
||||
"unknown_group" : "Unknown '{group}' group"
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@ import shutil
|
|||
from pwd import getpwnam
|
||||
from grp import getgrnam
|
||||
|
||||
from moulinette.core import MoulinetteError
|
||||
|
||||
|
||||
# Files & directories --------------------------------------------------
|
||||
|
||||
|
@ -60,11 +62,19 @@ def chown(path, uid=None, gid=None, recursive=False):
|
|||
|
||||
# Retrieve uid/gid
|
||||
if isinstance(uid, basestring):
|
||||
uid = getpwnam(uid).pw_uid
|
||||
try:
|
||||
uid = getpwnam(uid).pw_uid
|
||||
except KeyError:
|
||||
raise MoulinetteError(errno.EINVAL,
|
||||
m18n.g('unknown_user', user=uid))
|
||||
elif uid is None:
|
||||
uid = -1
|
||||
if isinstance(gid, basestring):
|
||||
gid = getpwnam(gid).gr_gid
|
||||
try:
|
||||
gid = getpwnam(gid).gr_gid
|
||||
except KeyError:
|
||||
raise MoulinetteError(errno.EINVAL,
|
||||
m18n.g('unknown_group', group=gid))
|
||||
elif gid is None:
|
||||
gid = -1
|
||||
|
||||
|
|
Loading…
Reference in a new issue