How to use selinux_enforcing method in autotest

Best Python code snippet using autotest_python

root-me.py

Source:root-me.py Github

copy

Full Screen

...82 osid = security_struct["osid"]83 sid = security_struct["sid"]84 write32(osid.address, 0x1) # SECINITSID_KERNEL = 1 = kernel85 write32(sid.address, 0x1) # SECINITSID_KERNEL = 1 = kernel86def disable_selinux_enforcing():87 """88 Disable selinux_enforcing globally89 """90 selinux_enforcing = gdb.parse_and_eval("selinux_enforcing")91 write32(selinux_enforcing.address, 0)92class TaskListFunc(gdb.Command):93 """List all task_struct"""94 def __init__(self):95 super(TaskListFunc, self).__init__("task-list", gdb.COMMAND_DATA)96 def invoke(self, arg, from_tty):97 task_list = task_lists()98 for task in task_list:99 gdb.write(100 "Task: {0} PID: {1} Command: {2}\n".format(101 task, task["pid"], task["comm"].string()102 )103 )104class TaskByPidFunc(gdb.Command):105 """List task_strcut by PID"""106 def __init__(self):107 super(TaskByPidFunc, self).__init__("task-by-pid", gdb.COMMAND_DATA)108 def invoke(self, arg, from_tty):109 argv = gdb.string_to_argv(arg)110 if not argv:111 raise gdb.GdbError("PID not provided")112 pid = int(argv[0])113 task = get_task_by_pid(pid)114 if task:115 gdb.write(116 "Task: {0} PID: {1} Command: {2}\n".format(117 task, task["pid"], task["comm"].string()118 )119 )120 else:121 raise gdb.GdbError("No task of PID: {0}".format(pid))122class RootByPidFunc(gdb.Command):123 """Give root privilege to given PID"""124 def __init__(self):125 super(RootByPidFunc, self).__init__("root-by-pid", gdb.COMMAND_DATA)126 def invoke(self, arg, from_tty):127 argv = gdb.string_to_argv(arg)128 if not argv:129 raise gdb.GdbError("PID not provided")130 pid = int(argv[0])131 task = get_task_by_pid(pid)132 if not task:133 raise gdb.GdbError("No task of PID: {0}".format(pid))134 gdb.write("[+] Rooting\n")135 gdb.write(" [*] PID: {0}\n".format(task["pid"]))136 gdb.write(" [*] Cmd: {0}\n".format(task["comm"].string()))137 gdb.write(" [*] Task: {0}\n".format(task))138 gdb.write("[+] Patching cred\n")139 gdb.write(" [*] Cred: {0}\n".format(task["cred"]))140 root_me(task)141 gdb.write("[+] Patching selinux_enforcing\n")142 gdb.write(143 " [*] selinux_enforcing: {0}\n".format(144 gdb.parse_and_eval("selinux_enforcing").address145 )146 )147 disable_selinux_enforcing()148 # gdb.write("[+] Patching selinux task context\n")149 # set_selinux_task_context(task)150 gdb.write("[*] Rooting complete\n")151# register the commands152TaskListFunc()153TaskByPidFunc()...

Full Screen

Full Screen

ipa-vagrant-ci-runner

Source:ipa-vagrant-ci-runner Github

copy

Full Screen

