10Sstevel@tonic-gate /*
2*8710SMark.Phalan@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
30Sstevel@tonic-gate * Use is subject to license terms.
40Sstevel@tonic-gate */
50Sstevel@tonic-gate
60Sstevel@tonic-gate /*
70Sstevel@tonic-gate * Copyright 1993 OpenVision Technologies, Inc., All Rights Reserved.
80Sstevel@tonic-gate *
90Sstevel@tonic-gate * $Id: kadm5_create.c,v 1.6 1998/10/30 02:52:37 marc Exp $
100Sstevel@tonic-gate * $Source: /cvs/krbdev/krb5/src/kadmin/dbutil/kadm5_create.c,v $
110Sstevel@tonic-gate */
120Sstevel@tonic-gate
130Sstevel@tonic-gate /*
140Sstevel@tonic-gate * Copyright (C) 1998 by the FundsXpress, INC.
150Sstevel@tonic-gate *
160Sstevel@tonic-gate * All rights reserved.
170Sstevel@tonic-gate *
180Sstevel@tonic-gate * Export of this software from the United States of America may require
190Sstevel@tonic-gate * a specific license from the United States Government. It is the
200Sstevel@tonic-gate * responsibility of any person or organization contemplating export to
210Sstevel@tonic-gate * obtain such a license before exporting.
220Sstevel@tonic-gate *
230Sstevel@tonic-gate * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
240Sstevel@tonic-gate * distribute this software and its documentation for any purpose and
250Sstevel@tonic-gate * without fee is hereby granted, provided that the above copyright
260Sstevel@tonic-gate * notice appear in all copies and that both that copyright notice and
270Sstevel@tonic-gate * this permission notice appear in supporting documentation, and that
280Sstevel@tonic-gate * the name of FundsXpress. not be used in advertising or publicity pertaining
290Sstevel@tonic-gate * to distribution of the software without specific, written prior
300Sstevel@tonic-gate * permission. FundsXpress makes no representations about the suitability of
310Sstevel@tonic-gate * this software for any purpose. It is provided "as is" without express
320Sstevel@tonic-gate * or implied warranty.
330Sstevel@tonic-gate *
340Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
350Sstevel@tonic-gate * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
360Sstevel@tonic-gate * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
370Sstevel@tonic-gate */
380Sstevel@tonic-gate
390Sstevel@tonic-gate #include "string_table.h"
400Sstevel@tonic-gate
410Sstevel@tonic-gate #include <stdio.h>
420Sstevel@tonic-gate #include <stdlib.h>
430Sstevel@tonic-gate #include <string.h>
444960Swillf #include <k5-int.h>
454960Swillf #include <kdb.h>
460Sstevel@tonic-gate #include <kadm5/admin.h>
472881Smp153739 #include <krb5/adm_proto.h>
482881Smp153739
490Sstevel@tonic-gate #include <krb5.h>
500Sstevel@tonic-gate #include <krb5/kdb.h>
514960Swillf #include "kdb5_util.h"
520Sstevel@tonic-gate #include <libintl.h>
530Sstevel@tonic-gate
540Sstevel@tonic-gate int
550Sstevel@tonic-gate add_admin_old_princ(void *handle, krb5_context context,
560Sstevel@tonic-gate char *name, char *realm, int attrs, int lifetime);
570Sstevel@tonic-gate int
580Sstevel@tonic-gate add_admin_sname_princ(void *handle, krb5_context context,
590Sstevel@tonic-gate char *sname, int attrs, int lifetime);
60*8710SMark.Phalan@Sun.COM static int
610Sstevel@tonic-gate add_admin_princ(void *handle, krb5_context context,
620Sstevel@tonic-gate krb5_principal principal, int attrs, int lifetime);
630Sstevel@tonic-gate
642881Smp153739 static int add_admin_princs(void *handle, krb5_context context, char *realm);
652881Smp153739
662881Smp153739 #define ERR 1
672881Smp153739 #define OK 0
680Sstevel@tonic-gate
690Sstevel@tonic-gate #define ADMIN_LIFETIME 60*60*3 /* 3 hours */
700Sstevel@tonic-gate #define CHANGEPW_LIFETIME 60*5 /* 5 minutes */
710Sstevel@tonic-gate
720Sstevel@tonic-gate extern char *progname;
730Sstevel@tonic-gate
740Sstevel@tonic-gate /*
750Sstevel@tonic-gate * Function: kadm5_create
760Sstevel@tonic-gate *
770Sstevel@tonic-gate * Purpose: create admin principals in KDC database
780Sstevel@tonic-gate *
790Sstevel@tonic-gate * Arguments: params (r) configuration parameters to use
800Sstevel@tonic-gate *
810Sstevel@tonic-gate * Effects: Creates KADM5_ADMIN_SERVICE and KADM5_CHANGEPW_SERVICE
820Sstevel@tonic-gate * principals in the KDC database and sets their attributes
830Sstevel@tonic-gate * appropriately.
840Sstevel@tonic-gate */
kadm5_create(kadm5_config_params * params)852881Smp153739 int kadm5_create(kadm5_config_params *params)
860Sstevel@tonic-gate {
870Sstevel@tonic-gate int retval;
880Sstevel@tonic-gate krb5_context context;
890Sstevel@tonic-gate
900Sstevel@tonic-gate kadm5_config_params lparams;
910Sstevel@tonic-gate
924960Swillf if ((retval = kadm5_init_krb5_context(&context)))
932881Smp153739 exit(ERR);
940Sstevel@tonic-gate
950Sstevel@tonic-gate (void) memset(&lparams, 0, sizeof (kadm5_config_params));
960Sstevel@tonic-gate
970Sstevel@tonic-gate /*
980Sstevel@tonic-gate * The lock file has to exist before calling kadm5_init, but
990Sstevel@tonic-gate * params->admin_lockfile may not be set yet...
1000Sstevel@tonic-gate */
1017934SMark.Phalan@Sun.COM if ((retval = kadm5_get_config_params(context, 1,
1022881Smp153739 params, &lparams))) {
1032881Smp153739 com_err(progname, retval, gettext("while looking up the Kerberos configuration"));
1042881Smp153739 return 1;
1050Sstevel@tonic-gate }
1062881Smp153739
1070Sstevel@tonic-gate retval = kadm5_create_magic_princs(&lparams, context);
1080Sstevel@tonic-gate
1090Sstevel@tonic-gate kadm5_free_config_params(context, &lparams);
1100Sstevel@tonic-gate krb5_free_context(context);
1110Sstevel@tonic-gate
1122881Smp153739 return retval;
1130Sstevel@tonic-gate }
1140Sstevel@tonic-gate
kadm5_create_magic_princs(kadm5_config_params * params,krb5_context context)1152881Smp153739 int kadm5_create_magic_princs(kadm5_config_params *params,
1162881Smp153739 krb5_context context)
1170Sstevel@tonic-gate {
1180Sstevel@tonic-gate int retval;
1190Sstevel@tonic-gate void *handle;
1200Sstevel@tonic-gate
1212881Smp153739 retval = krb5_klog_init(context, "admin_server", progname, 0);
1222881Smp153739 if (retval)
1232881Smp153739 return retval;
1240Sstevel@tonic-gate if ((retval = kadm5_init(progname, NULL, NULL, params,
1250Sstevel@tonic-gate KADM5_STRUCT_VERSION,
1260Sstevel@tonic-gate KADM5_API_VERSION_2,
1274960Swillf db5util_db_args,
1280Sstevel@tonic-gate &handle))) {
1292881Smp153739 com_err(progname, retval, gettext("while initializing the Kerberos admin interface"));
1302881Smp153739 return retval;
1310Sstevel@tonic-gate }
1322881Smp153739
1330Sstevel@tonic-gate retval = add_admin_princs(handle, context, params->realm);
1340Sstevel@tonic-gate
1350Sstevel@tonic-gate kadm5_destroy(handle);
1360Sstevel@tonic-gate
1372881Smp153739 krb5_klog_close(context);
1382881Smp153739
1392881Smp153739 return retval;
1400Sstevel@tonic-gate }
1410Sstevel@tonic-gate
1420Sstevel@tonic-gate /*
1430Sstevel@tonic-gate * Function: build_name_with_realm
1440Sstevel@tonic-gate *
1450Sstevel@tonic-gate * Purpose: concatenate a name and a realm to form a krb5 name
1460Sstevel@tonic-gate *
1470Sstevel@tonic-gate * Arguments:
1480Sstevel@tonic-gate *
1490Sstevel@tonic-gate * name (input) the name
1500Sstevel@tonic-gate * realm (input) the realm
1510Sstevel@tonic-gate *
1520Sstevel@tonic-gate * Returns:
1530Sstevel@tonic-gate *
1540Sstevel@tonic-gate * pointer to name@realm, in allocated memory, or NULL if it
1550Sstevel@tonic-gate * cannot be allocated
1560Sstevel@tonic-gate *
1570Sstevel@tonic-gate * Requires: both strings are null-terminated
1580Sstevel@tonic-gate */
build_name_with_realm(char * name,char * realm)1592881Smp153739 static char *build_name_with_realm(char *name, char *realm)
1600Sstevel@tonic-gate {
1610Sstevel@tonic-gate char *n;
1620Sstevel@tonic-gate
1630Sstevel@tonic-gate n = (char *) malloc(strlen(name) + strlen(realm) + 2);
1640Sstevel@tonic-gate sprintf(n, "%s@%s", name, realm);
1652881Smp153739 return n;
1660Sstevel@tonic-gate }
1670Sstevel@tonic-gate
1680Sstevel@tonic-gate /*
1690Sstevel@tonic-gate * Function: add_admin_princs
1700Sstevel@tonic-gate *
1710Sstevel@tonic-gate * Purpose: create admin principals
1720Sstevel@tonic-gate *
1730Sstevel@tonic-gate * Arguments:
1740Sstevel@tonic-gate *
1750Sstevel@tonic-gate * rseed (input) random seed
1760Sstevel@tonic-gate * realm (input) realm, or NULL for default realm
1770Sstevel@tonic-gate * <return value> (output) status, 0 for success, 1 for serious error
1780Sstevel@tonic-gate *
1790Sstevel@tonic-gate * Requires:
1800Sstevel@tonic-gate *
1810Sstevel@tonic-gate * Effects:
1820Sstevel@tonic-gate *
1830Sstevel@tonic-gate * add_admin_princs creates KADM5_ADMIN_SERVICE,
1840Sstevel@tonic-gate * KADM5_CHANGEPW_SERVICE. If any of these exist a message is
1850Sstevel@tonic-gate * printed. If any of these existing principal do not have the proper
1860Sstevel@tonic-gate * attributes, a warning message is printed.
1870Sstevel@tonic-gate */
add_admin_princs(void * handle,krb5_context context,char * realm)1882881Smp153739 static int add_admin_princs(void *handle, krb5_context context, char *realm)
1890Sstevel@tonic-gate {
1900Sstevel@tonic-gate krb5_error_code ret = 0;
1911508Smp153739
1921508Smp153739 /*
1931508Smp153739 * Solaris Kerberos:
1941508Smp153739 * The kadmin/admin principal is unused on Solaris. This principal is used
1951508Smp153739 * in AUTH_GSSAPI but Solaris doesn't support AUTH_GSSAPI. RPCSEC_GSS can only
1961508Smp153739 * be used with host-based principals.
1971508Smp153739 *
1981508Smp153739 */
1991508Smp153739
2001508Smp153739 #if 0
2011508Smp153739 if ((ret = add_admin_old_princ(handle, context,
2021508Smp153739 KADM5_ADMIN_SERVICE, realm,
2031508Smp153739 KRB5_KDB_DISALLOW_TGT_BASED,
2041508Smp153739 ADMIN_LIFETIME)))
2051508Smp153739 goto clean_and_exit;
2061508Smp153739 #endif
2070Sstevel@tonic-gate
2080Sstevel@tonic-gate if ((ret = add_admin_old_princ(handle, context,
2090Sstevel@tonic-gate KADM5_CHANGEPW_SERVICE, realm,
2100Sstevel@tonic-gate KRB5_KDB_DISALLOW_TGT_BASED |
2110Sstevel@tonic-gate KRB5_KDB_PWCHANGE_SERVICE,
2120Sstevel@tonic-gate CHANGEPW_LIFETIME)))
2130Sstevel@tonic-gate goto clean_and_exit;
2140Sstevel@tonic-gate
2150Sstevel@tonic-gate if ((ret = add_admin_sname_princ(handle, context,
2160Sstevel@tonic-gate KADM5_ADMIN_HOST_SERVICE,
2170Sstevel@tonic-gate KRB5_KDB_DISALLOW_TGT_BASED,
2180Sstevel@tonic-gate ADMIN_LIFETIME)))
2190Sstevel@tonic-gate goto clean_and_exit;
2200Sstevel@tonic-gate
2210Sstevel@tonic-gate if ((ret = add_admin_sname_princ(handle, context,
2220Sstevel@tonic-gate KADM5_CHANGEPW_HOST_SERVICE,
2230Sstevel@tonic-gate KRB5_KDB_DISALLOW_TGT_BASED |
2240Sstevel@tonic-gate KRB5_KDB_PWCHANGE_SERVICE,
2250Sstevel@tonic-gate ADMIN_LIFETIME)))
2260Sstevel@tonic-gate goto clean_and_exit;
2270Sstevel@tonic-gate
2281508Smp153739 if ((ret = add_admin_sname_princ(handle, context,
2291508Smp153739 KADM5_KIPROP_HOST_SERVICE,
2301508Smp153739 KRB5_KDB_DISALLOW_TGT_BASED,
2311508Smp153739 ADMIN_LIFETIME)))
2321508Smp153739 goto clean_and_exit;
2331508Smp153739
2340Sstevel@tonic-gate clean_and_exit:
2350Sstevel@tonic-gate
2362881Smp153739 return ret;
2370Sstevel@tonic-gate }
2380Sstevel@tonic-gate
2390Sstevel@tonic-gate /*
2400Sstevel@tonic-gate * Function: add_admin_princ
2410Sstevel@tonic-gate *
2420Sstevel@tonic-gate * Arguments:
2430Sstevel@tonic-gate *
2440Sstevel@tonic-gate * creator (r) principal to use as "mod_by"
2450Sstevel@tonic-gate * rseed (r) seed for random key generator
2460Sstevel@tonic-gate * principal (r) kerberos principal to add
2470Sstevel@tonic-gate * attrs (r) principal's attributes
2480Sstevel@tonic-gate * lifetime (r) principal's max life, or 0
2490Sstevel@tonic-gate * not_unique (r) error message for multiple entries, never used
2500Sstevel@tonic-gate * exists (r) warning message for principal exists
2510Sstevel@tonic-gate * wrong_attrs (r) warning message for wrong attributes
2520Sstevel@tonic-gate *
2530Sstevel@tonic-gate * Returns:
2540Sstevel@tonic-gate *
2552881Smp153739 * OK on success
2562881Smp153739 * ERR on serious errors
2570Sstevel@tonic-gate *
2580Sstevel@tonic-gate * Effects:
2590Sstevel@tonic-gate *
2600Sstevel@tonic-gate * If the principal is not unique, not_unique is printed (but this
2610Sstevel@tonic-gate * never happens). If the principal exists, then exists is printed
2620Sstevel@tonic-gate * and if the principals attributes != attrs, wrong_attrs is printed.
2630Sstevel@tonic-gate * Otherwise, the principal is created with mod_by creator and
2640Sstevel@tonic-gate * attributes attrs and max life of lifetime (if not zero).
2650Sstevel@tonic-gate */
2660Sstevel@tonic-gate
add_admin_princ(void * handle,krb5_context context,krb5_principal principal,int attrs,int lifetime)267*8710SMark.Phalan@Sun.COM static int add_admin_princ(void *handle, krb5_context context,
2680Sstevel@tonic-gate krb5_principal principal, int attrs, int lifetime)
2690Sstevel@tonic-gate {
2700Sstevel@tonic-gate char *fullname;
2710Sstevel@tonic-gate krb5_error_code ret;
2720Sstevel@tonic-gate kadm5_principal_ent_rec ent;
2730Sstevel@tonic-gate
2740Sstevel@tonic-gate memset(&ent, 0, sizeof(ent));
2750Sstevel@tonic-gate
2760Sstevel@tonic-gate if (krb5_unparse_name(context, principal, &fullname))
2772881Smp153739 return ERR;
2780Sstevel@tonic-gate
2790Sstevel@tonic-gate ent.principal = principal;
2800Sstevel@tonic-gate ent.max_life = lifetime;
2810Sstevel@tonic-gate ent.attributes = attrs | KRB5_KDB_DISALLOW_ALL_TIX;
2820Sstevel@tonic-gate
2832881Smp153739 ret = kadm5_create_principal(handle, &ent,
2842881Smp153739 (KADM5_PRINCIPAL | KADM5_MAX_LIFE |
2852881Smp153739 KADM5_ATTRIBUTES),
2862881Smp153739 "to-be-random");
2872881Smp153739 if (ret) {
2880Sstevel@tonic-gate if (ret != KADM5_DUP) {
2897934SMark.Phalan@Sun.COM com_err(progname, ret,
2900Sstevel@tonic-gate gettext(str_PUT_PRINC), fullname);
2910Sstevel@tonic-gate krb5_free_principal(context, ent.principal);
2920Sstevel@tonic-gate free(fullname);
2932881Smp153739 return ERR;
2940Sstevel@tonic-gate }
2950Sstevel@tonic-gate } else {
2960Sstevel@tonic-gate /* only randomize key if we created the principal */
297*8710SMark.Phalan@Sun.COM
298*8710SMark.Phalan@Sun.COM /*
299*8710SMark.Phalan@Sun.COM * Solaris Kerberos:
300*8710SMark.Phalan@Sun.COM * Create kadmind principals with keys for all supported encryption types.
301*8710SMark.Phalan@Sun.COM * Follows a similar pattern to add_principal() in keytab.c.
302*8710SMark.Phalan@Sun.COM */
303*8710SMark.Phalan@Sun.COM krb5_enctype *tmpenc, *enctype = NULL;
304*8710SMark.Phalan@Sun.COM krb5_key_salt_tuple *keysalt;
305*8710SMark.Phalan@Sun.COM int num_ks, i;
306*8710SMark.Phalan@Sun.COM krb5_int32 normalsalttype;
307*8710SMark.Phalan@Sun.COM
308*8710SMark.Phalan@Sun.COM ret = krb5_get_permitted_enctypes(context, &enctype);
309*8710SMark.Phalan@Sun.COM if (ret || *enctype == NULL) {
310*8710SMark.Phalan@Sun.COM com_err(progname, ret,
311*8710SMark.Phalan@Sun.COM gettext("while getting list of permitted encryption types"));
312*8710SMark.Phalan@Sun.COM krb5_free_principal(context, ent.principal);
313*8710SMark.Phalan@Sun.COM free(fullname);
314*8710SMark.Phalan@Sun.COM return ERR;
315*8710SMark.Phalan@Sun.COM }
316*8710SMark.Phalan@Sun.COM
317*8710SMark.Phalan@Sun.COM /* Count the number of enc types */
318*8710SMark.Phalan@Sun.COM for (tmpenc = enctype, num_ks = 0; *tmpenc; tmpenc++)
319*8710SMark.Phalan@Sun.COM num_ks++;
320*8710SMark.Phalan@Sun.COM
321*8710SMark.Phalan@Sun.COM keysalt = malloc (sizeof (krb5_key_salt_tuple) * num_ks);
322*8710SMark.Phalan@Sun.COM if (keysalt == NULL) {
323*8710SMark.Phalan@Sun.COM com_err(progname, ENOMEM,
324*8710SMark.Phalan@Sun.COM gettext("while generating list of key salt tuples"));
325*8710SMark.Phalan@Sun.COM krb5_free_ktypes(context, enctype);
326*8710SMark.Phalan@Sun.COM krb5_free_principal(context, ent.principal);
327*8710SMark.Phalan@Sun.COM free(fullname);
328*8710SMark.Phalan@Sun.COM return ERR;
329*8710SMark.Phalan@Sun.COM }
330*8710SMark.Phalan@Sun.COM
331*8710SMark.Phalan@Sun.COM ret = krb5_string_to_salttype("normal", &normalsalttype);
332*8710SMark.Phalan@Sun.COM if (ret) {
333*8710SMark.Phalan@Sun.COM com_err(progname, ret,
334*8710SMark.Phalan@Sun.COM gettext("while converting \"normal\" to a salttype"));
335*8710SMark.Phalan@Sun.COM free(keysalt);
336*8710SMark.Phalan@Sun.COM krb5_free_ktypes(context, enctype);
337*8710SMark.Phalan@Sun.COM krb5_free_principal(context, ent.principal);
338*8710SMark.Phalan@Sun.COM free(fullname);
339*8710SMark.Phalan@Sun.COM return ERR;
340*8710SMark.Phalan@Sun.COM }
341*8710SMark.Phalan@Sun.COM
342*8710SMark.Phalan@Sun.COM /* Only create keys with "normal" salttype */
343*8710SMark.Phalan@Sun.COM for (i = 0; i < num_ks; i++) {
344*8710SMark.Phalan@Sun.COM keysalt[i].ks_enctype = enctype[i];
345*8710SMark.Phalan@Sun.COM keysalt[i].ks_salttype = normalsalttype;
346*8710SMark.Phalan@Sun.COM }
347*8710SMark.Phalan@Sun.COM
348*8710SMark.Phalan@Sun.COM ret = kadm5_randkey_principal_3(handle, ent.principal, FALSE, num_ks,
349*8710SMark.Phalan@Sun.COM keysalt, NULL, NULL);
350*8710SMark.Phalan@Sun.COM free(keysalt);
351*8710SMark.Phalan@Sun.COM krb5_free_ktypes (context, enctype);
352*8710SMark.Phalan@Sun.COM
353*8710SMark.Phalan@Sun.COM
3547934SMark.Phalan@Sun.COM if (ret) {
3557934SMark.Phalan@Sun.COM com_err(progname, ret,
3560Sstevel@tonic-gate gettext(str_RANDOM_KEY), fullname);
3572881Smp153739 krb5_free_principal(context, ent.principal);
3582881Smp153739 free(fullname);
3592881Smp153739 return ERR;
3602881Smp153739 }
3612881Smp153739
3622881Smp153739 ent.attributes = attrs;
3632881Smp153739 ret = kadm5_modify_principal(handle, &ent, KADM5_ATTRIBUTES);
3642881Smp153739 if (ret) {
3652881Smp153739 com_err(progname, ret,
3662881Smp153739 gettext(str_PUT_PRINC), fullname);
3672881Smp153739 krb5_free_principal(context, ent.principal);
3682881Smp153739 free(fullname);
3692881Smp153739 return ERR;
3702881Smp153739 }
3712881Smp153739 }
3720Sstevel@tonic-gate
3732881Smp153739 krb5_free_principal(context, ent.principal);
3742881Smp153739 free(fullname);
3750Sstevel@tonic-gate
3762881Smp153739 return OK;
3770Sstevel@tonic-gate }
3780Sstevel@tonic-gate
3790Sstevel@tonic-gate int
add_admin_old_princ(void * handle,krb5_context context,char * name,char * realm,int attrs,int lifetime)3800Sstevel@tonic-gate add_admin_old_princ(void *handle, krb5_context context,
3810Sstevel@tonic-gate char *name, char *realm, int attrs, int lifetime)
3820Sstevel@tonic-gate {
3830Sstevel@tonic-gate char *fullname;
3840Sstevel@tonic-gate krb5_error_code ret;
3850Sstevel@tonic-gate krb5_principal principal;
3860Sstevel@tonic-gate
3870Sstevel@tonic-gate fullname = build_name_with_realm(name, realm);
3880Sstevel@tonic-gate if (ret = krb5_parse_name(context, fullname, &principal)) {
3890Sstevel@tonic-gate com_err(progname, ret, gettext(str_PARSE_NAME));
3902881Smp153739 return (ERR);
3910Sstevel@tonic-gate }
3920Sstevel@tonic-gate
3930Sstevel@tonic-gate return (add_admin_princ(handle, context, principal, attrs, lifetime));
3940Sstevel@tonic-gate }
3950Sstevel@tonic-gate
3960Sstevel@tonic-gate int
add_admin_sname_princ(void * handle,krb5_context context,char * sname,int attrs,int lifetime)3970Sstevel@tonic-gate add_admin_sname_princ(void *handle, krb5_context context,
3980Sstevel@tonic-gate char *sname, int attrs, int lifetime)
3990Sstevel@tonic-gate {
4000Sstevel@tonic-gate krb5_error_code ret;
4010Sstevel@tonic-gate krb5_principal principal;
4020Sstevel@tonic-gate
4030Sstevel@tonic-gate if (ret = krb5_sname_to_principal(context, NULL, sname,
4040Sstevel@tonic-gate KRB5_NT_SRV_HST, &principal)) {
4050Sstevel@tonic-gate com_err(progname, ret,
4060Sstevel@tonic-gate gettext("Could not get host based "
4070Sstevel@tonic-gate "service name for %s principal\n"), sname);
4082881Smp153739 return (ERR);
4090Sstevel@tonic-gate }
4100Sstevel@tonic-gate return (add_admin_princ(handle, context, principal, attrs, lifetime));
4110Sstevel@tonic-gate }
4120Sstevel@tonic-gate
4130Sstevel@tonic-gate
4140Sstevel@tonic-gate
415