disallow to create tree in case of unsafe run

This commit is contained in:
2021-10-14 04:44:36 +03:00
parent a83f1d5aa5
commit 233b1f7f39
29 changed files with 114 additions and 59 deletions

View File

@ -18,6 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import datetime
import os
import subprocess
import requests
@ -25,7 +26,7 @@ from logging import Logger
from pathlib import Path
from typing import Generator, Optional, Union
from ahriman.core.exceptions import InvalidOption
from ahriman.core.exceptions import InvalidOption, UnsafeRun
def check_output(*args: str, exception: Optional[Exception], cwd: Optional[Path] = None,
@ -54,6 +55,19 @@ def check_output(*args: str, exception: Optional[Exception], cwd: Optional[Path]
raise exception or e
def check_user(root: Path) -> None:
"""
check if current user is the owner of the root
:param root: root directory (i.e. ahriman home)
"""
if not root.exists():
return # no directory found, skip check
current_uid = os.getuid()
root_uid = root.stat().st_uid
if current_uid != root_uid:
raise UnsafeRun(current_uid, root_uid)
def exception_response_text(exception: requests.exceptions.HTTPError) -> str:
"""
safe response exception text generation