4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
35 struct profile_string_list
{
42 * From prof_get.c as the following four functions are private in mech_krb5.
45 * Initialize the string list abstraction.
48 init_list(struct profile_string_list
*list
)
52 list
->list
= malloc(list
->max
* sizeof (char *));
53 if (list
->list
== NULL
)
60 * If re_list is non-NULL then pass the list header to the caller else free
61 * the previously allocated list.
64 end_list(struct profile_string_list
*list
, char ***ret_list
)
71 *ret_list
= list
->list
;
74 profile_free_list(list
->list
);
75 list
->num
= list
->max
= 0;
80 * Add a string to the list.
83 add_to_list(struct profile_string_list
*list
, const char *str
)
85 char *newstr
, **newlist
;
88 if (list
->num
+ 1 >= list
->max
) {
89 newmax
= list
->max
+ 10;
90 newlist
= realloc(list
->list
, newmax
* sizeof (char *));
100 list
->list
[list
->num
++] = newstr
;
101 list
->list
[list
->num
] = NULL
;
108 (void) fprintf(stderr
, gettext("kconf -f <file> -r <realm> "
109 "-k <kdc[,kdc]> -m <master_kdc>\n -p <kpasswd_protocol> "
116 main(int argc
, char **argv
)
120 char c
, *realm
, *kdcs
, *master
, *domain
, *token
, *lasts
;
121 char *file
, **ret_values
= NULL
;
122 boolean_t set_change
= FALSE
;
123 struct profile_string_list values
;
125 (void) setlocale(LC_ALL
, "");
127 #if !defined(TEXT_DOMAIN)
128 #define TEXT_DOMAIN "SYS_TEST"
129 #endif /* TEXT_DOMAIN */
131 (void) textdomain(TEXT_DOMAIN
);
134 * kconf -f <file> -r <realm> -k <kdc[,kdc]> -m <master_kdc>
135 * -p <kpasswd_protocol> -d <domain>
137 while ((c
= getopt(argc
, argv
, "f:r:k:a:s:p:d:m:")) != -1) {
152 if (strcmp(optarg
, "SET_CHANGE") == 0)
164 code
= __profile_init(file
, &profile
);
166 fprintf(stderr
, gettext("Wasn't able to initialize profile\n"));
170 if (code
= init_list(&values
)) {
171 fprintf(stderr
, gettext("Can not initialize list %d\n"), code
);
174 token
= strtok_r(kdcs
, ",", &lasts
);
177 code
= add_to_list(&values
, token
);
179 fprintf(stderr
, gettext("Can not add to list "
184 fprintf(stderr
, gettext("Couldn't parse kdc list %d\n"),
188 } while ((token
= strtok_r(NULL
, ",", &lasts
)) != NULL
);
189 end_list(&values
, &ret_values
);
191 code
= __profile_add_realm(profile
, realm
, master
, ret_values
,
194 fprintf(stderr
, gettext("Wasn't able to add realm "
199 code
= __profile_add_domain_mapping(profile
, domain
, realm
);
201 fprintf(stderr
, gettext("Wasn't able to add domain mapping\n"));
206 if (ret_values
!= NULL
)
207 profile_free_list(ret_values
);
210 * Release profile, which will subsequently flush new profile to file.
211 * If this fails then at least free profile memory.
213 if ((code
= __profile_release(profile
)) != NULL
)
214 __profile_abandon(profile
);