su-to-root
Apr 13, 2011 6:29:50 GMT 1
Post by 2lss on Apr 13, 2011 6:29:50 GMT 1
This is a little program I made as an alternative to gksudo, since I don't want to drag in all of the dependencies.
It works, but could use a little polishing.
One drawback is that when using sudo to run graphical applications, configuration files can become owned by root. Gksudo gets around this by changing the HOME variable and using a temporary .Xauthority file. I still have to get this working.
For more info: help.ubuntu.com/community/RootSudo#Graphical%20sudo
It works, but could use a little polishing.
One drawback is that when using sudo to run graphical applications, configuration files can become owned by root. Gksudo gets around this by changing the HOME variable and using a temporary .Xauthority file. I still have to get this working.
For more info: help.ubuntu.com/community/RootSudo#Graphical%20sudo
' TODO
' * Spawn child into separate process and let parent (su-to-root) exit
' * Add gksudo features (Xorg variables?)
' * Find way around three wrong password delay
' * Set focus to text box and ok button (ie type password and hit enter)
SETENVIRON "LANG", "C"
INCLUDE "hug.bac"
HUGOPTIONS("TABLE 10 6")
SUB quit
QUIT
END SUB
SUB toggle_pw
LOCAL state
state = GET(show_pw_check)
IF state = 0 THEN
SET(password, 0)
ELSE
SET(password, 1)
END IF
END SUB
SUB execute
LOCAL dimension
LOCAL arg$, pw$, result$
' The three EOLs are to get past the wrong password attempts
pw$ = CONCAT$(GRAB$(password), NL$, NL$, NL$)
DISABLE(password)
HIDE(text1)
HIDE(text3)
SHOW(text2)
SYNC
SPLIT ARGUMENT$ BY " " TO arg_split$ SIZE dimension
FOR x = 1 TO dimension-1
arg$ = CONCAT$(arg$, arg_split$[x], " ")
NEXT
result$ = EXEC$(CONCAT$("sudo -S", " -H ", " sh -c ", "'", arg$, "'"), pw$)
IF RETVAL = 0 THEN
SYSTEM "sudo -k"
QUIT
ELIF RETVAL = 1 THEN
HIDE(text2)
SHOW(text3)
ENABLE(password)
ELIF RETVAL = 127 THEN
HIDE(text2)
DISABLE(ok_button)
DISABLE(show_pw_check)
SHOW(text4)
ENDIF
END SUB
GLOBAL mainwin, text1, text2, text3, text4, password, ok_button, cancel_button, show_pw_check
mainwin = WINDOW("su-to-root", 300, 100)
text1 = MARK("Enter Sudo Password", 6, 1)
ATTACH(mainwin, text1, 2, 1)
text2 = MARK("Checking Password...", 6, 1)
ATTACH(mainwin, text2, 2, 1)
HIDE(text2)
text3 = MARK("Wrong! Try Again", 6, 1)
ATTACH(mainwin, text3, 2, 1)
HIDE(text3)
text4 = MARK("Command Not Found!", 6, 1)
ATTACH(mainwin, text4, 2, 1)
HIDE(text4)
password = PASSWORD(4, 2)
ATTACH(mainwin, password, 3, 2)
ok_button = BUTTON("Ok", 2, 2)
ATTACH(mainwin, ok_button, 8, 4)
CALLBACK(ok_button, execute)
cancel_button = BUTTON("Cancel", 2, 2)
ATTACH(mainwin, cancel_button, 6, 4)
CALLBACK(cancel_button, quit)
show_pw_check = CHECK("Show Password", 4, 2)
ATTACH(mainwin, show_pw_check, 0, 4)
CALLBACK(show_pw_check, toggle_pw)
FOCUS(password)
'FOCUS(ok_button)
DISPLAY