version 1.87, 2012/04/12 04:47:59 |
version 1.88, 2012/05/23 05:29:22 |
|
|
char * |
char * |
adjustname(const char *fn, int slashslash) |
adjustname(const char *fn, int slashslash) |
{ |
{ |
|
struct stat statbuf; |
static char fnb[MAXPATHLEN]; |
static char fnb[MAXPATHLEN]; |
const char *cp, *ep = NULL; |
const char *cp, *ep = NULL; |
char user[LOGIN_NAME_MAX], path[MAXPATHLEN]; |
char user[LOGIN_NAME_MAX], path[MAXPATHLEN]; |
|
|
} |
} |
} |
} |
|
|
/* first handle tilde expansion */ |
/* |
if (fn[0] == '~') { |
* Next, expand file names beginning with '~', if appropriate: |
|
* 1, if ./~fn exists, continue without expanding tilde. |
|
* 2, otherwise, if username 'fn' exists, expand tilde with home |
|
* directory path. |
|
* 3, otherwise, continue and create new buffer called ~fn. |
|
*/ |
|
if (fn[0] == '~' && stat(fn, &statbuf) != 0) { |
struct passwd *pw; |
struct passwd *pw; |
|
|
cp = strchr(fn, '/'); |
cp = strchr(fn, '/'); |
|
|
user[ulen] = '\0'; |
user[ulen] = '\0'; |
} |
} |
pw = getpwnam(user); |
pw = getpwnam(user); |
if (pw == NULL) { |
if (pw != NULL) { |
ewprintf("Unknown user %s", user); |
plen = strlcpy(path, pw->pw_dir, sizeof(path)); |
return (NULL); |
if (plen == 0 || path[plen - 1] != '/') { |
} |
if (strlcat(path, "/", sizeof(path)) >= |
plen = strlcpy(path, pw->pw_dir, sizeof(path)); |
sizeof(path)) { |
if (plen == 0 || path[plen - 1] != '/') { |
ewprintf("Path too long"); |
if (strlcat(path, "/", sizeof(path)) >= sizeof(path)) { |
return (NULL); |
ewprintf("Path too long"); |
} |
return (NULL); |
|
} |
} |
|
fn = cp; |
|
if (*fn == '/') |
|
fn++; |
} |
} |
fn = cp; |
|
if (*fn == '/') |
|
fn++; |
|
} |
} |
if (strlcat(path, fn, sizeof(path)) >= sizeof(path)) { |
if (strlcat(path, fn, sizeof(path)) >= sizeof(path)) { |
ewprintf("Path too long"); |
ewprintf("Path too long"); |