xref: /illumos-gate/usr/src/lib/gss_mechs/mech_krb5/krb5/krb/set_realm.c (revision ea100d09ff60b44d2fb4efa29388f1dfd6c916fd)
1*ea100d09Sgtb #pragma ident	"%Z%%M%	%I%	%E% SMI"
2*ea100d09Sgtb /*
3*ea100d09Sgtb  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
4*ea100d09Sgtb  * Use is subject to license terms.
5*ea100d09Sgtb  */
6*ea100d09Sgtb /*
7*ea100d09Sgtb  * lib/krb5/krb/set_realm.c
8*ea100d09Sgtb  *
9*ea100d09Sgtb  * Copyright 1997 by the Massachusetts Institute of Technology.
10*ea100d09Sgtb  * All Rights Reserved.
11*ea100d09Sgtb  *
12*ea100d09Sgtb  * Export of this software from the United States of America may
13*ea100d09Sgtb  *   require a specific license from the United States Government.
14*ea100d09Sgtb  *   It is the responsibility of any person or organization contemplating
15*ea100d09Sgtb  *   export to obtain such a license before exporting.
16*ea100d09Sgtb  *
17*ea100d09Sgtb  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
18*ea100d09Sgtb  * distribute this software and its documentation for any purpose and
19*ea100d09Sgtb  * without fee is hereby granted, provided that the above copyright
20*ea100d09Sgtb  * notice appear in all copies and that both that copyright notice and
21*ea100d09Sgtb  * this permission notice appear in supporting documentation, and that
22*ea100d09Sgtb  * the name of M.I.T. not be used in advertising or publicity pertaining
23*ea100d09Sgtb  * to distribution of the software without specific, written prior
24*ea100d09Sgtb  * permission.  Furthermore if you modify this software you must label
25*ea100d09Sgtb  * your software as modified software and not distribute it in such a
26*ea100d09Sgtb  * fashion that it might be confused with the original M.I.T. software.
27*ea100d09Sgtb  * M.I.T. makes no representations about the suitability of
28*ea100d09Sgtb  * this software for any purpose.  It is provided "as is" without express
29*ea100d09Sgtb  * or implied warranty.
30*ea100d09Sgtb  */
31*ea100d09Sgtb 
32*ea100d09Sgtb #include "k5-int.h"
33*ea100d09Sgtb 
34*ea100d09Sgtb krb5_error_code KRB5_CALLCONV
35*ea100d09Sgtb krb5_set_principal_realm(krb5_context context, krb5_principal principal, const char *realm)
36*ea100d09Sgtb {
37*ea100d09Sgtb 	size_t	length;
38*ea100d09Sgtb 	char	*newrealm;
39*ea100d09Sgtb 
40*ea100d09Sgtb 	if (!realm || !*realm)
41*ea100d09Sgtb 		return EINVAL;
42*ea100d09Sgtb 
43*ea100d09Sgtb 	length = strlen(realm);
44*ea100d09Sgtb 	newrealm = malloc(length+1); /* Include room for the null */
45*ea100d09Sgtb 	if (!newrealm)
46*ea100d09Sgtb 		return ENOMEM;
47*ea100d09Sgtb 	strcpy(newrealm, realm);
48*ea100d09Sgtb 
49*ea100d09Sgtb 	(void) krb5_xfree(krb5_princ_realm(context,principal)->data);
50*ea100d09Sgtb 
51*ea100d09Sgtb 	krb5_princ_realm(context, principal)->length = length;
52*ea100d09Sgtb 	krb5_princ_realm(context, principal)->data = newrealm;
53*ea100d09Sgtb 
54*ea100d09Sgtb 	return 0;
55*ea100d09Sgtb }
56*ea100d09Sgtb 
57*ea100d09Sgtb 
58