Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
John McEleney
/
mailutils
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
fffe6137
...
fffe6137e227c5af157b7520fb4aa73aad00dd8e
authored
2002-04-15 02:34:56 +0000
by
Sam Roberts
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Implemented symlink unrolling before locking.
1 parent
7eb2aa3d
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
81 additions
and
3 deletions
include/mailutils/mutil.h
mailbox/locker.c
mailbox/mutil.c
include/mailutils/mutil.h
View file @
fffe613
...
...
@@ -84,6 +84,7 @@ typedef void *(*mu_retrieve_fp) __P((void *));
extern
void
mu_register_retriever
__P
((
list_t
*
pflist
,
mu_retrieve_fp
fun
));
extern
void
*
mu_retrieve
__P
((
list_t
flist
,
void
*
data
));
extern
int
mu_unroll_symlink
__P
((
char
*
out
,
size_t
outsz
,
const
char
*
in
));
#ifdef __cplusplus
}
...
...
mailbox/locker.c
View file @
fffe613
...
...
@@ -100,21 +100,26 @@ int locker_set_default_flags(int flags)
}
int
locker_create
(
locker_t
*
plocker
,
const
char
*
filename
,
int
flags
)
locker_create
(
locker_t
*
plocker
,
const
char
*
filename
_
,
int
flags
)
{
locker_t
l
;
char
filename
[
_POSIX_PATH_MAX
];
int
err
=
0
;
if
(
plocker
==
NULL
)
return
MU_ERR_OUT_PTR_NULL
;
if
(
filename
==
NULL
)
if
(
filename
_
==
NULL
)
return
EINVAL
;
if
((
err
=
mu_unroll_symlink
(
filename
,
sizeof
(
filename
),
filename_
)))
return
err
;
l
=
calloc
(
1
,
sizeof
(
*
l
));
if
(
l
==
NULL
)
return
ENOMEM
;
/* Should make l->file be the result of following the symlinks. */
l
->
file
=
strdup
(
filename
);
if
(
l
->
file
==
NULL
)
...
...
mailbox/mutil.c
View file @
fffe613
...
...
@@ -21,6 +21,7 @@
#endif
#include <errno.h>
#include <limits.h>
#include <netdb.h>
#include <pwd.h>
#include <signal.h>
...
...
@@ -776,3 +777,74 @@ int mu_spawnvp (const char* prog, const char* const av_[], int* stat)
return
err
;
}
/* The result of readlink() may be a path relative to that link,
* qualify it if necessary.
*/
static
void
mu_qualify_link
(
const
char
*
path
,
const
char
*
link
,
char
*
qualified
)
{
const
char
*
lb
=
NULL
;
size_t
len
;
/* link is full path */
if
(
*
link
==
'/'
)
{
mu_cpystr
(
qualified
,
link
,
_POSIX_PATH_MAX
);
return
;
}
if
((
lb
=
strrchr
(
path
,
'/'
))
==
NULL
)
{
/* no path in link */
mu_cpystr
(
qualified
,
link
,
_POSIX_PATH_MAX
);
return
;
}
len
=
lb
-
path
+
1
;
memcpy
(
qualified
,
path
,
len
);
mu_cpystr
(
qualified
+
len
,
link
,
_POSIX_PATH_MAX
-
len
);
}
#ifndef _POSIX_SYMLOOP_MAX
# define _POSIX_SYMLOOP_MAX 255
#endif
int
mu_unroll_symlink
(
char
*
out
,
size_t
outsz
,
const
char
*
in
)
{
char
path
[
_POSIX_PATH_MAX
];
int
symloops
=
0
;
while
(
symloops
++
<
_POSIX_SYMLOOP_MAX
)
{
struct
stat
s
;
char
link
[
_POSIX_PATH_MAX
];
char
qualified
[
_POSIX_PATH_MAX
];
int
len
;
if
(
lstat
(
in
,
&
s
)
==
-
1
)
return
errno
;
if
(
!
S_ISLNK
(
s
.
st_mode
))
{
mu_cpystr
(
path
,
in
,
sizeof
(
path
));
break
;
}
if
((
len
=
readlink
(
in
,
link
,
sizeof
(
link
)))
==
-
1
)
return
errno
;
link
[(
len
>=
sizeof
(
link
))
?
(
sizeof
(
link
)
-
1
)
:
len
]
=
'\0'
;
mu_qualify_link
(
in
,
link
,
qualified
);
mu_cpystr
(
path
,
qualified
,
sizeof
(
path
));
in
=
path
;
}
mu_cpystr
(
out
,
path
,
outsz
);
return
0
;
}
...
...
Please
register
or
sign in
to post a comment