prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  SELinux issue when service is restarted
  This issue was initially reported at
  https://bugzilla.redhat.com/show_bug.cgi?id=1754430
  
  There is a SELinux denial when the cobblerd service is restarted because of the permissions of the web.ss and others webui_sessions files.
  
  I'm not sure to understand if this is 3.0.x only or also only exists in 2.8.x, but for me there is a need to understand why cobblerd (uid root) tries to read theses files...
  Of course it can probably be fixed by using 640 perm on theses files. (to be tested) but it just workaround the problem.
  
  </issue>
  <code>
  [start of cobbler/cobblerd.py]
  1 """
  2 Cobbler daemon for logging remote syslog traffic during automatic installation
  3 
  4 Copyright 2007-2009, Red Hat, Inc and Others
  5 Michael DeHaan <michael.dehaan AT gmail>
  6 
  7 This program is free software; you can redistribute it and/or modify
  8 it under the terms of the GNU General Public License as published by
  9 the Free Software Foundation; either version 2 of the License, or
  10 (at your option) any later version.
  11 
  12 This program is distributed in the hope that it will be useful,
  13 but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15 GNU General Public License for more details.
  16 
  17 You should have received a copy of the GNU General Public License
  18 along with this program; if not, write to the Free Software
  19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  20 02110-1301  USA
  21 """
  22 
  23 import binascii
  24 import os
  25 import pwd
  26 import time
  27 
  28 from cobbler import remote
  29 from cobbler import utils
  30 from cobbler.api import CobblerAPI
  31 
  32 
  33 def core(cobbler_api: CobblerAPI):
  34     """
  35     Starts Cobbler.
  36 
  37     :param cobbler_api: The cobbler_api instance which is used for this method.
  38     """
  39     settings = cobbler_api.settings()
  40     xmlrpc_port = settings.xmlrpc_port
  41 
  42     regen_ss_file()
  43     do_xmlrpc_rw(cobbler_api, settings, xmlrpc_port)
  44 
  45 
  46 def regen_ss_file():
  47     """
  48     This is only used for Kerberos auth at the moment. It identifies XMLRPC requests from Apache that have already been
  49     cleared by Kerberos.
  50     """
  51     ssfile = "/var/lib/cobbler/web.ss"
  52     with open("/dev/urandom", 'rb') as fd:
  53         data = fd.read(512)
  54 
  55     with open(ssfile, 'wb', 0o660) as fd:
  56         fd.write(binascii.hexlify(data))
  57 
  58     http_user = "apache"
  59     family = utils.get_family()
  60     if family == "debian":
  61         http_user = "www-data"
  62     elif family == "suse":
  63         http_user = "wwwrun"
  64     os.lchown("/var/lib/cobbler/web.ss", pwd.getpwnam(http_user)[2], -1)
  65 
  66 
  67 def do_xmlrpc_rw(cobbler_api: CobblerAPI, settings, port):
  68     """
  69     This trys to bring up the Cobbler xmlrpc_api and restart it if it fails.
  70 
  71     :param cobbler_api: The cobbler_api instance which is used for this method.
  72     :param settings: The Cobbler settings instance which is used for this method.
  73     :param port: The port where the xmlrpc api should run on.
  74     """
  75     xinterface = remote.ProxiedXMLRPCInterface(cobbler_api, remote.CobblerXMLRPCInterface)
  76     server = remote.CobblerXMLRPCServer(('127.0.0.1', port))
  77     server.logRequests = 0      # don't print stuff
  78     xinterface.logger.debug("XMLRPC running on %s" % port)
  79     server.register_instance(xinterface)
  80 
  81     while True:
  82         try:
  83             print("SERVING!")
  84             server.serve_forever()
  85         except IOError:
  86             # interrupted? try to serve again
  87             time.sleep(0.5)
  88 
  89 
  90 if __name__ == "__main__":
  91     core(CobblerAPI())
  92
  [end of cobbler/cobblerd.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/cobbler/cobblerd.py b/cobbler/cobblerd.py
  --- a/cobbler/cobblerd.py
  +++ b/cobbler/cobblerd.py
  @@ -52,7 +52,7 @@
       with open("/dev/urandom", 'rb') as fd:
           data = fd.read(512)
   
  -    with open(ssfile, 'wb', 0o660) as fd:
  +    with open(ssfile, 'wb', 0o640) as fd:
           fd.write(binascii.hexlify(data))
   
       http_user = "apache"
  @@ -61,7 +61,7 @@
           http_user = "www-data"
       elif family == "suse":
           http_user = "wwwrun"
  -    os.lchown("/var/lib/cobbler/web.ss", pwd.getpwnam(http_user)[2], -1)
  +    os.lchown(ssfile, 0, pwd.getpwnam(http_user)[3])
   
   
   def do_xmlrpc_rw(cobbler_api: CobblerAPI, settings, port):
  
verification_info: {"golden_diff": "diff --git a/cobbler/cobblerd.py b/cobbler/cobblerd.py\n--- a/cobbler/cobblerd.py\n+++ b/cobbler/cobblerd.py\n@@ -52,7 +52,7 @@\n     with open(\"/dev/urandom\", 'rb') as fd:\n         data = fd.read(512)\n \n-    with open(ssfile, 'wb', 0o660) as fd:\n+    with open(ssfile, 'wb', 0o640) as fd:\n         fd.write(binascii.hexlify(data))\n \n     http_user = \"apache\"\n@@ -61,7 +61,7 @@\n         http_user = \"www-data\"\n     elif family == \"suse\":\n         http_user = \"wwwrun\"\n-    os.lchown(\"/var/lib/cobbler/web.ss\", pwd.getpwnam(http_user)[2], -1)\n+    os.lchown(ssfile, 0, pwd.getpwnam(http_user)[3])\n \n \n def do_xmlrpc_rw(cobbler_api: CobblerAPI, settings, port):\n", "issue": "SELinux issue when service is restarted\nThis issue was initially reported at\r\nhttps://bugzilla.redhat.com/show_bug.cgi?id=1754430\r\n\r\nThere is a SELinux denial when the cobblerd service is restarted because of the permissions of the web.ss and others webui_sessions files.\r\n\r\nI'm not sure to understand if this is 3.0.x only or also only exists in 2.8.x, but for me there is a need to understand why cobblerd (uid root) tries to read theses files...\r\nOf course it can probably be fixed by using 640 perm on theses files. (to be tested) but it just workaround the problem.\n", "before_files": [{"content": "\"\"\"\nCobbler daemon for logging remote syslog traffic during automatic installation\n\nCopyright 2007-2009, Red Hat, Inc and Others\nMichael DeHaan <michael.dehaan AT gmail>\n\nThis program is free software; you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation; either version 2 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program; if not, write to the Free Software\nFoundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA\n02110-1301  USA\n\"\"\"\n\nimport binascii\nimport os\nimport pwd\nimport time\n\nfrom cobbler import remote\nfrom cobbler import utils\nfrom cobbler.api import CobblerAPI\n\n\ndef core(cobbler_api: CobblerAPI):\n    \"\"\"\n    Starts Cobbler.\n\n    :param cobbler_api: The cobbler_api instance which is used for this method.\n    \"\"\"\n    settings = cobbler_api.settings()\n    xmlrpc_port = settings.xmlrpc_port\n\n    regen_ss_file()\n    do_xmlrpc_rw(cobbler_api, settings, xmlrpc_port)\n\n\ndef regen_ss_file():\n    \"\"\"\n    This is only used for Kerberos auth at the moment. It identifies XMLRPC requests from Apache that have already been\n    cleared by Kerberos.\n    \"\"\"\n    ssfile = \"/var/lib/cobbler/web.ss\"\n    with open(\"/dev/urandom\", 'rb') as fd:\n        data = fd.read(512)\n\n    with open(ssfile, 'wb', 0o660) as fd:\n        fd.write(binascii.hexlify(data))\n\n    http_user = \"apache\"\n    family = utils.get_family()\n    if family == \"debian\":\n        http_user = \"www-data\"\n    elif family == \"suse\":\n        http_user = \"wwwrun\"\n    os.lchown(\"/var/lib/cobbler/web.ss\", pwd.getpwnam(http_user)[2], -1)\n\n\ndef do_xmlrpc_rw(cobbler_api: CobblerAPI, settings, port):\n    \"\"\"\n    This trys to bring up the Cobbler xmlrpc_api and restart it if it fails.\n\n    :param cobbler_api: The cobbler_api instance which is used for this method.\n    :param settings: The Cobbler settings instance which is used for this method.\n    :param port: The port where the xmlrpc api should run on.\n    \"\"\"\n    xinterface = remote.ProxiedXMLRPCInterface(cobbler_api, remote.CobblerXMLRPCInterface)\n    server = remote.CobblerXMLRPCServer(('127.0.0.1', port))\n    server.logRequests = 0      # don't print stuff\n    xinterface.logger.debug(\"XMLRPC running on %s\" % port)\n    server.register_instance(xinterface)\n\n    while True:\n        try:\n            print(\"SERVING!\")\n            server.serve_forever()\n        except IOError:\n            # interrupted? try to serve again\n            time.sleep(0.5)\n\n\nif __name__ == \"__main__\":\n    core(CobblerAPI())\n", "path": "cobbler/cobblerd.py"}]}