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