1 #include <u.h> 2 #include <libc.h> 3 #include <auth.h> 4 #include <bio.h> 5 #include "imap4d.h" 6 7 void 8 debuglog(char *fmt, ...) 9 { 10 va_list arg; 11 static int logfd; 12 13 if(debug == 0) 14 return; 15 if(logfd == 0) 16 logfd = open("/sys/log/imap4d", OWRITE); 17 if(logfd > 0){ 18 va_start(arg, fmt); 19 fprint(logfd, "%s: ", username); 20 vfprint(logfd, fmt, arg); 21 va_end(arg); 22 } 23 } 24 25 void 26 boxVerify(Box *box) 27 { 28 Msg *m; 29 ulong seq, uid, recent; 30 31 if(box == nil) 32 return; 33 recent = 0; 34 seq = 0; 35 uid = 0; 36 for(m = box->msgs; m != nil; m = m->next){ 37 if(m->seq == 0) 38 fprint(2, "m->seq == 0: m->seq=%lud\n", m->seq); 39 else if(m->seq <= seq) 40 fprint(2, "m->seq=%lud out of order: last=%lud\n", m->seq, seq); 41 seq = m->seq; 42 43 if(m->uid == 0) 44 fprint(2, "m->uid == 0: m->seq=%lud\n", m->seq); 45 else if(m->uid <= uid) 46 fprint(2, "m->uid=%lud out of order: last=%lud\n", m->uid, uid); 47 uid = m->uid; 48 49 if(m->flags & MRecent) 50 recent++; 51 } 52 if(seq != box->max) 53 fprint(2, "max=%lud, should be %lud\n", box->max, seq); 54 if(uid >= box->uidnext) 55 fprint(2, "uidnext=%lud, maxuid=%lud\n", box->uidnext, uid); 56 if(recent != box->recent) 57 fprint(2, "recent=%lud, should be %lud\n", box->recent, recent); 58 } 59 60 void 61 openfiles(void) 62 { 63 Dir *d; 64 int i; 65 66 for(i = 0; i < 20; i++){ 67 d = dirfstat(i); 68 if(d != nil){ 69 fprint(2, "fd[%d]='%s' type=%c dev=%d user='%s group='%s'\n", i, d->name, d->type, d->dev, d->uid, d->gid); 70 free(d); 71 } 72 } 73 } 74 75 void 76 ls(char *file) 77 { 78 Dir *d; 79 int fd, i, nd; 80 81 fd = open(file, OREAD); 82 if(fd < 0) 83 return; 84 85 /* 86 * read box to find all messages 87 * each one has a directory, and is in numerical order 88 */ 89 d = dirfstat(fd); 90 if(d == nil){ 91 close(fd); 92 return; 93 } 94 if(!(d->mode & DMDIR)){ 95 fprint(2, "file %s\n", file); 96 free(d); 97 close(fd); 98 return; 99 } 100 free(d); 101 while((nd = dirread(fd, &d)) > 0){ 102 for(i = 0; i < nd; i++){ 103 fprint(2, "%s/%s %c\n", file, d[i].name, "-d"[(d[i].mode & DMDIR) == DMDIR]); 104 } 105 free(d); 106 } 107 close(fd); 108 } 109