-
Notifications
You must be signed in to change notification settings - Fork 0
/
gdmlogin.py
executable file
·137 lines (109 loc) · 3.12 KB
/
gdmlogin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#! /usr/bin/env python2
import os
import sys
import getopt
CONF_PATH = "/etc/gdm/custom.conf"
#---
def SetValue(targetfile,targetsection,target,value):
FIND_STATE = False
ofile = open(targetfile,'r')
lines = ofile.readlines()
ofile.close()
for i in range(len(lines)) :
if lines[i].strip()[0:len(target)+1]==target+"=" :
lines[i] = target+'='+value+'\n'
FIND_STATE = True
break
if FIND_STATE :
ofile = open(targetfile,'w')
ofile.writelines(lines)
ofile.close()
else:
SECTION_FIND_STATE = False
for i in range(len(lines)) :
if lines[i].strip()=="["+targetsection+"]" :
lines.insert(i+1,target+'='+value+'\n')
SECTION_FIND_STATE = True
break
if SECTION_FIND_STATE :
ofile = open(targetfile,'w')
ofile.writelines(lines)
ofile.close()
else:
#print >> sys.stderr, "SECTION "+targetsection+" NOT FOUND"
lines.append("\n")
lines.append("["+targetsection+"]\n")
lines.append(target+'='+value+'\n')
lines.append("\n")
ofile = open(targetfile,'w')
ofile.writelines(lines)
ofile.close()
#--
args = sys.argv[1:]
optlist, optargs = getopt.getopt(args,'mau:d:')
MANUALLOGIN = False
AUTOLOGIN = False
TIMED = False
TIMED_TIME = 0
USER = False
USER_NAME = ""
for i in range(len(optlist)) :
opt , arg = optlist[i]
if opt == "-m" :
MANUALLOGIN = True
elif opt == "-a" :
AUTOLOGIN = True
elif opt == "-u" :
USER = True
USER_NAME = arg
elif opt == "-d" :
TIMED = True
TIMED_TIME = arg
if os.getuid()==0 :
if not os.path.isfile(CONF_PATH) :
ofile = open(CONF_PATH,'w')
ofile.write("# GDM configuration storage\n\n\
[daemon]\n\n\
[security]\n\n\
[xdmcp]\n\n\
[greeter]\n\n\
[chooser]\n\n\
[debug]\n\n\
")
ofile.close()
if (MANUALLOGIN and AUTOLOGIN) or (AUTOLOGIN and not USER) or (not AUTOLOGIN and not MANUALLOGIN):
if MANUALLOGIN and AUTOLOGIN :
print >> sys.stderr, "ERROR : Manual and Automatic Login in same time !"
if AUTOLOGIN and not USER :
print >> sys.stderr, "ERROR : Automatic Login Without User Name !"
if not AUTOLOGIN and not MANUALLOGIN :
print "gdm3setup.py :\n\
-m :\tManual login\n\
-a :\tAutomtic login\n\
-u :\tUserName (Need for autologin)\n\
-d :\tDelay before autologin in second"
else:
if AUTOLOGIN :
if AUTOLOGIN and not TIMED :
print "AutomaticLoginEnable=1"
print "AutomaticLogin="+USER_NAME
print "TimedLoginEnable=0"
SetValue(CONF_PATH,"daemon","AutomaticLoginEnable","1")
SetValue(CONF_PATH,"daemon","AutomaticLogin",USER_NAME)
SetValue(CONF_PATH,"daemon","TimedLoginEnable","0")
else:
print "AutomaticLoginEnable=0"
print "TimedLoginEnable=1"
print "TimedLogin="+USER_NAME
print "TimedLoginDelay : "+TIMED_TIME
SetValue(CONF_PATH,"daemon","AutomaticLoginEnable","0")
SetValue(CONF_PATH,"daemon","TimedLoginEnable","1")
SetValue(CONF_PATH,"daemon","TimedLogin",USER_NAME)
SetValue(CONF_PATH,"daemon","TimedLoginDelay",TIMED_TIME)
else:
print "AutomaticLoginEnable=0"
print "TimedLoginEnable=0"
SetValue(CONF_PATH,"daemon","AutomaticLoginEnable","0")
SetValue(CONF_PATH,"daemon","TimedLoginEnable","0")
else:
print >> sys.stderr, "Must Be Run as root"