xref: /illumos-gate/usr/src/test/libmlrpc-tests/tests/netrlogon/krb5_pac_tests/krb5_pac_decode.c (revision 0554d5ecd11d9644cbb915be31b5a0b7abb40122)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2020 Tintri by DDN, Inc. All rights reserved.
14  */
15 
16 /*
17  * Test the ability to decode PAC data from AD Kerberos tickets.
18  */
19 
20 #include <smbsrv/libmlsvc.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 
24 #include <util_common.h>
25 
26 enum KPAC_RC {
27 	KPC_SUCCESS = 0,
28 	KPC_ARGC,
29 	KPC_PAC_FILE,
30 	KPC_TOKEN_ALLOC,
31 	KPC_DECODE_PAC
32 };
33 
34 int
35 main(int argc, char *argv[])
36 {
37 	char *pac_file;
38 	uchar_t *pac_buf;
39 	size_t buflen;
40 	smb_token_t *token;
41 	uint32_t status;
42 
43 	if (argc < 2) {
44 		fprintf(stderr, "usage: %s <Binary PAC File>\n", argv[0]);
45 		return (-KPC_ARGC);
46 	}
47 
48 	pac_file = argv[1];
49 
50 	pac_buf = read_buf_from_file(pac_file, &buflen);
51 
52 	if (pac_buf == NULL) {
53 		fprintf(stderr, "failed to read pac data\n");
54 		return (-KPC_PAC_FILE);
55 	}
56 
57 	token = calloc(1, sizeof (*token));
58 	if (token == NULL) {
59 		fprintf(stderr, "failed to allocate token\n");
60 		return (-KPC_TOKEN_ALLOC);
61 	}
62 
63 	/* Initialize only those bits on which smb_decode_krb5_pac depends */
64 	(void) smb_lgrp_start();
65 
66 	status = smb_decode_krb5_pac(token, (char *)pac_buf, buflen);
67 	if (status != 0) {
68 		fprintf(stderr, "smb_decode_krb5_pac failed with 0x%x\n",
69 		    status);
70 		return (-KPC_DECODE_PAC);
71 	}
72 
73 	smb_token_log(token);
74 
75 	return (KPC_SUCCESS);
76 }
77