/ gsstoolwrapper / main.m
main.m
 1  /*
 2  * Copyright (c) 2006 Kungliga Tekniska Högskolan
 3  * (Royal Institute of Technology, Stockholm, Sweden).
 4  * All rights reserved.
 5  *
 6  * Portions Copyright (c) 2020 Apple Inc. All rights reserved.
 7  *
 8  * Redistribution and use in source and binary forms, with or without
 9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * 3. Neither the name of KTH nor the names of its contributors may be
20  *    used to endorse or promote products derived from this software without
21  *    specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY KTH AND ITS CONTRIBUTORS ``AS IS'' AND ANY
24  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KTH OR ITS CONTRIBUTORS BE
27  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
32  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
33  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35  
36  #import <Foundation/Foundation.h>
37  
38  
39  int main(int argc, const char * argv[]) {
40      @autoreleasepool {
41  
42  	if (argc != 2)
43  	{
44  	    printf("gsstoolwrapper [audit token file name] \n");
45  	    printf("This program is a quick way to get a \"real\" audit token to pass to gsstool for testing. The pid from it has to be alive for it to be valid for gss use. The intended use is to run the app and then bacground it.  It will stay alive so that gsstool can use the audit token to confirm that delegation is working correctly based on the current configuration.  If the wrapper tool is assigned per app vpn, then gss tool should be able to confirm delegation is working correctly.\n");
46  	}
47  	
48  	NSString *tempFilePath = [NSString stringWithCString:argv[1] encoding:NSUTF8StringEncoding];
49  	
50  	audit_token_t self_token;
51  	mach_msg_type_number_t token_size = TASK_AUDIT_TOKEN_COUNT;
52  	kern_return_t kr = task_info(mach_task_self(), TASK_AUDIT_TOKEN,
53  	(integer_t *)&self_token, &token_size);
54  	if (kr != KERN_SUCCESS) {
55  	    printf("Failed to get own token");
56  	    return 1;
57  	}
58  	
59  	NSData *tokenData = [NSData dataWithBytesNoCopy:&self_token length:sizeof(audit_token_t)];
60  	
61  	if (![tokenData writeToFile:tempFilePath atomically:YES]) {
62  	    printf("Failed to write out token");
63  	    return 1;
64  	}
65  
66  	[[NSRunLoop currentRunLoop] run];
67  
68      }
69      return 0;
70  }