diff --git a/locales/en.json b/locales/en.json index 51efcd82..f18aaebe 100644 --- a/locales/en.json +++ b/locales/en.json @@ -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" } diff --git a/moulinette/utils/filesystem.py b/moulinette/utils/filesystem.py index 5ee4c7d2..6d48c30c 100644 --- a/moulinette/utils/filesystem.py +++ b/moulinette/utils/filesystem.py @@ -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