1#!/usr/bin/python32# Author: Martin Basti3# See LICENSE file for license4import argparse5import logging6import sys7import traceback8from ipavagrant.config import IPAVagrantConfig9from ipavagrant.ipaci import IPACIRunner10from ipavagrant import constants11def main():12 parser = argparse.ArgumentParser(description="")13 parser.add_argument("test_name", type=str,14 help="Name of CI test(s) to be executed",15 nargs='*')16 parser.add_argument("--init", action="store_true", default=False,17 dest="initialize",18 help="Initialize IPA CI runner in current directory")19 test_config = parser.add_argument_group("Test configuration options")20 test_config.add_argument(21 '--add-package',22 dest="packages",23 action="append",24 help="Allows to specify packages that will be installed from "25 "repository",26 default=[],27 metavar="NAME")28 test_config.add_argument(29 '--add-copr', dest="copr_repos", action="append",30 help="Allows to specify copr repositories that will be enabled",31 default=[], metavar="NAME")32 test_config.add_argument(33 '--memory-controller', dest="memory_controller",34 help="Allows to specify memory for controller [MB]",35 metavar="MBytes", default=None)36 test_config.add_argument(37 '--memory-server', dest="memory_server",38 help="Allows to specify memory for server [MB]",39 metavar="MBytes", default=None)40 test_config.add_argument(41 '--memory-client', dest="memory_client",42 help="Allows to specify memory for client [MB]",43 metavar="MBytes", default=None)44 # selinux45 test_config.add_argument(46 '--selinux-enforce', dest="selinux_enforcing",47 action='store_true',48 help="Set SELinux to enforce mode")49 test_config.add_argument(50 '--no-selinux-enforce', dest="selinux_enforcing",51 action='store_false',52 help="Set SELinux to permissive mode")53 test_config.set_defaults(selinux_enforcing=None)54 test_config.add_argument(55 '--box', dest="box", default=None,56 help="Set box that will be used")57 test_config.add_argument(58 '--domain', dest="domain", type=str,59 default=None, help="Domain for provisioned VM")60 file_config = parser.add_argument_group("Configuration file options")61 file_config.add_argument(62 '--config-file', dest="config_file", default=None,63 help="Path to configuration file (default: %s)" %64 constants.DEFAULT_CONFIG_FILENAME)65 file_config.add_argument(66 "--config-topo-file", dest="config_topo_file",67 default=None,68 help="Path for configuration file contains tests and topologies "69 "configuration. (default: {})".format(70 constants.DEFAULT_TOPO_CONFIG_FILENAME))71 file_config.add_argument(72 '--export-topo-config',73 dest="export_topo_config",74 default=False,75 action="store_true",76 help="export current configuration to config file (destination: "77 "--config-topo-file)")78 file_config.add_argument(79 '--list-tests', dest="list_tests", default=False,80 action="store_true", help="list available/configured tests")81 parser.add_argument("--debug", action="store_true", default=False,82 dest="debug",83 help="Enables DEBUG level logging")84 parser.add_argument("--dry-run", action="store_true", default=False,85 dest="dry_run",86 help="Do not execute any vagrant command, just "87 "create vagrant files (for testing)")88 args = parser.parse_args()89 if args.debug:90 logging.basicConfig(level=logging.DEBUG)91 else:92 logging.basicConfig(level=logging.INFO)93 config = IPAVagrantConfig(94 filename=args.config_file,95 # options96 domain=args.domain,97 memory_controller=args.memory_controller,98 memory_server=args.memory_server,99 memory_client=args.memory_client,100 selinux_enforcing=args.selinux_enforcing,101 box=args.box,102 packages=args.packages,103 copr_repos=args.copr_repos104 )105 runner = IPACIRunner(106 args.test_name,107 config_topo_file=args.config_topo_file,108 config=config,109 dry_run=args.dry_run110 )111 if args.initialize:112 if runner.is_initialized():113 raise RuntimeError("Already initialized")114 else:115 runner.initialize()116 print("Initialization done", file=sys.stderr)117 sys.exit(0)118 if args.export_topo_config:119 where = runner.topo_config.export_config()120 print("Configuration saved to", where, file=sys.stderr)121 return122 if args.list_tests:123 print("\n".join(sorted(runner.topo_config.tests.keys())))124 return125 if not runner.is_initialized():126 raise RuntimeError("IPA CI runner must be initialized first in "127 "current directory. Please use option '--init'")128 if not args.test_name:129 RuntimeError("No tests have been specified")130 runner.run()131if __name__ == "__main__":132 try:133 main()134 except RuntimeError as e:135 logging.debug(traceback.format_exc())136 print(e, file=sys.stderr)...

Full Screen

Full Screen

ipa-vagrant-ci-topology-create

Source:ipa-vagrant-ci-topology-create Github

copy

Full Screen

