Revision bbfd0568 daemons/ganeti-masterd

b/daemons/ganeti-masterd
29 29
# pylint: disable-msg=C0103
30 30
# C0103: Invalid name ganeti-masterd
31 31

  
32
import grp
33
import os
34
import pwd
32 35
import sys
33 36
import socket
34 37
import SocketServer
35 38
import time
39
import tempfile
36 40
import collections
37 41
import logging
38 42

  
......
79 83
  master socket.
80 84

  
81 85
  """
82
  def __init__(self, mainloop, address, handler_class):
86
  def __init__(self, mainloop, address, handler_class, uid, gid):
83 87
    """MasterServer constructor
84 88

  
85 89
    @type mainloop: ganeti.daemon.Mainloop
86 90
    @param mainloop: Mainloop used to poll for I/O events
87 91
    @param address: the unix socket address to bind the MasterServer to
88 92
    @param handler_class: handler class for the connections
93
    @param uid: The uid of the owner of the socket
94
    @param gid: The gid of the owner of the socket
89 95

  
90 96
    """
91
    daemon.AsyncStreamServer.__init__(self, socket.AF_UNIX, address)
97
    temp_name = tempfile.mktemp(dir=os.path.dirname(address))
98
    daemon.AsyncStreamServer.__init__(self, socket.AF_UNIX, temp_name)
99
    os.chmod(temp_name, 0770)
100
    os.chown(temp_name, uid, gid)
101
    os.rename(temp_name, address)
102

  
92 103
    self.request_handler_class = handler_class
93 104
    self.mainloop = mainloop
94 105

  
......
473 484

  
474 485
  ssconf.CheckMaster(options.debug)
475 486

  
487
  try:
488
    options.uid = pwd.getpwnam(constants.MASTERD_USER).pw_uid
489
    options.gid = grp.getgrnam(constants.DAEMONS_GROUP).gr_gid
490
  except KeyError:
491
    print >> sys.stderr, ("User or group not existing on system: %s:%s" %
492
                          (constants.MASTERD_USER, constants.DAEMONS_GROUP))
493
    sys.exit(constants.EXIT_FAILURE)
494

  
495

  
476 496
  # If CheckMaster didn't fail we believe we are the master, but we have to
477 497
  # confirm with the other nodes.
478 498
  if options.no_voting:
......
506 526
  utils.RemoveFile(constants.MASTER_SOCKET)
507 527

  
508 528
  mainloop = daemon.Mainloop()
509
  master = MasterServer(mainloop, constants.MASTER_SOCKET, ClientRqHandler)
529
  master = MasterServer(mainloop, constants.MASTER_SOCKET, ClientRqHandler,
530
                        options.uid, options.gid)
510 531
  try:
511 532
    rpc.Init()
512 533
    try:

Also available in: Unified diff