-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnames.c
110 lines (97 loc) · 3.21 KB
/
names.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#define _LARGEFILE64_SOURCE
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <ldns/ldns.h>
#include "uthash.h"
#include "proto.h"
#include "utilities.h"
#pragma GCC optimize ("O0")
const char* baseviewkeys[] = { "namerevision", NULL};
const char* inputviewkeys[] = { "nameupcoming", "namehierarchy", NULL};
const char* prepareviewkeys[] = { "namerevision", "namenoserial", "namenewserial", NULL};
const char* signviewkeys[] = { "nameready", "expiry", "denialname", NULL};
const char* outputviewkeys[] = { "validnow", NULL};
int
names_docreate(struct names_struct** zoneptr, const char* apex, const char* persist, const char* input)
{
struct names_struct* zone = *zoneptr;
int status = 0;
if(!*zoneptr) {
zone = malloc(sizeof(struct names_struct));
zone->basefd = open(".", O_PATH, 07777);
zone->apex = strdup(apex);
zone->source = NULL;
zone->persist = strdup(persist);
}
if (input) {
zone->source = strdup(input);
}
if(!*zoneptr) {
zone->baseview = names_viewcreate(NULL, " base ", baseviewkeys);
status = names_viewrestore(zone->baseview, zone->apex, zone->basefd, persist);
zone->inputview = names_viewcreate(zone->baseview, " input ", inputviewkeys);
zone->prepareview = names_viewcreate(zone->baseview, " prepare ", prepareviewkeys);
zone->signview = names_viewcreate(zone->baseview, " sign ", signviewkeys);
zone->outputview = names_viewcreate(zone->baseview, " output ", outputviewkeys);
}
if(status && zone->source != NULL) {
if(zone->apex != NULL) {
free(zone->apex);
zone->apex = NULL;
}
readzone(zone->inputview, PLAIN, zone->source, &zone->apex, NULL);
if (names_viewcommit(zone->inputview)) {
return -1;
}
if(zone->apex == NULL) {
zone->apex = strdup(apex);
}
}
*zoneptr = zone;
return 0;
}
void
names_dodestroy(struct names_struct* names)
{
names_viewreset(names->baseview);
names_viewpersist(names->baseview, names->basefd, names->persist);
names_viewdestroy(names->inputview);
names_viewdestroy(names->prepareview);
names_viewdestroy(names->signview);
names_viewdestroy(names->outputview);
names_viewdestroy(names->baseview);
close(names->basefd);
}
void
names_docycle(struct names_struct* names, int* serial, const char* filename)
{
if(serial) {
names_viewreset(names->prepareview);
prepare(names->prepareview, *serial);
if (names_viewcommit(names->prepareview)) {
abort(); // FIXME
}
names_viewreset(names->signview);
sign(names->signview, names->apex);
if (names_viewcommit(names->signview)) {
abort(); // FIXME
}
}
if(filename) {
names_viewreset(names->outputview);
writezone(names->outputview, filename, names->apex, NULL);
}
}
void
names_dopersist(struct names_struct* names)
{
names_viewreset(names->baseview);
names_viewpersist(names->baseview, names->basefd, names->persist);
}