################################################################################
+#####################################
+#### This may run within sudo !! ####
+#####################################
def init():
global Cnf, Options, projectB
################################################################################
+#####################################
+#### This may run within sudo !! ####
+#####################################
def load_transitions(trans_file):
# Parse the yaml file
sourcefile = file(trans_file, 'r')
################################################################################
+#####################################
+#### This may run within sudo !! ####
+#####################################
def lock_file(file):
for retry in range(10):
lock_fd = os.open(file, os.O_RDWR | os.O_CREAT)
################################################################################
+#####################################
+#### This may run within sudo !! ####
+#####################################
def write_transitions(from_trans):
"""Update the active transitions file safely.
This function takes a parsed input file (which avoids invalid
class ParseException(Exception):
pass
+##########################################
+#### This usually runs within sudo !! ####
+##########################################
def write_transitions_from_file(from_file):
"""We have a file we think is valid; if we're using sudo, we invoke it
here, otherwise we just parse the file and call write_transitions"""
+ # Lets check if from_file is in the directory we expect it to be in
+ if not os.path.abspath(from_file).startswith(Cnf["Transitions::TempPath"]):
+ print "Will not accept transitions file outside of %s" % (Cnf["Transitions::TempPath"])
+ sys.exit(3)
+
if Options["sudo"]:
os.spawnl(os.P_WAIT, "/usr/bin/sudo", "/usr/bin/sudo", "-u", "dak", "-H",
"/usr/local/bin/dak", "transitions", "--import", from_file)
# We need the chmod, as the file is (most possibly) copied from a
# sudo-ed script and would be unreadable if it has default mkstemp mode
- (fd, path) = tempfile.mkstemp("","transitions")
+ (fd, path) = tempfile.mkstemp("","transitions",Cnf["Transitions::TempPath"])
os.chmod(path, 0644)
f = open(path, "w")
syck.dump(transitions, f)
def main():
global Cnf
+ #####################################
+ #### This can run within sudo !! ####
+ #####################################
init()
# Check if there is a file defined (and existant)
print m
sys.exit(2)
sys.exit(0)
+ ##############################################
+ #### Up to here it can run within sudo !! ####
+ ##############################################
# Parse the yaml file
transitions = load_transitions(transpath)