Fixed getlogin() usage
This commit is contained in:
parent
029014ab20
commit
50bf39660f
@ -87,12 +87,17 @@ int strschg_environ(std::string& s) {
|
|||||||
#ifndef __HAVE_DRIVES__
|
#ifndef __HAVE_DRIVES__
|
||||||
if(not s.empty() and (s[0] == '~')) {
|
if(not s.empty() and (s[0] == '~')) {
|
||||||
std::string name;
|
std::string name;
|
||||||
|
char* lname;
|
||||||
const char *p = s.c_str()+1;
|
const char *p = s.c_str()+1;
|
||||||
if((s.length() != 1) and not isslash(*p)) {
|
if((s.length() != 1) and not isslash(*p)) {
|
||||||
while(*p and not isslash(*p))
|
while(*p and not isslash(*p))
|
||||||
name += *p++;
|
name += *p++;
|
||||||
} else
|
}
|
||||||
name = getlogin();
|
else {
|
||||||
|
if ((lname = getlogin()) == NULL)
|
||||||
|
lname = getenv("LOGNAME");
|
||||||
|
name = lname;
|
||||||
|
}
|
||||||
struct passwd *pe = getpwnam(name.c_str());
|
struct passwd *pe = getpwnam(name.c_str());
|
||||||
if(pe != NULL) {
|
if(pe != NULL) {
|
||||||
std::string dirname = pe->pw_dir;
|
std::string dirname = pe->pw_dir;
|
||||||
@ -188,12 +193,16 @@ bool maketruepath(std::string &dirname) {
|
|||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
if(!dirname.empty() && (dirname[0] == '~')) {
|
if(!dirname.empty() && (dirname[0] == '~')) {
|
||||||
|
char* lname;
|
||||||
const char *p = dirname.c_str()+1;
|
const char *p = dirname.c_str()+1;
|
||||||
if((dirname.length() != 1) && !isslash(*p)) {
|
if((dirname.length() != 1) && !isslash(*p)) {
|
||||||
while(*p && !isslash(*p))
|
while(*p && !isslash(*p))
|
||||||
ndirname += *p++; // get user name
|
ndirname += *p++; // get user name
|
||||||
} else
|
} else {
|
||||||
ndirname = getlogin(); // get current user name
|
if ((lname = getlogin()) == NULL)
|
||||||
|
lname = getenv("LOGNAME");
|
||||||
|
ndirname = lname; // get current user name
|
||||||
|
}
|
||||||
struct passwd *pe = getpwnam(ndirname.c_str()); // get home
|
struct passwd *pe = getpwnam(ndirname.c_str()); // get home
|
||||||
if(pe != NULL) {
|
if(pe != NULL) {
|
||||||
ndirname = pe->pw_dir;
|
ndirname = pe->pw_dir;
|
||||||
|
Reference in New Issue
Block a user