summaryrefslogtreecommitdiff
path: root/src/qmail-newu.c
diff options
context:
space:
mode:
authorJannis Hoffmann <jannis@fehcom.de>2024-07-03 15:52:39 +0200
committerJannis Hoffmann <jannis@fehcom.de>2024-07-03 15:52:39 +0200
commita6a7d6ce079cabdaf2fa502b2e2cf15e5428ac6f (patch)
treeb88cc7a8457658d67e0321718556ac807f6bccf3 /src/qmail-newu.c
parent00be7622c428f279872f84569f098ce16150f8a8 (diff)
format files
Diffstat (limited to 'src/qmail-newu.c')
-rw-r--r--src/qmail-newu.c72
1 files changed, 37 insertions, 35 deletions
diff --git a/src/qmail-newu.c b/src/qmail-newu.c
index d5e9baa..f2e33cd 100644
--- a/src/qmail-newu.c
+++ b/src/qmail-newu.c
@@ -1,52 +1,55 @@
-#include <unistd.h>
#include <sys/stat.h>
-#include <stdio.h> // rename
-#include "stralloc.h"
-#include "getln.h"
+#include <unistd.h>
+
+#include <stdio.h> // rename
+
#include "buffer.h"
+#include "byte.h"
+#include "case.h"
#include "cdbmake.h"
#include "exit.h"
-#include "open.h"
+#include "getln.h"
#include "logmsg.h"
-#include "case.h"
-#include "byte.h"
+#include "open.h"
+#include "stralloc.h"
+
#include "auto_qmail.h"
#define WHO "qmail-newu"
-int rename(const char *,const char *); // stdio.h
+int rename(const char *, const char *); // stdio.h
void die_chdir()
{
- logmsg(WHO,110,ERROR,"unable to chdir");
+ logmsg(WHO, 110, ERROR, "unable to chdir");
}
void die_nomem()
{
- logmsg(WHO,111,FATAL,"fatal: out of memory");
+ logmsg(WHO, 111, FATAL, "fatal: out of memory");
}
void die_opena()
{
- logmsg(WHO,112,ERROR,"unable to open users/assign");
+ logmsg(WHO, 112, ERROR, "unable to open users/assign");
}
void die_reada()
{
- logmsg(WHO,110,ERROR,"unable to read users/assign");
+ logmsg(WHO, 110, ERROR, "unable to read users/assign");
}
void die_format()
{
- logmsg(WHO,112,ERROR,"bad format in users/assign");
+ logmsg(WHO, 112, ERROR, "bad format in users/assign");
}
void die_opent()
{
- logmsg(WHO,112,ERROR,"unable to open users/assign.cdb.tmp");
+ logmsg(WHO, 112, ERROR, "unable to open users/assign.cdb.tmp");
}
void die_writet()
{
- logmsg(WHO,112,ERROR,"unable to write users/assign.cdb.tmp");
+ logmsg(WHO, 112, ERROR, "unable to write users/assign.cdb.tmp");
}
void die_rename()
{
- logmsg(WHO,112,ERROR,"unable to move users/cdb.tmp to users/assign.cdb");
+ logmsg(WHO, 112, ERROR, "unable to move users/cdb.tmp to users/assign.cdb");
}
struct cdb_make cdb;
@@ -75,39 +78,38 @@ int main()
fd = open_read("users/assign");
if (fd == -1) die_opena();
- buffer_init(&bi,read,fd,inbuf,sizeof(inbuf));
+ buffer_init(&bi, read, fd, inbuf, sizeof(inbuf));
fdtemp = open_trunc("users/assign.cdb.tmp");
if (fdtemp == -1) die_opent();
- if (cdb_make_start(&cdb,fdtemp) == -1) die_writet();
+ if (cdb_make_start(&cdb, fdtemp) == -1) die_writet();
- if (!stralloc_copys(&wildchars,"")) die_nomem();
+ if (!stralloc_copys(&wildchars, "")) die_nomem();
for (;;) {
- if (getln(&bi,&line,&match,'\n') != 0) die_reada();
+ if (getln(&bi, &line, &match, '\n') != 0) die_reada();
if (line.len && (line.s[0] == '.')) break;
if (!match) die_format();
- if (byte_chr(line.s,line.len,'\0') < line.len) die_format();
- i = byte_chr(line.s,line.len,':');
+ if (byte_chr(line.s, line.len, '\0') < line.len) die_format();
+ i = byte_chr(line.s, line.len, ':');
if (i == line.len) die_format();
if (i == 0) die_format();
- if (!stralloc_copys(&key,"!")) die_nomem();
+ if (!stralloc_copys(&key, "!")) die_nomem();
if (line.s[0] == '+') {
- if (!stralloc_catb(&key,line.s + 1,i - 1)) die_nomem();
- case_lowerb(key.s,key.len);
+ if (!stralloc_catb(&key, line.s + 1, i - 1)) die_nomem();
+ case_lowerb(key.s, key.len);
if (i >= 2)
- if (byte_chr(wildchars.s,wildchars.len,line.s[i - 1]) == wildchars.len)
- if (!stralloc_append(&wildchars,line.s + i - 1)) die_nomem();
- }
- else {
- if (!stralloc_catb(&key,line.s + 1,i - 1)) die_nomem();
+ if (byte_chr(wildchars.s, wildchars.len, line.s[i - 1]) == wildchars.len)
+ if (!stralloc_append(&wildchars, line.s + i - 1)) die_nomem();
+ } else {
+ if (!stralloc_catb(&key, line.s + 1, i - 1)) die_nomem();
if (!stralloc_0(&key)) die_nomem();
- case_lowerb(key.s,key.len);
+ case_lowerb(key.s, key.len);
}
- if (!stralloc_copyb(&data,line.s + i + 1,line.len - i - 1)) die_nomem();
+ if (!stralloc_copyb(&data, line.s + i + 1, line.len - i - 1)) die_nomem();
numcolons = 0;
for (i = 0; i < data.len; ++i)
@@ -118,15 +120,15 @@ int main()
if (numcolons < 6) die_format();
data.len = i;
- if (cdb_make_add(&cdb,key.s,key.len,data.s,data.len) == -1) die_writet();
+ if (cdb_make_add(&cdb, key.s, key.len, data.s, data.len) == -1) die_writet();
}
- if (cdb_make_add(&cdb,"",0,wildchars.s,wildchars.len) == -1) die_writet();
+ if (cdb_make_add(&cdb, "", 0, wildchars.s, wildchars.len) == -1) die_writet();
if (cdb_make_finish(&cdb) == -1) die_writet();
if (fsync(fdtemp) == -1) die_writet();
if (close(fdtemp) == -1) die_writet(); /* NFS stupidity */
- if (rename("users/assign.cdb.tmp","users/assign.cdb") == -1) die_rename();
+ if (rename("users/assign.cdb.tmp", "users/assign.cdb") == -1) die_rename();
_exit(0);
}