added username/homedir support

This commit is contained in:
Дмитрий Левин 2002-08-12 15:53:39 +00:00
parent 962bb173fc
commit c3a7049f78
2 changed files with 28 additions and 4 deletions

View File

@ -502,13 +502,9 @@ static void rpmSetDefaults(void)
return;
else
{
struct passwd *pw = getpwuid( geteuid() );
setVar( "_usr", "/usr" );
setVar( "_var", "/var" );
setVar( "_preScriptEnvironment", prescriptenviron );
setVar( "_username", pw ? pw->pw_name : 0 );
setVar( "_homedir", pw ? pw->pw_dir : 0 );
setVar( "_topdir", "%{_usr}/src/RPM" );
setVar( "_tmppath", "%{_var}/tmp" );

View File

@ -1109,6 +1109,32 @@ doFoo(MacroBuf mb, int negate, const char * f, size_t fn,
} else if (STREQ("F", f, fn)) {
b = buf + strlen(buf) + 1;
sprintf(b, "file%s.file", buf);
} else if (STREQ("username", f, fn)) {
struct passwd *pw;
if (buf[0])
pw = getpwnam (buf);
else
pw = getpwuid (geteuid());
buf[0] = '\0';
if (pw && pw->pw_name) {
strncat (buf, pw->pw_name, sizeof buf);
b = buf;
}
} else if (STREQ("homedir", f, fn)) {
struct passwd *pw;
if (buf[0])
pw = getpwnam (buf);
else
pw = getpwuid (geteuid());
buf[0] = '\0';
if (pw && pw->pw_dir) {
strncat (buf, pw->pw_dir, sizeof buf);
b = buf;
}
}
if (b) {
@ -1337,6 +1363,8 @@ expandMacro(MacroBuf mb)
STREQ("uncompress", f, fn) ||
STREQ("url2path", f, fn) ||
STREQ("u2p", f, fn) ||
STREQ("username", f, fn) ||
STREQ("homedir", f, fn) ||
STREQ("S", f, fn) ||
STREQ("P", f, fn) ||
STREQ("F", f, fn)) {