예제 #1
0
def validate():
    """
    Should be run after logging is enabled.

    """
    logger.debug("Running script with argv: " + str(sys.argv))
    logger.debug("Parsed options: " + str(options))
    logger.debug("Unparsed args: " + str(args))
    
    if args:
        logger.fatal("Unrecognized command line arguments: " + string.join(args))

    if options.non_root_user:
        try:
            utils.get_user_idinfo(options.non_root_user)
        except KeyError:
            logger.fatal("User '%s' doesn't exist" % options.non_root_user)

    if options.non_root_user and not utils.is_root():
        logger.fatal("[-u | --non-root-user] flags are invalid when current user is not root")

    if options.break_at_failure:
        options.debug = True

    if options.filter_tests:
        options.filter_tests = re.compile(options.filter_tests)
    
    logger.debug("Preprocessed options: " + str(options))
예제 #2
0
def perform_checks():
    # TODO(javierhonduco): We can do more checks
    # - kernel version
    # - libbcc version
    # - sample bpf programs to probe for features
    if not is_root():
        print("You need root to use rbperf, sorry!")
        sys.exit(1)
예제 #3
0
파일: test_dcgmi.py 프로젝트: omertuc/DCGM
def test_dcgmi_config(handle, gpuIds):
    """
    Test DCGMI config
    """
    assert len(gpuIds) > 0, "Failed to get devices from the node"

    dcgmHandle = pydcgm.DcgmHandle(handle=handle)
    dcgmSystem = dcgmHandle.GetSystem()
    # Getting GPU power limits
    for gpuId in gpuIds:
        gpuAttrib = dcgmSystem.discovery.GetGpuAttributes(gpuId)
        dft_pwr = str(gpuAttrib.powerLimits.defaultPowerLimit)
        max_pwr = str(gpuAttrib.powerLimits.maxPowerLimit)

    groupId = str(_create_dcgmi_group())

    ## keep args in this order. Changing it may break the test
    validArgsTestList = [
        ["group", "-g", groupId, "-a",
         str(gpuIds[0])],  # add gpu to group
        ["config", "--get", "-g", groupId],  # get default group configuration
        [
            "config", "--get", "-g", "0"
        ],  # get default group configuration by ID. This will work as long as group IDs start at 0
        ["config", "-g", groupId, "--set", "-P",
         dft_pwr],  # set default power limit
        ["config", "-g", groupId, "--set", "-P",
         max_pwr],  # set max power limit
        ["config", "--get", "-g", groupId,
         "--verbose"],  # get verbose default group configuration
        ["config", "--enforce", "-g",
         groupId],  # enforce default group configuration
        ["config", "--enforce", "-g",
         "0"]  # enforce group configuration on default group by ID
    ]

    # Setting the compute mode is only supported when MIG mode is not enabled.
    if not test_utils.is_mig_mode_enabled():
        # set group configuration on default group by ID
        validArgsTestList.append(["config", "--set", "-c", "0", "-g", "0"])

    #Config management only works when the host engine is running as root
    if utils.is_root():
        _test_valid_args(validArgsTestList)
    else:
        _test_invalid_args(validArgsTestList)

    ## keep args in this order. Changing it may break the test
    _test_invalid_args([
        ["config", "--get", "-g",
         "9999"],  # Can't get config of group that doesn't exist
        ["config", "--get", "-g", "9999",
         "--verbose"],  # Can't get config of group that doesn't exist
        ["config", "--set", ""],  # Can't set group configuration to nothing
        ["config", "--set", "-c", "5"],  # Can't set an invalid compute mode
        ["config", "--enforce", "-g",
         "9999"]  # Can't enforce a configuration of group that doesn't exist
    ])
예제 #4
0
def must_be_sudo() -> None:
    """
    checks if the user is root and if not it prints an warning message

    :return: None

    :since: 0.1.0
    """
    from colorama import Fore
    if atils.is_root() is False:
        print(Fore.RED + "to execute the command, aion must be run as sudo" +
              Fore.RESET)
        exit(-1)
