venus: Remove dedebug
[openafs.git] / tests / auth / writekeyfile.c
1 /* This is a simple program which originally produced the KeyFile used
2  * by the test suite. The contents of that file shouldn't be regenerated,
3  * though, as the purpose of the tests using that file is to ensure that we
4  * can still read old KeyFiles.
5  */
6
7 #include <afsconfig.h>
8 #include <afs/param.h>
9 #include <afs/cellconfig.h>
10 #include <afs/afsutil.h>
11 #include <afs/opr.h>
12
13 #include <roken.h>
14
15 #include "common.h"
16
17 int
18 main(int argc, char **argv)
19 {
20     struct afsconf_dir *dir;
21     char *dirname;
22     char *block;
23     char *keyfile = NULL;
24     int in, out;
25     size_t len;
26
27     dirname = afstest_BuildTestConfig();
28     if (dirname == NULL) {
29         fprintf(stderr, "Unable to create tmp config dir\n");
30         exit(1);
31     }
32
33     dir = afsconf_Open(dirname);
34     if (dir == NULL) {
35         fprintf(stderr, "Unable to open configuration directory\n");
36         exit(1);
37     }
38
39     afsconf_AddKey(dir, 1, "\x01\x02\x04\x08\x10\x20\x40\x80", 1);
40     afsconf_AddKey(dir, 2, "\x04\x04\x04\x04\x04\x04\x04\x04", 1);
41     afsconf_AddKey(dir, 4, "\x19\x16\xfe\xe6\xba\x77\x2f\xfd", 1);
42
43     afsconf_Close(dir);
44
45     /* Copy out the resulting keyfile into our homedirectory */
46     opr_Verify(asprintf(&keyfile, "%s/KeyFile", dirname) > 0);
47     in = open(keyfile, O_RDONLY);
48     out = open("KeyFile", O_WRONLY | O_CREAT, 0644);
49
50     block = malloc(1024);
51     do {
52         len = read(in, block, 1024);
53         if (len > 0) {
54             if (write(out, block, len) != len) {
55                 len = -1;
56             }
57         }
58     } while (len > 0);
59
60     if (len == -1) {
61         fprintf(stderr, "I/O error whilst copying file\n");
62         exit(1);
63     }
64
65     close(in);
66     close(out);
67
68     afstest_UnlinkTestConfig(dirname);
69
70     return 0;
71 }