26#define WHO "qmail-qmaint"
53 logmsg(
WHO,111,ERROR,B(
"Failed to make: ",name));
58 logmsg(
WHO,111,ERROR,B(
"Failed to determine uid of: ",
user));
63 logmsg(
WHO,111,ERROR,B(
"Failed to determine gid of: ",group));
68 logmsg(
WHO,111,ERROR,
"Failed while checking directory structure. \nEnsure the given queue exists and you have permission to access it.");
73 logmsg(
WHO,110,ERROR,
"Failed to reconstruct queue. \nEnsure the queue exists and you have permission to modify it.");
78 logmsg(
WHO,110,ERROR,
"Out of memory.");
87 if (getln(buffer_0,&
query,&
match,
'\n'))
return 0;
89 if (
query.s[0] ==
'y' ||
query.s[0] ==
'Y' ||
query.s[0] ==
'\n')
return 1;
95#define DIRS logmsg(WHO,0,WARN,"It looks like some directories don't exist, should I create them? (Y/n)")
96#define FILES logmsg(WHO,0,WARN,"It looks like some files don't exist, should I create them? (Y/n)")
98#define PERMS logmsg(WHO,0,WARN,B("It looks like permissions are wrong for ",name," should I fix them? (Y/n)"))
99#define CPERMS logmsg(WHO,0,WARN,B("Changing permissions: ",name," => ",pnum))
101#define OWNER logmsg(WHO,0,WARN,B("It looks like ownerships are wrong for ",name," should I fix them? (Y/n)"))
102#define COWNER logmsg(WHO,0,WARN,B("Changing ownership: ",name," => ",unum,"/",gnum))
116 strnum[fmt_ulong(gnum,gid)] = 0;
121 if (stat(name,&st)) {
122 if (errno != ENOENT)
return -1;
128 logmsg(
WHO,0,INFO,B(
"Creating directory: ",name));
135 if (st.st_uid !=
uid || st.st_gid != gid) {
139 if ((st.st_mode & 07777) !=
perm) {
145 if (stat(name,&st))
return -1;
147 if (st.st_uid !=
uid || (st.st_gid != gid && gid != -1)) {
151 if ((st.st_mode & 07777) !=
perm) {
157 if (stat(name,&st)) {
158 if (errno != ENOENT)
return -1;
166 logmsg(
WHO,0,INFO,B(
"Creating: ",name,
" with size ",
num));
167 fd = open_trunc(name);
176 if (st.st_uid !=
uid || (st.st_gid != gid && gid != -1)) {
180 if ((st.st_mode & 07777) !=
perm) {
184 if (st.st_size !=
size) {
185 logmsg(
WHO,0,WARN,B(
"File ",name,
" has not the right size. I will not fix it, please investigate."));
189 if (stat(name,&st)) {
190 if (errno != ENOENT)
return -1;
196 logmsg(
WHO,INFO,0,B(
"Creating fifo: ",name));
203 if (st.st_uid !=
uid || (st.st_gid != gid && gid != -1)) {
207 if ((st.st_mode & 07777) !=
perm) {
222 dir = opendir(directory);
225 while ((
d = readdir(dir))) {
226 if (
d->d_name[0] ==
'.')
continue;
243 dir = opendir(directory);
246 while ((
d = readdir(dir))) {
247 if (
d->d_name[0] ==
'.')
continue;
255 logmsg(
WHO,0,WARN,B(
"Found files in ",directory,
" that shouldn't be there. I will not remove them. You should consider checking it out."));
258int check_splits(
char * directory,
int dir_uid,
int dir_gid,
int dir_perm,
int file_gid,
int file_perm)
277 while ((
d = readdir(dir))) {
278 if (
d->d_name[0] ==
'.')
continue;
291int rename_mess(
char *dir,
char *part,
char *new_part,
char *old_filename,
char *new_filename)
295 logmsg(
WHO,0,INFO,
"It looks like some files need to be renamed, should I rename them? (Y/n)\n");
318 if (errno != ENOENT)
return -1;
329 char inode[FMT_ULONG];
330 char new_part[FMT_ULONG];
333 int correct_part_num;
335 scan_uint(part,&part_num);
345 while ((
d = readdir(dir))) {
346 if (
d->d_name[0] ==
'.')
continue;
356 scan_uint(
d->d_name,&old_inode);
357 correct_part_num = st.st_ino %
split_num;
358 if (st.st_ino != old_inode || part_num != correct_part_num) {
360 inode[fmt_ulong(inode,st.st_ino)] = 0;
361 new_part[fmt_ulong(new_part,correct_part_num)] = 0;
362 if (
rename_mess(
"mess/",part,new_part,
d->d_name,inode)) { closedir(dir);
return -1; }
363 if (
rename_mess(
"info/",part,new_part,
d->d_name,inode)) { closedir(dir);
return -1; }
364 if (
rename_mess(
"local/",part,new_part,
d->d_name,inode)) { closedir(dir);
return -1; }
365 if (
rename_mess(
"remote/",part,new_part,
d->d_name,inode)) { closedir(dir);
return -1; }
366 if (
rename_mess(
"todo/",part,new_part,
d->d_name,inode)) { closedir(dir);
return -1; }
367 if (
rename_mess(
"intd/",part,new_part,
d->d_name,inode)) { closedir(dir);
return -1; }
369 if (
rename_mess(
"bounce",
"",
"",
d->d_name,inode)) { closedir(dir);
return -1; }
496 foo[fmt_ulong(
foo,
id)] = 0;
497 logmsg(
WHO,99,WARN,B(
"no such file to unlink #",
foo));
503 foo[fmt_ulong(
foo,
id)] = 0;
504 logmsg(
WHO,100,ERROR,B(
"trouble with unlinking #",
foo));
509 logmsg(
WHO,110,FATAL,
"unable to chdir");
524 if (!bounce && unlink(
fn.s) == -1)
529 if (unlink(
fn.s) == -1)
535 if (unlink(
fn.s) == -1)
541 if (unlink(
fn.s) == -1)
546 if (unlink(
fn.s) == -1)
555 unsigned long id = 0;
558 if (!str_diff(argv[1],
"-i")) {
560 }
else if (!str_diff(argv[1],
"-d")) {
561 if (!argv[2]) logmsg(
WHO,111,USAGE,
"qmail-qmaint [-i] || [-d messid]");
564 scan_ulong(
mess,&
id);
571 logmsg(
WHO,0,INFO,B(
"Checking s/qmail queue at: ",
auto_qmail,
"/queue/"));
587 logmsg(
WHO,0,INFO,B(
"file ",
mess,
" from queue deleted."));
591 logmsg(
WHO,0,INFO,
"done.");
int stralloc_copys(stralloc *, char const *)
int rename(const char *, const char *)
int fifo_make(char *fn, int mode)
unsigned int fmtqfn(char *s, char *dirslash, unsigned long id, int flagsplit)
void warn_files(char *directory)
void fnmake_local(unsigned long id)
void fnmake_info(unsigned long id)
void fnmake_remote(unsigned long id)
void die_user(char *user)
void die_make(char *name)
int check_splits(char *directory, int dir_uid, int dir_gid, int dir_perm, int file_gid, int file_perm)
int check_files(char *directory, int uid, int gid, int perm)
void die_group(char *group)
void warn_unlink(unsigned long id)
int check_item(char *name, int uid, int gid, int perm, char type, int size)
void fnmake_mess(unsigned long id)
int rename_mess(char *dir, char *part, char *new_part, char *old_filename, char *new_filename)
void err_unlink(unsigned long id)
int delete_msg(unsigned long id)
void fnmake_bounce(unsigned long id)
void fnmake_dkim(unsigned long id)