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