ser_princ.c (505d05c7) | ser_princ.c (159d09a2) |
---|---|
1/* | 1/* |
2 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. | 2 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. |
3 * Use is subject to license terms. 4 */ 5 | 3 * Use is subject to license terms. 4 */ 5 |
6#pragma ident "%Z%%M% %I% %E% SMI" | |
7 8/* 9 * lib/krb5/krb/ser_princ.c 10 * 11 * Copyright 1995 by the Massachusetts Institute of Technology. 12 * All Rights Reserved. 13 * 14 * Export of this software from the United States of America may 15 * require a specific license from the United States Government. 16 * It is the responsibility of any person or organization contemplating 17 * export to obtain such a license before exporting. 18 * 19 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and 20 * distribute this software and its documentation for any purpose and 21 * without fee is hereby granted, provided that the above copyright 22 * notice appear in all copies and that both that copyright notice and 23 * this permission notice appear in supporting documentation, and that 24 * the name of M.I.T. not be used in advertising or publicity pertaining 25 * to distribution of the software without specific, written prior | 6 7/* 8 * lib/krb5/krb/ser_princ.c 9 * 10 * Copyright 1995 by the Massachusetts Institute of Technology. 11 * All Rights Reserved. 12 * 13 * Export of this software from the United States of America may 14 * require a specific license from the United States Government. 15 * It is the responsibility of any person or organization contemplating 16 * export to obtain such a license before exporting. 17 * 18 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and 19 * distribute this software and its documentation for any purpose and 20 * without fee is hereby granted, provided that the above copyright 21 * notice appear in all copies and that both that copyright notice and 22 * this permission notice appear in supporting documentation, and that 23 * the name of M.I.T. not be used in advertising or publicity pertaining 24 * to distribution of the software without specific, written prior |
26 * permission. M.I.T. makes no representations about the suitability of | 25 * permission. Furthermore if you modify this software you must label 26 * your software as modified software and not distribute it in such a 27 * fashion that it might be confused with the original M.I.T. software. 28 * 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 32/* 33 * ser_princ.c - Serialize a krb5_principal structure. 34 */ | 29 * this software for any purpose. It is provided "as is" without express 30 * or implied warranty. 31 * 32 */ 33 34/* 35 * ser_princ.c - Serialize a krb5_principal structure. 36 */ |
35#include <k5-int.h> 36#include <int-proto.h> | 37#include "k5-int.h" 38#include "int-proto.h" |
37 38/* 39 * Routines to deal with externalizing the krb5_principal: 40 * krb5_principal_size(); 41 * krb5_principal_externalize(); 42 * krb5_principal_internalize(); 43 */ 44static krb5_error_code krb5_principal_size --- 25 unchanged lines hidden (view full) --- 70 /* 71 * krb5_principal requires: 72 * krb5_int32 for KV5M_PRINCIPAL 73 * krb5_int32 for flattened name size 74 * strlen(name) for name. 75 * krb5_int32 for KV5M_PRINCIPAL 76 */ 77 kret = EINVAL; | 39 40/* 41 * Routines to deal with externalizing the krb5_principal: 42 * krb5_principal_size(); 43 * krb5_principal_externalize(); 44 * krb5_principal_internalize(); 45 */ 46static krb5_error_code krb5_principal_size --- 25 unchanged lines hidden (view full) --- 72 /* 73 * krb5_principal requires: 74 * krb5_int32 for KV5M_PRINCIPAL 75 * krb5_int32 for flattened name size 76 * strlen(name) for name. 77 * krb5_int32 for KV5M_PRINCIPAL 78 */ 79 kret = EINVAL; |
80 /* Solaris Kerberos */ |
|
78 principal = (krb5_principal) arg; 79 if ((principal) && 80 !(kret = krb5_unparse_name(kcontext, principal, &fname))) { 81 *sizep += (3*sizeof(krb5_int32)) + strlen(fname); | 81 principal = (krb5_principal) arg; 82 if ((principal) && 83 !(kret = krb5_unparse_name(kcontext, principal, &fname))) { 84 *sizep += (3*sizeof(krb5_int32)) + strlen(fname); |
85 /* Solaris Kerberos */ |
|
82 krb5_xfree_wrap(fname, strlen(fname) + 1); 83 } 84 return(kret); 85} 86 87/* 88 * krb5_principal_externalize() - Externalize the krb5_principal. 89 */ --- 6 unchanged lines hidden (view full) --- 96 krb5_octet *bp; 97 size_t remain; 98 char *fname; 99 100 required = 0; 101 bp = *buffer; 102 remain = *lenremain; 103 kret = EINVAL; | 86 krb5_xfree_wrap(fname, strlen(fname) + 1); 87 } 88 return(kret); 89} 90 91/* 92 * krb5_principal_externalize() - Externalize the krb5_principal. 93 */ --- 6 unchanged lines hidden (view full) --- 100 krb5_octet *bp; 101 size_t remain; 102 char *fname; 103 104 required = 0; 105 bp = *buffer; 106 remain = *lenremain; 107 kret = EINVAL; |
108 /* Solaris Kerberos */ |
|
104 principal = (krb5_principal) arg; 105 if (principal) { 106 kret = ENOMEM; 107 if (!krb5_principal_size(kcontext, arg, &required) && 108 (required <= remain)) { 109 if (!(kret = krb5_unparse_name(kcontext, principal, &fname))) { 110 111 (void) krb5_ser_pack_int32(KV5M_PRINCIPAL, &bp, &remain); 112 (void) krb5_ser_pack_int32((krb5_int32) strlen(fname), 113 &bp, &remain); 114 (void) krb5_ser_pack_bytes((krb5_octet *) fname, 115 strlen(fname), &bp, &remain); 116 (void) krb5_ser_pack_int32(KV5M_PRINCIPAL, &bp, &remain); 117 *buffer = bp; 118 *lenremain = remain; 119 | 109 principal = (krb5_principal) arg; 110 if (principal) { 111 kret = ENOMEM; 112 if (!krb5_principal_size(kcontext, arg, &required) && 113 (required <= remain)) { 114 if (!(kret = krb5_unparse_name(kcontext, principal, &fname))) { 115 116 (void) krb5_ser_pack_int32(KV5M_PRINCIPAL, &bp, &remain); 117 (void) krb5_ser_pack_int32((krb5_int32) strlen(fname), 118 &bp, &remain); 119 (void) krb5_ser_pack_bytes((krb5_octet *) fname, 120 strlen(fname), &bp, &remain); 121 (void) krb5_ser_pack_int32(KV5M_PRINCIPAL, &bp, &remain); 122 *buffer = bp; 123 *lenremain = remain; 124 |
125 /* Solaris Kerberos */ |
|
120 krb5_xfree_wrap(fname, strlen(fname) + 1); 121 } 122 } 123 } 124 return(kret); 125} 126 127/* 128 * krb5_principal_internalize() - Internalize the krb5_principal. 129 */ 130static krb5_error_code 131krb5_principal_internalize(krb5_context kcontext, krb5_pointer *argp, krb5_octet **buffer, size_t *lenremain) 132{ 133 krb5_error_code kret; 134 krb5_principal principal; 135 krb5_int32 ibuf; 136 krb5_octet *bp; 137 size_t remain; 138 char *tmpname; | 126 krb5_xfree_wrap(fname, strlen(fname) + 1); 127 } 128 } 129 } 130 return(kret); 131} 132 133/* 134 * krb5_principal_internalize() - Internalize the krb5_principal. 135 */ 136static krb5_error_code 137krb5_principal_internalize(krb5_context kcontext, krb5_pointer *argp, krb5_octet **buffer, size_t *lenremain) 138{ 139 krb5_error_code kret; 140 krb5_principal principal; 141 krb5_int32 ibuf; 142 krb5_octet *bp; 143 size_t remain; 144 char *tmpname; |
145 /* Solaris Kerberos */ |
|
139 int tmpsize; 140 bp = *buffer; 141 remain = *lenremain; 142 kret = EINVAL; 143 /* Read our magic number */ 144 if (krb5_ser_unpack_int32(&ibuf, &bp, &remain)) 145 ibuf = 0; 146 if (ibuf == KV5M_PRINCIPAL) { 147 kret = ENOMEM; 148 149 /* See if we have enough data for the length */ 150 if (!(kret = krb5_ser_unpack_int32(&ibuf, &bp, &remain))) { 151 /* Get the string */ | 146 int tmpsize; 147 bp = *buffer; 148 remain = *lenremain; 149 kret = EINVAL; 150 /* Read our magic number */ 151 if (krb5_ser_unpack_int32(&ibuf, &bp, &remain)) 152 ibuf = 0; 153 if (ibuf == KV5M_PRINCIPAL) { 154 kret = ENOMEM; 155 156 /* See if we have enough data for the length */ 157 if (!(kret = krb5_ser_unpack_int32(&ibuf, &bp, &remain))) { 158 /* Get the string */ |
159 /* Solaris Kerberos */ |
|
152 tmpsize = ibuf+1; 153 tmpname = (char *) MALLOC(tmpsize); 154 if ((tmpname) && 155 !(kret = krb5_ser_unpack_bytes((krb5_octet *) tmpname, 156 (size_t) ibuf, 157 &bp, &remain))) { 158 tmpname[ibuf] = '\0'; 159 --- 7 unchanged lines hidden (view full) --- 167 *lenremain = remain; 168 *argp = principal; 169 } 170 else 171 kret = EINVAL; 172 } 173 if (kret && principal) 174 krb5_free_principal(kcontext, principal); | 160 tmpsize = ibuf+1; 161 tmpname = (char *) MALLOC(tmpsize); 162 if ((tmpname) && 163 !(kret = krb5_ser_unpack_bytes((krb5_octet *) tmpname, 164 (size_t) ibuf, 165 &bp, &remain))) { 166 tmpname[ibuf] = '\0'; 167 --- 7 unchanged lines hidden (view full) --- 175 *lenremain = remain; 176 *argp = principal; 177 } 178 else 179 kret = EINVAL; 180 } 181 if (kret && principal) 182 krb5_free_principal(kcontext, principal); |
183 /* Solaris Kerberos */ |
|
175 FREE(tmpname,tmpsize); 176 } 177 } 178 } 179 return(kret); 180} 181 182/* 183 * Register the context serializer. 184 */ 185krb5_error_code 186krb5_ser_principal_init(krb5_context kcontext) 187{ 188 return(krb5_register_serializer(kcontext, &krb5_principal_ser_entry)); 189} | 184 FREE(tmpname,tmpsize); 185 } 186 } 187 } 188 return(kret); 189} 190 191/* 192 * Register the context serializer. 193 */ 194krb5_error_code 195krb5_ser_principal_init(krb5_context kcontext) 196{ 197 return(krb5_register_serializer(kcontext, &krb5_principal_ser_entry)); 198} |