2 * Copyright (c) 2010 Your File System Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 * Common functions for building a configuration directory
29 #include <afsconfig.h>
30 #include <afs/param.h>
33 #include <afs/cellconfig.h>
34 #include <afs/afsutil.h>
36 #include <hcrypto/des.h>
38 #include <tests/tap/basic.h>
42 openConfigFile(char *dirname
, char *filename
) {
46 if (asprintf(&path
, "%s/%s", dirname
, filename
) == -1)
49 file
= fopen(path
, "w");
55 unlinkConfigFile(char *dirname
, char *filename
) {
58 if (asprintf(&path
, "%s/%s", dirname
, filename
) != -1) {
65 * Build a test configuration directory, containing a CellServDB and ThisCell
66 * file for the "example.org" cell
69 * The path to the configuration directory. This should be freed by the caller
75 afstest_BuildTestConfig(void) {
82 if (asprintf(&dir
, "%s/afs_XXXXXX", gettmpdir()) == -1)
85 if (mkdtemp(dir
) == NULL
)
88 /* Work out which IP address to use in our CellServDB. We figure this out
89 * according to the IP address which ubik is most likely to pick for one of
92 gethostname(hostname
, sizeof(hostname
));
93 host
= gethostbyname(hostname
);
97 memcpy(&iaddr
, host
->h_addr
, 4);
99 file
= openConfigFile(dir
, "CellServDB");
100 fprintf(file
, ">example.org # An example cell\n");
101 fprintf(file
, "%s #test.example.org\n", inet_ntoa(iaddr
));
104 /* Create a ThisCell file */
105 file
= openConfigFile(dir
, "ThisCell");
106 fprintf(file
, "example.org");
118 * Delete at test configuration directory
122 afstest_UnlinkTestConfig(char *dir
)
127 /* Sanity check, only zap directories that look like ours */
128 if (!strstr(dir
, "afs_"))
130 if (getenv("MAKECHECK") != NULL
) {
134 while ((de
= readdir(dirp
)))
135 unlinkConfigFile(dir
, de
->d_name
);
141 afstest_AddDESKeyFile(struct afsconf_dir
*dir
)
143 char keymaterial
[]="\x19\x17\xff\xe6\xbb\x77\x2e\xfc";
145 /* Make sure that it is actually a valid key */
146 DES_set_odd_parity((DES_cblock
*)keymaterial
);
148 return afsconf_AddKey(dir
, 1, keymaterial
, 1);