* lib/commonio.c: Avoid PATH_MAX. On glibc, we can use realpath
with a NULL argument. * src/useradd.c: Replace PATH_MAX by a fixed constant. The buffer was not meant as a storage for a path. * src/useradd.c, src/newusers.c, src/chpasswd.c: Better detection of fgets errors. Lines shall end with a \n, unless we reached the end of file. * libmisc/copydir.c: Avoid PATH_MAX. Support file paths with any length. Added readlink_malloc().
This commit is contained in:
@@ -83,21 +83,36 @@ static bool nscd_need_reload = false;
|
||||
*/
|
||||
int lrename (const char *old, const char *new)
|
||||
{
|
||||
|
||||
char resolved_path[PATH_MAX];
|
||||
int res;
|
||||
char *r = NULL;
|
||||
|
||||
#if defined(S_ISLNK)
|
||||
#ifndef __GLIBC__
|
||||
char resolved_path[PATH_MAX];
|
||||
#endif /* !__GLIBC__ */
|
||||
struct stat sb;
|
||||
if (lstat (new, &sb) == 0 && S_ISLNK (sb.st_mode)) {
|
||||
if (realpath (new, resolved_path) == NULL) {
|
||||
#ifdef __GLIBC__ /* now a POSIX.1-2008 feature */
|
||||
r = realpath (new, NULL);
|
||||
#else /* !__GLIBC__ */
|
||||
r = realpath (new, resolved_path);
|
||||
#endif /* !__GLIBC__ */
|
||||
if (NULL == r) {
|
||||
perror ("realpath in lrename()");
|
||||
} else {
|
||||
new = resolved_path;
|
||||
new = r;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif /* S_ISLNK */
|
||||
|
||||
res = rename (old, new);
|
||||
|
||||
#ifdef __GLIBC__
|
||||
if (NULL != r) {
|
||||
free (r);
|
||||
}
|
||||
#endif /* __GLIBC__ */
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user