Skip to content

Commit

Permalink
handle target root path in system agent (.target)
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Oct 23, 2013
1 parent d567951 commit 26c9246
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions agent-system/src/SystemAgent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,8 @@ SystemAgent::Read (const YCPPath& path, const YCPValue& arg, const YCPValue&)
return YCPNull ();
}

filename = targetPath(filename);

if (cmd == "string")
{
/**
Expand Down Expand Up @@ -697,12 +699,9 @@ SystemAgent::Write (const YCPPath& path, const YCPValue& value,
path->component_str (1).c_str () + ":" + passwd +
"' |/usr/sbin/chpasswd -e >/dev/null 2>&1";

// Don't write the password into the log - even though it's crypted
// y2debug("Executing: '%s'", bashcommand.c_str());

int exitcode = system(bashcommand.c_str());
int exitcode = shellcommand(root(), bashcommand.c_str());

return YCPBoolean (WIFEXITED (exitcode) && WEXITSTATUS (exitcode) == 0);
return YCPBoolean(exitcode == 0);
}

else if (cmd == "string")
Expand Down Expand Up @@ -752,6 +751,8 @@ SystemAgent::Write (const YCPPath& path, const YCPValue& value,
return YCPBoolean (false);
}

filename = targetPath(filename);

int fd = open(filename.c_str(), O_WRONLY | O_CREAT | O_TRUNC, filemode);
if (fd >= 0)
{
Expand Down Expand Up @@ -785,7 +786,7 @@ SystemAgent::Write (const YCPPath& path, const YCPValue& value,
return YCPBoolean (false);
}

string filename = value->asString ()->value ();
string filename = targetPath(value->asString()->value());
YCPByteblock byteblock = arg->asByteblock ();

int fd = open (filename.c_str (), O_WRONLY | O_CREAT | O_TRUNC, 0644);
Expand Down Expand Up @@ -857,6 +858,8 @@ SystemAgent::Write (const YCPPath& path, const YCPValue& value,
return YCPBoolean (false);
}

filename = targetPath(filename);

// Create directory, if missing
size_t pos = 0;
while (pos = filename.find('/', pos + 1), pos != string::npos)
Expand Down Expand Up @@ -1082,6 +1085,9 @@ SystemAgent::Execute (const YCPPath& path, const YCPValue& value,
{
return YCPError ("Bad arguments to Execute (.symlink, string old, string new)");
}

// the old path does not need root() prefix
// otherwise it would point to wrong place in the target system
const char *oldpath = value->asString()->value_cstr();
const string newpath = targetPath(arg->asString()->value());

Expand Down

0 comments on commit 26c9246

Please sign in to comment.