Commit bbfd0568 authored by René Nussbaumer's avatar René Nussbaumer
Browse files

Modify ganeti-masterd to set permission and owner of masterd-socket


Signed-off-by: default avatarRené Nussbaumer <rn@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 8b72b05c
......@@ -29,10 +29,14 @@ inheritance from parent classes requires it.
# pylint: disable-msg=C0103
# C0103: Invalid name ganeti-masterd
import grp
import os
import pwd
import sys
import socket
import SocketServer
import time
import tempfile
import collections
import logging
......@@ -79,16 +83,23 @@ class MasterServer(daemon.AsyncStreamServer):
master socket.
"""
def __init__(self, mainloop, address, handler_class):
def __init__(self, mainloop, address, handler_class, uid, gid):
"""MasterServer constructor
@type mainloop: ganeti.daemon.Mainloop
@param mainloop: Mainloop used to poll for I/O events
@param address: the unix socket address to bind the MasterServer to
@param handler_class: handler class for the connections
@param uid: The uid of the owner of the socket
@param gid: The gid of the owner of the socket
"""
daemon.AsyncStreamServer.__init__(self, socket.AF_UNIX, address)
temp_name = tempfile.mktemp(dir=os.path.dirname(address))
daemon.AsyncStreamServer.__init__(self, socket.AF_UNIX, temp_name)
os.chmod(temp_name, 0770)
os.chown(temp_name, uid, gid)
os.rename(temp_name, address)
self.request_handler_class = handler_class
self.mainloop = mainloop
......@@ -473,6 +484,15 @@ def CheckMasterd(options, args):
ssconf.CheckMaster(options.debug)
try:
options.uid = pwd.getpwnam(constants.MASTERD_USER).pw_uid
options.gid = grp.getgrnam(constants.DAEMONS_GROUP).gr_gid
except KeyError:
print >> sys.stderr, ("User or group not existing on system: %s:%s" %
(constants.MASTERD_USER, constants.DAEMONS_GROUP))
sys.exit(constants.EXIT_FAILURE)
# If CheckMaster didn't fail we believe we are the master, but we have to
# confirm with the other nodes.
if options.no_voting:
......@@ -506,7 +526,8 @@ def ExecMasterd (options, args): # pylint: disable-msg=W0613
utils.RemoveFile(constants.MASTER_SOCKET)
mainloop = daemon.Mainloop()
master = MasterServer(mainloop, constants.MASTER_SOCKET, ClientRqHandler)
master = MasterServer(mainloop, constants.MASTER_SOCKET, ClientRqHandler,
options.uid, options.gid)
try:
rpc.Init()
try:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment