Author: jsrain
Date: Wed Oct 22 17:22:40 2008
New Revision: 52442
URL: http://svn.opensuse.org/viewcvs/yast?rev=52442&view=rev
Log:
added support for running as non-root
Modified:
trunk/support/package/yast2-support.changes
trunk/support/src/.dep
trunk/support/src/Support.ycp
trunk/support/src/complex.ycp
trunk/support/src/dialogs.ycp
Modified: trunk/support/package/yast2-support.changes
URL: http://svn.opensuse.org/viewcvs/yast/trunk/support/package/yast2-support.changes?rev=52442&r1=52441&r2=52442&view=diff
==============================================================================
--- trunk/support/package/yast2-support.changes (original)
+++ trunk/support/package/yast2-support.changes Wed Oct 22 17:22:40 2008
@@ -1,4 +1,9 @@
-------------------------------------------------------------------
+Wed Oct 22 17:04:56 CEST 2008 - jsrain@suse.cz
+
+- added support for running as non-root
+
+-------------------------------------------------------------------
Mon Oct 20 13:20:26 CEST 2008 - mzugec@suse.cz
- fixed some text typos (bnc#436826)
Modified: trunk/support/src/.dep
URL: http://svn.opensuse.org/viewcvs/yast/trunk/support/src/.dep?rev=52442&r1=52441&r2=52442&view=diff
==============================================================================
--- trunk/support/src/.dep (original)
+++ trunk/support/src/.dep Wed Oct 22 17:22:40 2008
@@ -4,5 +4,6 @@
/usr/share/YaST2/modules/Summary.ybc \
/usr/share/YaST2/modules/Message.ybc \
/usr/share/YaST2/modules/Map.ybc \
- /usr/share/YaST2/modules/PackageSystem.ybc
+ /usr/share/YaST2/modules/PackageSystem.ybc \
+ /usr/share/YaST2/modules/Label.ybc
Modified: trunk/support/src/Support.ycp
URL: http://svn.opensuse.org/viewcvs/yast/trunk/support/src/Support.ycp?rev=52442&r1=52441&r2=52442&view=diff
==============================================================================
--- trunk/support/src/Support.ycp (original)
+++ trunk/support/src/Support.ycp Wed Oct 22 17:22:40 2008
@@ -41,6 +41,7 @@
import "Message";
import "Map";
import "PackageSystem";
+import "Label";
/**
* Prototypes
@@ -69,6 +70,63 @@
boolean() AbortFunction = Modified;
/**
+ * root password for running supportconfig if module run as non-root
+ */
+global string root_pw = nil;
+
+global string pwd_pipe = nil;
+
+global boolean CheckRootPw (string pw) {
+ if (pwd_pipe == nil)
+ pwd_pipe = ((string)SCR::Read (.target.tmpdir) + "/pwd_pipe");
+ SCR::Execute (.target.bash, "test -e %1 || mkfifo %1", pwd_pipe);
+ SCR::Write (.target.string, pwd_pipe, pw + "\n");
+ integer exit = (integer)SCR::Execute (.target.bash, sformat ("cat %1 | su -c 'echo 0'", pwd_pipe));
+ boolean success = (exit == 0);
+ y2milestone ("Root password check: %1", success);
+ if (success)
+ root_pw = pw;
+ return success;
+}
+
+global integer WhoAmI() {
+ if ((integer)SCR::Read (.target.size, "/usr/bin/id") <= 0)
+ {
+ y2warning ("/usr/bin/id not existing, supposing to be root");
+ return 0;
+ }
+
+ map out = (map) SCR::Execute (.target.bash_output, "/usr/bin/id --user");
+ list<string> lines = splitstring (out["stdout"]:"", "\n");
+ string strid = lines[0]:"";
+ integer id = tointeger (strid);
+ if (id == nil)
+ return 0;
+ return id;
+}
+
+global boolean AskForRootPwd () {
+ while (root_pw == nil) {
+ UI::OpenDialog (`VBox (
+ `Label (_("To continue, enter root password")),
+ `Password (`id (`passwd), _("root Password")),
+ `ButtonBox (
+ `PushButton (`id(`ok), `opt (`okButton, `default, `key_F10), Label::OKButton()),
+ `PushButton (`id(`cancel), `opt (`cancelButton, `key_F9), Label::CancelButton())
+ )
+ ));
+ symbol input = (symbol)UI::UserInput();
+ string pw = (string)UI::QueryWidget (`id (`passwd), `Value);
+ UI::CloseDialog ();
+ if (input == `cancel)
+ return false;
+ if (! CheckRootPw (pw))
+ Report::Error (_("Password incorrect"));
+ }
+ return true;
+}
+
+/**
* Abort function
* @return boolean return true if abort
*/
Modified: trunk/support/src/complex.ycp
URL: http://svn.opensuse.org/viewcvs/yast/trunk/support/src/complex.ycp?rev=52442&r1=52441&r2=52442&view=diff
==============================================================================
--- trunk/support/src/complex.ycp (original)
+++ trunk/support/src/complex.ycp Wed Oct 22 17:22:40 2008
@@ -64,7 +64,71 @@
symbol ReadDialog() {
Wizard::RestoreHelp(HELPS["read"]:"");
// Support::SetAbortFunction(PollAbort);
- if (!Confirm::MustBeRoot()) return `abort;
+// if (!Confirm::MustBeRoot()) return `abort;
+ if (Support::WhoAmI() != 0)
+ {
+ // use configuration file in home directory
+ string cmd = sformat ("ls %1", "~/.supportconfig");
+ map out = (map)SCR::Execute (.target.bash_output, cmd);
+ string file = out["stdout"]:"";
+ file = splitstring (file, "\n")[0]:"";
+ if (file == "" || file == nil)
+ {
+ if (!Confirm::MustBeRoot()) return `abort;
+ }
+ y2milestone ("Using configuration file %1", file);
+ setenv ("SC_CONF", file);
+ // ensure ~/.supportconfig does exist
+ if (SCR::Read (.target.size, file) < 0)
+ {
+ string cmd = sformat ("/bin/cp %1 %2", "/etc/supportconfig.conf", file);
+ SCR::Execute (.target.bash, cmd);
+ }
+ SCR::UnregisterAgent(.etc.supportconfig);
+ SCR::RegisterAgent (.etc.supportconfig, `ag_ini(
+ `IniAgent( file,
+ $[
+ "options" : [ "global_values", "comments_last", "line_can_continue", "join_multiline" ],
+ "comments": [
+ "^[ \t]*$", // empty line
+ "^[ \t]+[;#].*$", // comment char is not first char
+ "^[#][ \t]*$", // only comment chars
+ "^[#][ \t]*\\[[^]]*$", // comment chars followed by '[' without matching ']'
+ "^[#][^ \t[]", // comment char followed by non-blank nor '['
+ "^[#][ \t]+[^[a-z \t].*$", // comment chars followed by non a-z char nor '[' nor blank
+ "^[#][ \t]+[a-z ]*[a-z][ \t]*$", // comment chars followed by a-z or blank chars
+ "^[#][ \t]+[a-z ]*[a-z][ \t]*[^a-z \t=].*$", // like above, but followed by non a-z nor blank nor '=' chars
+ ],
+ /*
+ "sections" : [
+ $[
+ "begin" : [ "^[ \t]*\\[[ \t]*(.*[^ \t])[ \t]*\\][ \t]*", "[%s]" ],
+ ], $[
+ // this is a special type for commenting out the values
+ "begin" : [ "^[#;][ \t]*\\[[ \t]*(.*[^ \t])[ \t]*\\][ \t]*", "# [%s]" ],
+ ]
+ ],
+ */
+ // we need to exclude ; because of the second matching rule
+ "params" : [
+ // Options with one value ('yes' / 'no')
+ // $[ "match" : [ "^[#;][ \t]*([^ \t]+)[ \t]+([^ \t]+)[ \t]+$", "%s %s" ]],
+ // $[ "match" : [ "^[#;][ \t]*([^ \t\=]+)[ \t\=]?(.+)[ \t]*$", "; %s %s" ]],
+ // Options with more possible values
+ // $[ "match" : [ "^[ \t]*([^ \t\=]+)[ \t\=]+[ ]*\"(.*)\"[ \t]*$", "%s=\"%s\"" ]],
+ // string
+ $[ "match" : [ "^[ \t]*([^ \t\=]+)[ \t\=]+[ ]*\"(.*)\"[[:space:]]*\#[\-[:space:][:alnum:]]*$", "%s=\"%s\"" ]],
+ $[ "match" : [ "^[ \t]*([^ \t\=]+)[ \t\=]+[ ]*\"(.*)\"[[:space:]]*$", "%s=\"%s\"" ]],
+ // number
+ $[ "match" : [ "^[ \t]*([^ \t\=]+)[ \t\=]+[ ]*([[:digit:]]+)[[:space:]]*\#[\-[:alnum:][:space:]]*$", "%s=%s" ]],
+ $[ "match" : [ "^[ \t]*([^ \t\=]+)[ \t\=]+[ ]*(.+)[[:space:]]*$", "%s=%s" ]],
+ ],
+ ]
+ )
+ ));
+ }
+ y2internal ("Read 2: %1", SCR::Read (.etc.supportconfig.all));
+
boolean ret = Support::Read();
return ret ? `next : `abort;
}
Modified: trunk/support/src/dialogs.ycp
URL: http://svn.opensuse.org/viewcvs/yast/trunk/support/src/dialogs.ycp?rev=52442&r1=52441&r2=52442&view=diff
==============================================================================
--- trunk/support/src/dialogs.ycp (original)
+++ trunk/support/src/dialogs.ycp Wed Oct 22 17:22:40 2008
@@ -195,6 +195,13 @@
string url = (string)UI::QueryWidget(`url, `Value);
if (size(url)>0) command = sformat("%1 -U %2", command, url);
}
+ if (Support::WhoAmI() != 0) {
+ if (! Support::AskForRootPwd())
+ return `back;
+ integer id = Support::WhoAmI();
+ SCR::Write (.target.string, Support::pwd_pipe, Support::root_pw + "\n");
+ command = sformat("cat %2 | su -c '%1'", command, Support::pwd_pipe);
+ }
y2milestone("executing %1", command);
map