xref: /plan9-contrib/sys/src/cmd/auth/lib/wrbio.c (revision 219b2ee8daee37f4aad58d63f21287faa8e4ffdc)
1 #include <u.h>
2 #include <libc.h>
3 #include <bio.h>
4 #include <ctype.h>
5 #include <auth.h>
6 #include "authsrv.h"
7 
8 void
9 wrbio(char *file, Acctbio *a)
10 {
11 	char uinfo[512];
12 	char sponsors[512];
13 	int i, fd, n;
14 
15 	fd = open(file, OWRITE);
16 	if(fd < 0)
17 		error("can't open %s", file);
18 	if(seek(fd, 0, 2) < 0)
19 		error("can't seek %s", file);
20 
21 	if(a->name == 0)
22 		a->name = strdup(a->user);
23 	if(a->dept == 0)
24 		a->dept = strdup("1127?");
25 	if(a->email[0] == 0)
26 		a->email[0] = strdup(a->user);
27 
28 	snprint(uinfo, sizeof(uinfo), "%s %s <%s>", a->name, a->dept, a->email[0]);
29 	n = 0;
30 	sponsors[0] = 0;
31 	for(i = 1; i < Nemail; i++){
32 		if(a->email[i] == 0)
33 			break;
34 		n += snprint(sponsors+n, sizeof(sponsors)-n, "<%s>", a->email[i]);
35 	}
36 
37 	fprint(fd, "%s		%s		%s\n", a->user, uinfo, sponsors);
38 	close(fd);
39 }
40