1#!/usr/bin/python32# Author: Martin Basti3# See LICENSE file for license4import argparse5import os6import sys7import logging8import traceback9from ipavagrant import constants10from ipavagrant.config import IPAVagrantConfig11from ipavagrant.ipaci import IPACITopology12def main():13 parser = argparse.ArgumentParser(description="")14 parser.add_argument("topology_name", type=str,15 help="Name for topology (directory with this name "16 "will be created)",17 nargs="?")18 parser.add_argument("--replicas", dest="replicas", type=int, default=0,19 metavar="INT",20 help="Number of IPA replicas to be prepared "21 "(default: 0)")22 parser.add_argument('--clients', dest="clients", type=int, default=0,23 metavar="INT",24 help="Number of IPA clients to be prepared "25 "(default: 0)")26 test_config = parser.add_argument_group("Test configuration options")27 test_config.add_argument(28 '--add-package', dest="packages", action="append",29 help="Allows to specify packages that will be installed from "30 "repository",31 default=[], metavar="NAME")32 test_config.add_argument(33 '--add-copr', dest="copr_repos", action="append",34 help="Allows to specify copr repositories that will be enabled",35 default=[], metavar="NAME")36 test_config.add_argument(37 '--memory-controller', dest="memory_controller",38 help="Allows to specify memory for controller [MB]",39 metavar="MBytes", default=None)40 test_config.add_argument(41 '--memory-server', dest="memory_server",42 help="Allows to specify memory for server [MB]",43 metavar="MBytes", default=None)44 test_config.add_argument(45 '--memory-client', dest="memory_client",46 help="Allows to specify memory for client [MB]",47 metavar="MBytes", default=None)48 # selinux49 test_config.add_argument(50 '--selinux-enforce', dest="selinux_enforcing",51 action='store_true',52 help="Set SELinux to enforce mode")53 test_config.add_argument(54 '--no-selinux-enforce', dest="selinux_enforcing",55 action='store_false',56 help="Set SELinux to permissive mode")57 test_config.set_defaults(selinux_enforcing=None)58 test_config.add_argument(59 '--box', dest="box", default=None,60 help="Set box that will be used")61 test_config.add_argument(62 '--domain', dest="domain", type=str,63 default=None, help="Domain for provisioned VM")64 file_config = parser.add_argument_group("Configuration file options")65 file_config.add_argument(66 '--config-file', dest="config_file", default=None,67 help="Path to configuration file (default: %s)" %68 constants.DEFAULT_CONFIG_FILENAME)69 file_config.add_argument(70 '--export-config', dest="export_config", default=False,71 action="store_true", help="export current configuration to config "72 "file (destination: --config-file)")73 file_config.add_argument(74 '--show-config', dest="show_config", default=False,75 action="store_true", help="show current configuration")76 parser.add_argument("--debug", action="store_true", default=False,77 dest='debug',78 help="Enables DEBUG level logging")79 args = parser.parse_args()80 if args.debug:81 logging.basicConfig(level=logging.DEBUG)82 else:83 logging.basicConfig(level=logging.INFO)84 if not args.topology_name:85 if args.show_config or args.export_config:86 topology_path = "_unused_"87 else:88 raise RuntimeError("Topology name is required")89 else:90 topology_path = os.path.abspath(args.topology_name)91 config = IPAVagrantConfig(92 filename=args.config_file,93 # options94 domain=args.domain,95 memory_controller=args.memory_controller,96 memory_server=args.memory_server,97 memory_client=args.memory_client,98 selinux_enforcing=args.selinux_enforcing,99 box=args.box,100 packages=args.packages,101 copr_repos=args.copr_repos102 )103 ci_topo = IPACITopology(104 topology_path,105 config=config,106 replicas=args.replicas,107 clients=args.clients,108 )109 if args.show_config:110 print("Current configuration:")111 keys = sorted(ci_topo.config.config.keys())112 for key in keys:113 print(" %s: %r" % (key, ci_topo.config.config[key]))114 print("Path to used config file: ", ci_topo.config.get_filename())115 if not args.export_config:116 return117 if args.export_config:118 where = ci_topo.config.export_config()119 print("Configuration saved to %s" % where, file=sys.stderr)120 return121 ci_topo.create()122if __name__ == '__main__':123 try:124 main()125 except RuntimeError as e:126 logging.debug(traceback.format_exc())127 print(e, file=sys.stderr)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful