mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-07-12 13:35:47 +00:00
disallow to create tree in case of unsafe run
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user