ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb/*
159d09a20817016f09b3ea28d1bdada4a336bb91Mark Phalan * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb * Use is subject to license terms.
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb */
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb/*
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb * lib/krb5/krb/set_realm.c
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb *
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb * Copyright 1997 by the Massachusetts Institute of Technology.
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb * All Rights Reserved.
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb *
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb * Export of this software from the United States of America may
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb * require a specific license from the United States Government.
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb * It is the responsibility of any person or organization contemplating
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb * export to obtain such a license before exporting.
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb *
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb * distribute this software and its documentation for any purpose and
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb * without fee is hereby granted, provided that the above copyright
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb * notice appear in all copies and that both that copyright notice and
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb * this permission notice appear in supporting documentation, and that
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb * the name of M.I.T. not be used in advertising or publicity pertaining
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb * to distribution of the software without specific, written prior
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb * permission. Furthermore if you modify this software you must label
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb * your software as modified software and not distribute it in such a
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb * fashion that it might be confused with the original M.I.T. software.
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb * M.I.T. makes no representations about the suitability of
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb * this software for any purpose. It is provided "as is" without express
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb * or implied warranty.
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb */
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb#include "k5-int.h"
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtbkrb5_error_code KRB5_CALLCONV
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtbkrb5_set_principal_realm(krb5_context context, krb5_principal principal, const char *realm)
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb{
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb size_t length;
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb char *newrealm;
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb if (!realm || !*realm)
159d09a20817016f09b3ea28d1bdada4a336bb91Mark Phalan return EINVAL; /* Solaris Kerberos */
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb length = strlen(realm);
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb newrealm = malloc(length+1); /* Include room for the null */
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb if (!newrealm)
159d09a20817016f09b3ea28d1bdada4a336bb91Mark Phalan return ENOMEM; /* Solaris Kerberos */
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb strcpy(newrealm, realm);
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb (void) krb5_xfree(krb5_princ_realm(context,principal)->data);
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb krb5_princ_realm(context, principal)->length = length;
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb krb5_princ_realm(context, principal)->data = newrealm;
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb return 0;
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb}
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb
ea100d09ff60b44d2fb4efa29388f1dfd6c916fdgtb