Exemplo n.º 1
0
 def __init__(self, middleware):
     self.logger = Logger(type(self).__name__).getLogger()
     self.middleware = middleware
Exemplo n.º 2
0
import os
import errno
import pwd
import tempfile
import subprocess
import threading
import shutil
from collections import defaultdict
from middlewared.schema import accepts, Bool, Dict, Str, Int, Ref, List
from middlewared.validators import Range, Match
from middlewared.service import (Service, job, CallError, CRUDService,
                                 SystemServiceService)
from middlewared.logger import Logger

logger = Logger('rsync').getLogger()
RSYNC_PATH = '/usr/local/bin/rsync'


def demote(user):
    """
    Helper function to call the subprocess as the specific user.
    Taken from: https://gist.github.com/sweenzor/1685717
    Pass the function 'set_ids' to preexec_fn, rather than just calling
    setuid and setgid. This will change the ids for that subprocess only"""
    def set_ids():
        if user:
            user_info = pwd.getpwnam(user)
            os.setgid(user_info.pw_gid)
            os.setuid(user_info.pw_uid)