Dolda2000 GitWeb
/
doldaconnect.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Updated findfile.
[doldaconnect.git]
/
common
/
utils.c
diff --git
a/common/utils.c
b/common/utils.c
index
cdf2bc6
..
5c909ec
100644
(file)
--- a/
common/utils.c
+++ b/
common/utils.c
@@
-732,31
+732,38
@@
char *getetcpath(char *binpath)
return(etcpath);
}
return(etcpath);
}
-char *findfile(char *
gname, char *u
name, char *homedir, int filldef)
+char *findfile(char *name, char *homedir, int filldef)
{
char *path, *binpath, *etcpath, *p;
struct passwd *pw;
{
char *path, *binpath, *etcpath, *p;
struct passwd *pw;
- int mode;
+ int mode
, homeonly
;
+ if(name == NULL)
+ return(NULL);
+
mode = R_OK | (filldef ? W_OK : 0);
mode = R_OK | (filldef ? W_OK : 0);
- if(uname != NULL) {
+ homeonly = homedir != NULL;
+
+ if(!strchr(name, '/'))
+ {
if(homedir == NULL)
homedir = getenv("HOME");
if((homedir == NULL) && ((pw = getpwuid(getuid())) != NULL))
homedir = pw->pw_dir;
if(homedir == NULL)
homedir = getenv("HOME");
if((homedir == NULL) && ((pw = getpwuid(getuid())) != NULL))
homedir = pw->pw_dir;
- if((homedir != NULL) && ((path = sprintf2("%s/.%s", homedir,
u
name)) != NULL))
+ if((homedir != NULL) && ((path = sprintf2("%s/.%s", homedir, name)) != NULL))
{
if(!access(path, mode))
return(path);
free(path);
}
}
{
if(!access(path, mode))
return(path);
free(path);
}
}
- if(gname != NULL)
+
+ if(!homeonly)
{
{
- if(strchr(
g
name, '/') != NULL)
+ if(strchr(name, '/') != NULL)
{
{
- if(!access(
g
name, mode))
- return(sstrdup(
g
name));
+ if(!access(name, mode))
+ return(sstrdup(name));
} else {
if((binpath = getenv("PATH")) == NULL)
etcpath = sstrdup("/usr/local/etc:/etc:/usr/etc");
} else {
if((binpath = getenv("PATH")) == NULL)
etcpath = sstrdup("/usr/local/etc:/etc:/usr/etc");
@@
-764,7
+771,7
@@
char *findfile(char *gname, char *uname, char *homedir, int filldef)
etcpath = getetcpath(binpath);
for(p = strtok(etcpath, ":"); p != NULL; p = strtok(NULL, ":"))
{
etcpath = getetcpath(binpath);
for(p = strtok(etcpath, ":"); p != NULL; p = strtok(NULL, ":"))
{
- if((path = sprintf2("%s/%s", p,
g
name)) != NULL)
+ if((path = sprintf2("%s/%s", p, name)) != NULL)
{
if(!access(path, mode))
{
{
if(!access(path, mode))
{
@@
-777,10
+784,11
@@
char *findfile(char *gname, char *uname, char *homedir, int filldef)
free(etcpath);
}
}
free(etcpath);
}
}
+
if(filldef) {
if(filldef) {
- if(
uname &&
homedir)
- return(sprintf2("%s/.%s", homedir,
u
name));
- return(sprintf2("/etc/%s",
g
name));
+ if(homedir)
+ return(sprintf2("%s/.%s", homedir, name));
+ return(sprintf2("/etc/%s", name));
} else {
return(NULL);
}
} else {
return(NULL);
}