Blame tests/51-live-user_notification.py

Packit Service 10c312
#!/usr/bin/env python
Packit Service 10c312
Packit Service 10c312
#
Packit Service 10c312
# Seccomp Library test program
Packit Service 10c312
#
Packit Service 10c312
# Copyright (c) 2019 Cisco Systems, Inc. <pmoore2@cisco.com>
Packit Service 10c312
# Author: Paul Moore <paul@paul-moore.com>
Packit Service 10c312
#
Packit Service 10c312
Packit Service 10c312
#
Packit Service 10c312
# This library is free software; you can redistribute it and/or modify it
Packit Service 10c312
# under the terms of version 2.1 of the GNU Lesser General Public License as
Packit Service 10c312
# published by the Free Software Foundation.
Packit Service 10c312
#
Packit Service 10c312
# This library is distributed in the hope that it will be useful, but WITHOUT
Packit Service 10c312
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
Packit Service 10c312
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
Packit Service 10c312
# for more details.
Packit Service 10c312
#
Packit Service 10c312
# You should have received a copy of the GNU Lesser General Public License
Packit Service 10c312
# along with this library; if not, see <http://www.gnu.org/licenses>.
Packit Service 10c312
#
Packit Service 10c312
Packit Service 10c312
import argparse
Packit Service 10c312
import os
Packit Service 10c312
import signal
Packit Service 10c312
import sys
Packit Service 10c312
Packit Service 10c312
import util
Packit Service 10c312
Packit Service 10c312
from seccomp import *
Packit Service 10c312
Packit Service 10c312
def test():
Packit Service 10c312
    magic = os.getuid() + 1
Packit Service 10c312
    f = SyscallFilter(ALLOW)
Packit Service 10c312
    f.add_rule(NOTIFY, "getuid")
Packit Service 10c312
    f.load()
Packit Service 10c312
    pid = os.fork()
Packit Service 10c312
    if pid == 0:
Packit Service 10c312
        val = os.getuid()
Packit Service 10c312
        if val != magic:
Packit Service 10c312
            raise RuntimeError("Response return value failed")
Packit Service 10c312
            quit(1)
Packit Service 10c312
        quit(0)
Packit Service 10c312
    else:
Packit Service 10c312
        notify = f.receive_notify()
Packit Service 10c312
        if notify.syscall != resolve_syscall(Arch(), "getuid"):
Packit Service 10c312
            raise RuntimeError("Notification failed")
Packit Service 10c312
        f.respond_notify(NotificationResponse(notify, magic, 0, 0))
Packit Service 10c312
        wpid, rc = os.waitpid(pid, 0)
Packit Service 10c312
        if os.WIFEXITED(rc) == 0:
Packit Service 10c312
            raise RuntimeError("Child process error")
Packit Service 10c312
        if os.WEXITSTATUS(rc) != 0:
Packit Service 10c312
            raise RuntimeError("Child process error")
Packit Service 10c312
        f.reset(ALLOW)
Packit Service 10c312
        f.add_rule(NOTIFY, "getppid")
Packit Service 10c312
        f.load()
Packit Service 10c312
        # no easy way to check the notification fd here
Packit Service 10c312
        quit(160)
Packit Service 10c312
Packit Service 10c312
test()
Packit Service 10c312
Packit Service 10c312
# kate: syntax python;
Packit Service 10c312
# kate: indent-mode python; space-indent on; indent-width 4; mixedindent off;