예제 #5
0
#!/usr/bin/python3

# 17g service
import os
import sys
import config
from utils import err, is_root, run
if not is_root():
    print("You must be root!")
    exit(1)

# Check live mode and single run
if config.get("boot", "normal") != "live":
    exit(0)
if os.path.exists("/run/17g") or "--force" in sys.argv:
    exit(0)
else:
    os.mkdir("/run/17g")

# Write live-installer into /etc/xprofile file
if config.get("welcome_screen", True):
    if os.path.exists("/etc/xprofile"):
        xprofile = open("/etc/xprofile", "a")
    else:
        xprofile = open("/etc/xprofile", "w")
    xprofile.write("live-installer --welcome")
    xprofile.close()

# live functions
# Ignore this function with debian (debian uses live-config package)
if config.get("enable_live",
예제 #6
0
def mount(source, destination, fstype, flags=0, data=''):
    assert utils.is_root()
    return libc.mount(source, destination, fstype, flags, data)
예제 #7
0
파일: main.py 프로젝트: 0x07cc/ips-cc
# Parameters
queue_number = 33
log_file  = "logfile.log"
pcap_file = "dropped_packets.pcap"
# List of banned Regular Expressions and strings
regex_list = ['CC{\w+}', 'CCRU{\w+}', 'doveva annà così fratellì', 'https://www.youtube.com/watch?v=dQw4w9WgXcQ']
service_type = 'Netcat'  # Name of the service
# Parameter that controls the packet dropping policy:
# 0: only drop the packet;
# 1: drop the packet and send a RST packet to kill the connection;
# 2: drop the packet and send a ACK packet to continue the connection.
dropping_policy = 1

# Checking root privileges
if not utils.is_root():
    print("You need root privileges to run this application!")
    exit(-1)

# Checking debug flag status (-d or --debug)
debug = utils.is_debug()

# Indispensable objects instantiation
log = mylog.Log(log_file)
shield = my_analysis.Shield(regex_list, service_type, log)
handling = packet_handling.PacketHandling(log, shield, debug, dropping_policy)

# Optional objects instantiation: comment them to disable
statistics = stats.Stats(log, handling)
pcap_exporter = pcap.PCAP(log, handling, pcap_file)
예제 #8
0
import user, sys, getopt, utils, os, crypt
from getpass import getpass

utils.is_root()


argv = sys.argv[1:]
opts, argument = getopt.getopt(argv, ":c:d:g:G:k:p:s:h:u:" )

username = str(argument[0])
gid =  default_gid = user.group
gid_flag = False
shell = default_shell = user.shell
home = default_home = user.home + '/' + username
skel = default_skel = user.skel
uid = default_uid = user.group
uid_flag = False
gen_pass = True
password = '******'
hashed_pass = user.password
comment = username

for opt, arg in opts:
    if  opt in ['-c']:
        comment = arg
    elif  opt in ['-d']:
        home = arg
    elif  opt in ['-g']:
        try:
            gid = utils.grep(user.group_file, arg)[0][1]
            gid_flag = True
예제 #9
0
from utils import cat, cut, grep, gen_groups, is_root
from time import time

is_root()

group_file = gen_groups(cat('/etc/group'))
shadow_file = cat('/etc/shadow')
passwd_file = gen_groups(cat('/etc/passwd'))

all_users = []
all_uids = []
all_groups = []
all_gids = []

for user in passwd_file:
    all_users.append(user[0])
    all_uids.append(int(user[1]))

for group in group_file:
    all_groups.append(group[0])
    all_gids.append(int(group[1]))

defaults = cat('defaults')
home = cut(grep(defaults, 'HOME'))
shell = cut(grep(defaults, 'SHELL'))
group = cut(grep(defaults, 'GROUP'))
skel = cut(grep(defaults, 'SKEL'))
del (defaults)

login_defs = cat('login.defs')
pass_max_days = cut(grep(login_defs, 'PASS_MAX_DAYS'))