]>
git.saurik.com Git - apple/security.git/blob - SecurityTests/regressions/test/testenv.c
2 * Copyright (c) 2005-2006 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
31 #include <sys/types.h>
37 static int current_dir
= -1;
38 static char scratch_dir
[50];
39 static char *home_var
;
42 rmdir_recursive(const char *path
)
44 char command_buf
[256];
45 if (strlen(path
) + 10 > sizeof(command_buf
) || strchr(path
, '\''))
47 fprintf(stderr
, "# rmdir_recursive: invalid path: %s", path
);
51 sprintf(command_buf
, "rm -rf '%s'", path
);
52 return system(command_buf
);
56 tests_begin(int argc
, char * const *argv
)
59 char preferences_dir
[80];
63 /* Create scratch dir for tests to run in. */
64 sprintf(scratch_dir
, "/tmp/tst-%d", getpid());
65 sprintf(library_dir
, "%s/Library", scratch_dir
);
66 sprintf(preferences_dir
, "%s/Preferences", library_dir
);
67 return (ok_unix(mkdir(scratch_dir
, 0755), "mkdir") &&
68 ok_unix(current_dir
= open(".", O_RDONLY
), "open") &&
69 ok_unix(chdir(scratch_dir
), "chdir") &&
70 ok_unix(setenv("HOME", scratch_dir
, 1), "setenv") &&
71 /* @@@ Work around a bug that the prefs code in
72 libsecurity_keychain never creates the Library/Preferences
74 ok_unix(mkdir(library_dir
, 0755), "mkdir") &&
75 ok_unix(mkdir(preferences_dir
, 0755), "mkdir") &&
76 ok_unix(home_var
= getenv("HOME"), "getenv"));
83 /* Restore previous cwd and remove scratch dir. */
84 return (ok_unix(fchdir(current_dir
), "fchdir") &&
85 ok_unix(close(current_dir
), "close") &&
86 ok_unix(rmdir_recursive(scratch_dir
), "rmdir_recursive"));