void do_maintenance(const char *listdir, const char *mlmmjsend,
const char *mlmmjbounce, const char *mlmmjunsub)
{
- char *random, *logname, *logstr;
+ char *random, *logname;
char timenow[64];
struct stat st;
int maintdlogfd;
mlmmj_list_init(&list);
- if (stat(listdir, &st) < 0) {
+ if (!mlmmj_list_open(&list)) {
+ log_error(LOG_ARGS, "Could not open '%s'", list.dir);
+ return;
+ }
+
+ if (fstat(list.fd, &st) < 0) {
log_error(LOG_ARGS, "Could not stat(%s) "
"No maintenance run performed.", listdir);
return;
}
-
+
if(uid == 0) { /* We're root. Do something about it.*/
if(setuid(st.st_uid) < 0) {
log_error(LOG_ARGS, "Could not setuid listdir owner.");
return;
}
- mlmmj_list_open(&list);
random = random_str();
- logname = concatstr(3, listdir, "/maintdlog-", random);
+ myasprintf(&logname, "maintdlog-%s", random);
myfree(random);
- maintdlogfd = open(logname, O_WRONLY|O_EXCL|O_CREAT, S_IRUSR|S_IWUSR);
+ maintdlogfd = openat(list.fd, logname, O_WRONLY|O_EXCL|O_CREAT, S_IRUSR|S_IWUSR);
if(maintdlogfd < 0) {
log_error(LOG_ARGS, "Could not open %s", logname);
myfree(logname);
close(maintdlogfd);
- logstr = concatstr(3, listdir, "/", MAINTD_LOGFILE);
-
- if(rename(logname, logstr) < 0)
- log_error(LOG_ARGS, "Could not rename(%s,%s)",
- logname, logstr);
+ if(renameat(list.fd, logname, list.fd, MAINTD_LOGFILE) < 0)
+ log_error(LOG_ARGS, "Could not rename(%s/%s,%s/"MAINTD_LOGFILE")",
+ list.dir, logname, list.dir);
myfree(logname);
- myfree(logstr);
mlmmj_list_close(&list);
}
{
int opt, daemonize = 1, ret = 0;
char *bindir, *listdir = NULL, *mlmmjsend, *mlmmjbounce, *mlmmjunsub;
- char *dirlists = NULL, *s, *listiter;
- struct stat st;
+ char *dirlists = NULL, *listiter;
struct dirent *dp;
DIR *dirp;
if((strcmp(dp->d_name, "..") == 0) ||
(strcmp(dp->d_name, ".") == 0))
continue;
-
- listiter = concatstr(3, dirlists, "/", dp->d_name);
-
- if(stat(listiter, &st) < 0) {
- log_error(LOG_ARGS, "Could not stat(%s)",
- listiter);
- myfree(listiter);
- continue;
- }
-
- if(!S_ISDIR(st.st_mode)) {
- myfree(listiter);
- continue;
- }
-
- s = concatstr(2, listiter, "/control/listaddress");
- ret = stat(s, &st);
- myfree(s);
-
- if(ret < 0) { /* If ret < 0 it's not a listiter */
- myfree(listiter);
- continue;
- }
-
+ myasprintf(&listiter, "%s/%s", dirlists, dp->d_name);
do_maintenance(listiter, mlmmjsend, mlmmjbounce,
mlmmjunsub);
-
myfree(listiter);
}