summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGünther Deschner <gd@samba.org>2008-10-22 14:06:08 +0200
committerGünther Deschner <gd@samba.org>2008-10-22 21:37:36 +0200
commitd9f1fff5b35a2c852e69c2c58e68824b5f381d01 (patch)
tree7a0c9d09fb9f3623fa9aef746266b60a7cda1873
parentcef97c245955d0f125928740cd89984100635d29 (diff)
downloadsamba-d9f1fff5b35a2c852e69c2c58e68824b5f381d01.tar.gz
samba-d9f1fff5b35a2c852e69c2c58e68824b5f381d01.tar.bz2
samba-d9f1fff5b35a2c852e69c2c58e68824b5f381d01.zip
s3: use shared asn1 code.
Guenther
-rw-r--r--source3/Makefile.in8
-rw-r--r--source3/include/asn_1.h54
-rw-r--r--source3/include/includes.h3
-rw-r--r--source3/include/proto.h33
-rw-r--r--source3/libads/cldap.c8
-rw-r--r--source3/libads/sasl.c6
-rw-r--r--source3/libsmb/asn1.c603
-rw-r--r--source3/libsmb/cliconnect.c15
-rw-r--r--source3/libsmb/clikrb5.c4
-rw-r--r--source3/libsmb/clispnego.c34
-rw-r--r--source3/libsmb/spnego.c28
-rw-r--r--source3/rpc_server/srv_pipe.c2
-rw-r--r--source3/smbd/sesssetup.c2
13 files changed, 57 insertions, 743 deletions
diff --git a/source3/Makefile.in b/source3/Makefile.in
index 25c3a590ca..eee03dbaa8 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -425,7 +425,7 @@ LIBSAMBA_OBJ = $(LIBSMB_OBJ0) \
CLDAP_OBJ = libads/cldap.o
LIBSMB_OBJ = libsmb/clientgen.o libsmb/cliconnect.o libsmb/clifile.o \
- libsmb/clikrb5.o libsmb/clispnego.o libsmb/asn1.o \
+ libsmb/clikrb5.o libsmb/clispnego.o ../lib/util/asn1.o \
libsmb/clirap.o libsmb/clierror.o libsmb/climessage.o \
libsmb/clireadwrite.o libsmb/clilist.o libsmb/cliprint.o \
libsmb/clitrans.o libsmb/clisecdesc.o libsmb/clidgram.o \
@@ -772,7 +772,7 @@ SMBPASSWD_OBJ = utils/smbpasswd.o $(PASSWD_UTIL_OBJ) $(PASSCHANGE_OBJ) \
PDBEDIT_OBJ = utils/pdbedit.o $(PASSWD_UTIL_OBJ) $(PARAM_OBJ) $(PASSDB_OBJ) @LIBWBCLIENT_STATIC@ \
$(LIBSAMBA_OBJ) \
$(LIB_NONSMBD_OBJ) $(GROUPDB_OBJ) \
- $(POPT_LIB_OBJ) $(SMBLDAP_OBJ) libsmb/asn1.o \
+ $(POPT_LIB_OBJ) $(SMBLDAP_OBJ) ../lib/util/asn1.o \
$(LDB_OBJ)
SMBGET_OBJ = utils/smbget.o $(POPT_LIB_OBJ) $(LIBSMBCLIENT_OBJ1) @LIBWBCLIENT_STATIC@
@@ -988,7 +988,7 @@ NDRDUMP_OBJ = ../librpc/tools/ndrdump.o \
librpc/gen_ndr/ndr_svcctl.o \
librpc/gen_ndr/tables.o ../librpc/ndr/ndr_table.o \
../librpc/ndr/ndr_krb5pac.o \
- librpc/gen_ndr/ndr_krb5pac.o libsmb/asn1.o
+ librpc/gen_ndr/ndr_krb5pac.o ../lib/util/asn1.o
DEBUG2HTML_OBJ = utils/debug2html.o utils/debugparse.o
@@ -1121,7 +1121,7 @@ TDBTORTURE_OBJ = @tdbdir@/tools/tdbtorture.o @LIBTDB_STATIC@ $(LIBREPLACE_OBJ) \
NTLM_AUTH_OBJ1 = utils/ntlm_auth.o utils/ntlm_auth_diagnostics.o
NTLM_AUTH_OBJ = ${NTLM_AUTH_OBJ1} $(LIBSAMBA_OBJ) $(POPT_LIB_OBJ) \
- libsmb/asn1.o libsmb/spnego.o libsmb/clikrb5.o libads/kerberos.o \
+ ../lib/util/asn1.o libsmb/spnego.o libsmb/clikrb5.o libads/kerberos.o \
$(SERVER_MUTEX_OBJ) $(LIBADS_SERVER_OBJ) \
$(PASSDB_OBJ) $(GROUPDB_OBJ) \
$(SMBLDAP_OBJ) $(LIBNMB_OBJ) \
diff --git a/source3/include/asn_1.h b/source3/include/asn_1.h
deleted file mode 100644
index b9bade2db9..0000000000
--- a/source3/include/asn_1.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- simple ASN1 code
- Copyright (C) Andrew Tridgell 2001
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef _ASN_1_H
-#define _ASN_1_H
-
-struct nesting {
- off_t start;
- size_t taglen; /* for parsing */
- struct nesting *next;
-};
-
-typedef struct asn1_data {
- uint8 *data;
- size_t length;
- off_t ofs;
- struct nesting *nesting;
- bool has_error;
-} ASN1_DATA;
-
-
-#define ASN1_APPLICATION(x) ((x)+0x60)
-#define ASN1_APPLICATION_SIMPLE(x) ((x)+0x40)
-#define ASN1_SEQUENCE(x) ((x)+0x30)
-#define ASN1_CONTEXT(x) ((x)+0xa0)
-#define ASN1_CONTEXT_SIMPLE(x) ((x)+0x80)
-#define ASN1_GENERAL_STRING 0x1b
-#define ASN1_OCTET_STRING 0x4
-#define ASN1_OID 0x6
-#define ASN1_BOOLEAN 0x1
-#define ASN1_INTEGER 0x2
-#define ASN1_BITFIELD 0x3
-#define ASN1_ENUMERATED 0xa
-#define ASN1_SET 0x31
-
-#define ASN1_MAX_OIDS 20
-
-#endif /* _ASN_1_H */
diff --git a/source3/include/includes.h b/source3/include/includes.h
index c164d285c1..716235752d 100644
--- a/source3/include/includes.h
+++ b/source3/include/includes.h
@@ -584,6 +584,8 @@ struct smb_iconv_convenience *lp_iconv_convenience(void *lp_ctx);
#include "../lib/util/data_blob.h"
#include "../lib/util/time.h"
+#include "../lib/util/asn1.h"
+
/* And a little extension. Abort on type mismatch */
#define talloc_get_type_abort(ptr, type) \
(type *)talloc_check_name_abort(ptr, #type)
@@ -643,7 +645,6 @@ struct smb_iconv_convenience *lp_iconv_convenience(void *lp_ctx);
#include "client.h"
#include "session.h"
-#include "asn_1.h"
#include "popt.h"
#include "mangle.h"
#include "module.h"
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 9b555e6db2..370a64185a 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -2474,37 +2474,6 @@ _PUBLIC_ NTSTATUS dcerpc_pipe_connect(TALLOC_CTX *parent_ctx, struct dcerpc_pipe
struct cli_credentials *credentials, struct event_context *ev,
struct loadparm_context *lp_ctx);
-/* The following definitions come from libsmb/asn1.c */
-
-void asn1_free(ASN1_DATA *data);
-bool asn1_write(ASN1_DATA *data, const void *p, int len);
-bool asn1_write_uint8(ASN1_DATA *data, uint8 v);
-bool asn1_push_tag(ASN1_DATA *data, uint8 tag);
-bool asn1_pop_tag(ASN1_DATA *data);
-bool asn1_write_Integer(ASN1_DATA *data, int i);
-bool asn1_write_OID(ASN1_DATA *data, const char *OID);
-bool asn1_write_OctetString(ASN1_DATA *data, const void *p, size_t length);
-bool asn1_write_GeneralString(ASN1_DATA *data, const char *s);
-bool asn1_write_BOOLEAN(ASN1_DATA *data, bool v);
-bool asn1_write_BOOLEAN2(ASN1_DATA *data, bool v);
-bool asn1_check_BOOLEAN(ASN1_DATA *data, bool v);
-bool asn1_load(ASN1_DATA *data, DATA_BLOB blob);
-bool asn1_read(ASN1_DATA *data, void *p, int len);
-bool asn1_read_uint8(ASN1_DATA *data, uint8 *v);
-bool asn1_check_tag(ASN1_DATA *data, uint8 tag);
-bool asn1_start_tag(ASN1_DATA *data, uint8 tag);
-bool asn1_end_tag(ASN1_DATA *data);
-int asn1_tag_remaining(ASN1_DATA *data);
-bool asn1_read_OID(ASN1_DATA *data, char **OID);
-bool asn1_check_OID(ASN1_DATA *data, const char *OID);
-bool asn1_read_GeneralString(ASN1_DATA *data, char **s);
-bool asn1_read_OctetString(ASN1_DATA *data, DATA_BLOB *blob);
-bool asn1_read_Integer(ASN1_DATA *data, int *i);
-bool asn1_check_enumerated(ASN1_DATA *data, int v);
-bool asn1_write_enumerated(ASN1_DATA *data, uint8 v);
-bool ber_write_OID_String(DATA_BLOB *blob, const char *OID);
-bool ber_read_OID_String(TALLOC_CTX *mem_ctx, DATA_BLOB blob, const char **OID);
-
/* The following definitions come from libsmb/cliconnect.c */
ADS_STATUS cli_session_setup_spnego(struct cli_state *cli, const char *user,
@@ -2966,7 +2935,7 @@ DATA_BLOB spnego_gen_negTokenInit(char guid[16],
const char *principal);
DATA_BLOB gen_negTokenInit(const char *OID, DATA_BLOB blob);
bool spnego_parse_negTokenInit(DATA_BLOB blob,
- char *OIDs[ASN1_MAX_OIDS],
+ char *OIDs[ASN1_MAX_OIDS],
char **principal);
DATA_BLOB gen_negTokenTarg(const char *OIDs[], DATA_BLOB blob);
bool parse_negTokenTarg(DATA_BLOB blob, char *OIDs[ASN1_MAX_OIDS], DATA_BLOB *secblob);
diff --git a/source3/libads/cldap.c b/source3/libads/cldap.c
index c37220c903..7180464d47 100644
--- a/source3/libads/cldap.c
+++ b/source3/libads/cldap.c
@@ -46,7 +46,7 @@ static int send_cldap_netlogon(int sock, const char *domain,
asn1_write_enumerated(&data, 0);
asn1_write_Integer(&data, 0);
asn1_write_Integer(&data, 0);
- asn1_write_BOOLEAN2(&data, False);
+ asn1_write_BOOLEAN(&data, False);
asn1_push_tag(&data, ASN1_CONTEXT(0));
if (domain) {
@@ -164,12 +164,12 @@ static int recv_cldap_netlogon(TALLOC_CTX *mem_ctx,
asn1_start_tag(&data, ASN1_SEQUENCE(0));
asn1_read_Integer(&data, &i1);
asn1_start_tag(&data, ASN1_APPLICATION(4));
- asn1_read_OctetString(&data, &os1);
+ asn1_read_OctetString(&data, NULL, &os1);
asn1_start_tag(&data, ASN1_SEQUENCE(0));
asn1_start_tag(&data, ASN1_SEQUENCE(0));
- asn1_read_OctetString(&data, &os2);
+ asn1_read_OctetString(&data, NULL, &os2);
asn1_start_tag(&data, ASN1_SET);
- asn1_read_OctetString(&data, &os3);
+ asn1_read_OctetString(&data, NULL, &os3);
asn1_end_tag(&data);
asn1_end_tag(&data);
asn1_end_tag(&data);
diff --git a/source3/libads/sasl.c b/source3/libads/sasl.c
index 55bc16a1be..3182b936e0 100644
--- a/source3/libads/sasl.c
+++ b/source3/libads/sasl.c
@@ -784,7 +784,7 @@ static ADS_STATUS ads_sasl_spnego_bind(ADS_STRUCT *ads)
got_kerberos_mechanism = True;
}
#endif
- free(OIDs[i]);
+ talloc_free(OIDs[i]);
}
DEBUG(3,("ads_sasl_spnego_bind: got server principal name = %s\n", given_principal));
@@ -795,7 +795,7 @@ static ADS_STATUS ads_sasl_spnego_bind(ADS_STRUCT *ads)
struct ads_service_principal p;
status = ads_generate_service_principal(ads, given_principal, &p);
- SAFE_FREE(given_principal);
+ TALLOC_FREE(given_principal);
if (!ADS_ERR_OK(status)) {
return status;
}
@@ -830,7 +830,7 @@ static ADS_STATUS ads_sasl_spnego_bind(ADS_STRUCT *ads)
} else
#endif
{
- SAFE_FREE(given_principal);
+ TALLOC_FREE(given_principal);
}
/* lets do NTLMSSP ... this has the big advantage that we don't need
diff --git a/source3/libsmb/asn1.c b/source3/libsmb/asn1.c
deleted file mode 100644
index aca1c48841..0000000000
--- a/source3/libsmb/asn1.c
+++ /dev/null
@@ -1,603 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- simple SPNEGO routines
- Copyright (C) Andrew Tridgell 2001
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "includes.h"
-
-/* free an asn1 structure */
-void asn1_free(ASN1_DATA *data)
-{
- struct nesting *nesting = data->nesting;
-
- while (nesting) {
- struct nesting *nnext = nesting->next;
- free(nesting);
- nesting = nnext;
- };
- data->nesting = NULL;
- SAFE_FREE(data->data);
-}
-
-/* write to the ASN1 buffer, advancing the buffer pointer */
-bool asn1_write(ASN1_DATA *data, const void *p, int len)
-{
- if (data->has_error) return false;
- if (data->length < data->ofs+len) {
- data->data = SMB_REALLOC_ARRAY(data->data, unsigned char,
- data->ofs+len);
- if (!data->data) {
- data->has_error = true;
- return false;
- }
- data->length = data->ofs+len;
- }
- memcpy(data->data + data->ofs, p, len);
- data->ofs += len;
- return true;
-}
-
-/* useful fn for writing a uint8 */
-bool asn1_write_uint8(ASN1_DATA *data, uint8 v)
-{
- return asn1_write(data, &v, 1);
-}
-
-/* push a tag onto the asn1 data buffer. Used for nested structures */
-bool asn1_push_tag(ASN1_DATA *data, uint8 tag)
-{
- struct nesting *nesting;
-
- asn1_write_uint8(data, tag);
- nesting = SMB_MALLOC_P(struct nesting);
- if (!nesting) {
- data->has_error = true;
- return false;
- }
-
- nesting->start = data->ofs;
- nesting->next = data->nesting;
- data->nesting = nesting;
- return asn1_write_uint8(data, 0xff);
-}
-
-/* pop a tag */
-bool asn1_pop_tag(ASN1_DATA *data)
-{
- struct nesting *nesting;
- size_t len;
-
- if (data->has_error) {
- return false;
- }
-
- nesting = data->nesting;
-
- if (!nesting) {
- data->has_error = true;
- return false;
- }
- len = data->ofs - (nesting->start+1);
- /* yes, this is ugly. We don't know in advance how many bytes the length
- of a tag will take, so we assumed 1 byte. If we were wrong then we
- need to correct our mistake */
- if (len > 0xFFFF) {
- data->data[nesting->start] = 0x83;
- if (!asn1_write_uint8(data, 0)) return false;
- if (!asn1_write_uint8(data, 0)) return false;
- if (!asn1_write_uint8(data, 0)) return false;
- memmove(data->data+nesting->start+4, data->data+nesting->start+1, len);
- data->data[nesting->start+1] = (len>>16) & 0xFF;
- data->data[nesting->start+2] = (len>>8) & 0xFF;
- data->data[nesting->start+3] = len&0xff;
- } else if (len > 255) {
- data->data[nesting->start] = 0x82;
- if (!asn1_write_uint8(data, 0)) return false;
- if (!asn1_write_uint8(data, 0)) return false;
- memmove(data->data+nesting->start+3, data->data+nesting->start+1, len);
- data->data[nesting->start+1] = len>>8;
- data->data[nesting->start+2] = len&0xff;
- } else if (len > 127) {
- data->data[nesting->start] = 0x81;
- if (!asn1_write_uint8(data, 0)) return false;
- memmove(data->data+nesting->start+2, data->data+nesting->start+1, len);
- data->data[nesting->start+1] = len;
- } else {
- data->data[nesting->start] = len;
- }
-
- data->nesting = nesting->next;
- free(nesting);
- return true;
-}
-
-
-/* write an integer */
-bool asn1_write_Integer(ASN1_DATA *data, int i)
-{
- if (!asn1_push_tag(data, ASN1_INTEGER)) return false;
- do {
- asn1_write_uint8(data, i);
- i = i >> 8;
- } while (i);
- return asn1_pop_tag(data);
-}
-
-/* write an object ID to a ASN1 buffer */
-bool asn1_write_OID(ASN1_DATA *data, const char *OID)
-{
- unsigned v, v2;
- const char *p = (const char *)OID;
- char *newp;
-
- if (!asn1_push_tag(data, ASN1_OID))
- return false;
- v = strtol(p, &newp, 10);
- p = newp;
- v2 = strtol(p, &newp, 10);
- p = newp;
- if (!asn1_write_uint8(data, 40*v + v2))
- return false;
-
- while (*p) {
- v = strtol(p, &newp, 10);
- p = newp;
- if (v >= (1<<28)) asn1_write_uint8(data, 0x80 | ((v>>28)&0xff));
- if (v >= (1<<21)) asn1_write_uint8(data, 0x80 | ((v>>21)&0xff));
- if (v >= (1<<14)) asn1_write_uint8(data, 0x80 | ((v>>14)&0xff));
- if (v >= (1<<7)) asn1_write_uint8(data, 0x80 | ((v>>7)&0xff));
- if (!asn1_write_uint8(data, v&0x7f))
- return false;
- }
- return asn1_pop_tag(data);
-}
-
-/* write an octet string */
-bool asn1_write_OctetString(ASN1_DATA *data, const void *p, size_t length)
-{
- asn1_push_tag(data, ASN1_OCTET_STRING);
- asn1_write(data, p, length);
- asn1_pop_tag(data);
- return !data->has_error;
-}
-
-/* write a general string */
-bool asn1_write_GeneralString(ASN1_DATA *data, const char *s)
-{
- asn1_push_tag(data, ASN1_GENERAL_STRING);
- asn1_write(data, s, strlen(s));
- asn1_pop_tag(data);
- return !data->has_error;
-}
-
-/* write a BOOLEAN */
-bool asn1_write_BOOLEAN(ASN1_DATA *data, bool v)
-{
- asn1_write_uint8(data, ASN1_BOOLEAN);
- asn1_write_uint8(data, v);
- return !data->has_error;
-}
-
-/* write a BOOLEAN - hmm, I suspect this one is the correct one, and the
- above boolean is bogus. Need to check */
-bool asn1_write_BOOLEAN2(ASN1_DATA *data, bool v)
-{
- asn1_push_tag(data, ASN1_BOOLEAN);
- asn1_write_uint8(data, v);
- asn1_pop_tag(data);
- return !data->has_error;
-}
-
-/* check a BOOLEAN */
-bool asn1_check_BOOLEAN(ASN1_DATA *data, bool v)
-{
- uint8 b = 0;
-
- asn1_read_uint8(data, &b);
- if (b != ASN1_BOOLEAN) {
- data->has_error = true;
- return false;
- }
- asn1_read_uint8(data, &b);
- if (b != v) {
- data->has_error = true;
- return false;
- }
- return !data->has_error;
-}
-
-
-/* load a ASN1_DATA structure with a lump of data, ready to be parsed */
-bool asn1_load(ASN1_DATA *data, DATA_BLOB blob)
-{
- ZERO_STRUCTP(data);
- data->data = (unsigned char *)memdup(blob.data, blob.length);
- if (!data->data) {
- data->has_error = true;
- return false;
- }
- data->length = blob.length;
- return true;
-}
-
-/* read from a ASN1 buffer, advancing the buffer pointer */
-bool asn1_read(ASN1_DATA *data, void *p, int len)
-{
- if (data->has_error)
- return false;
-
- if (len < 0 || data->ofs + len < data->ofs || data->ofs + len < len) {
- data->has_error = true;
- return false;
- }
-
- if (data->ofs + len > data->length) {
- data->has_error = true;
- return false;
- }
- memcpy(p, data->data + data->ofs, len);
- data->ofs += len;
- return true;
-}
-
-/* read a uint8 from a ASN1 buffer */
-bool asn1_read_uint8(ASN1_DATA *data, uint8 *v)
-{
- return asn1_read(data, v, 1);
-}
-
-/*
- * Check thta the value of the ASN1 buffer at the current offset equals tag.
- */
-bool asn1_check_tag(ASN1_DATA *data, uint8 tag)
-{
- if (data->has_error || data->ofs >= data->length || data->ofs < 0) {
- data->has_error = true;
- return false;
- }
-
- return (tag == data->data[data->ofs]);
-}
-
-/* start reading a nested asn1 structure */
-bool asn1_start_tag(ASN1_DATA *data, uint8 tag)
-{
- uint8 b;
- struct nesting *nesting;
-
- if (!asn1_read_uint8(data, &b))
- return false;
-
- if (b != tag) {
- data->has_error = true;
- return false;
- }
- nesting = SMB_MALLOC_P(struct nesting);
- if (!nesting) {
- data->has_error = true;
- return false;
- }
-
- if (!asn1_read_uint8(data, &b)) {
- SAFE_FREE(nesting);
- return false;
- }
-
- if (b & 0x80) {
- int n = b & 0x7f;
- if (!asn1_read_uint8(data, &b)) {
- SAFE_FREE(nesting);
- return false;
- }
- nesting->taglen = b;
- while (n > 1) {
- if (!asn1_read_uint8(data, &b)) {
- SAFE_FREE(nesting);
- return false;
- }
- nesting->taglen = (nesting->taglen << 8) | b;
- n--;
- }
- } else {
- nesting->taglen = b;
- }
- nesting->start = data->ofs;
- nesting->next = data->nesting;
- data->nesting = nesting;
- return !data->has_error;
-}
-
-
-/* stop reading a tag */
-bool asn1_end_tag(ASN1_DATA *data)
-{
- struct nesting *nesting;
-
- /* make sure we read it all */
- if (asn1_tag_remaining(data) != 0) {
- data->has_error = true;
- return false;
- }
-
- nesting = data->nesting;
-
- if (!nesting) {
- data->has_error = true;
- return false;
- }
-
- data->nesting = nesting->next;
- free(nesting);
- return true;
-}
-
-/* work out how many bytes are left in this nested tag */
-int asn1_tag_remaining(ASN1_DATA *data)
-{
- if (data->has_error)
- return 0;
-
- if (!data->nesting) {
- data->has_error = true;
- return -1;
- }
- return data->nesting->taglen - (data->ofs - data->nesting->start);
-}
-
-/* read an object ID from a ASN1 buffer */
-bool asn1_read_OID(ASN1_DATA *data, char **OID)
-{
- uint8 b = 0;
- char *oid_str = NULL;
-
- *OID = NULL;
-
- if (!asn1_start_tag(data, ASN1_OID)) {
- return false;
- }
- asn1_read_uint8(data, &b);
-
- oid_str = talloc_asprintf(NULL,
- "%u",
- b/40);
- if (!oid_str) {
- data->has_error = true;
- goto out;
- }
- oid_str = talloc_asprintf_append(oid_str,
- " %u",
- b%40);
- if (!oid_str) {
- data->has_error = true;
- goto out;
- }
-
- while (asn1_tag_remaining(data) > 0) {
- unsigned v = 0;
- do {
- asn1_read_uint8(data, &b);
- v = (v<<7) | (b&0x7f);
- } while (!data->has_error && b & 0x80);
- oid_str = talloc_asprintf_append(oid_str,
- " %u",
- v);
- if (!oid_str) {
- data->has_error = true;
- goto out;
- }
- }
-
- out:
-
- asn1_end_tag(data);
-
- if (!data->has_error) {
- *OID = SMB_STRDUP(oid_str);
- }
-
- TALLOC_FREE(oid_str);
-
- return !data->has_error;
-}
-
-/* check that the next object ID is correct */
-bool asn1_check_OID(ASN1_DATA *data, const char *OID)
-{
- char *id;
-
- if (!asn1_read_OID(data, &id)) {
- return false;
- }
-
- if (strcmp(id, OID) != 0) {
- data->has_error = true;
- free(id);
- return false;
- }
- free(id);
- return true;
-}
-
-/* read a GeneralString from a ASN1 buffer */
-bool asn1_read_GeneralString(ASN1_DATA *data, char **s)
-{
- int len;
- char *str;
-
- *s = NULL;
-
- if (!asn1_start_tag(data, ASN1_GENERAL_STRING)) {
- return false;
- }
- len = asn1_tag_remaining(data);
- if (len < 0) {
- data->has_error = true;
- return false;
- }
- str = SMB_MALLOC_ARRAY(char, len+1);
- if (!str) {
- data->has_error = true;
- return false;
- }
- asn1_read(data, str, len);
- str[len] = 0;
- asn1_end_tag(data);
-
- if (!data->has_error) {
- *s = str;
- }
- return !data->has_error;
-}
-
-/* read a octet string blob */
-bool asn1_read_OctetString(ASN1_DATA *data, DATA_BLOB *blob)
-{
- int len;
- ZERO_STRUCTP(blob);
- if (!asn1_start_tag(data, ASN1_OCTET_STRING)) return false;
- len = asn1_tag_remaining(data);
- if (len < 0) {
- data->has_error = true;
- return false;
- }
- *blob = data_blob(NULL, len);
- asn1_read(data, blob->data, len);
- asn1_end_tag(data);
- return !data->has_error;
-}
-
-/* read an interger */
-bool asn1_read_Integer(ASN1_DATA *data, int *i)
-{
- uint8 b;
- *i = 0;
-
- if (!asn1_start_tag(data, ASN1_INTEGER)) return false;
- while (asn1_tag_remaining(data)>0) {
- asn1_read_uint8(data, &b);
- *i = (*i << 8) + b;
- }
- return asn1_end_tag(data);
-
-}
-
-/* check a enumarted value is correct */
-bool asn1_check_enumerated(ASN1_DATA *data, int v)
-{
- uint8 b;
- if (!asn1_start_tag(data, ASN1_ENUMERATED)) return false;
- asn1_read_uint8(data, &b);
- asn1_end_tag(data);
-
- if (v != b)
- data->has_error = false;
-
- return !data->has_error;
-}
-
-/* write an enumarted value to the stream */
-bool asn1_write_enumerated(ASN1_DATA *data, uint8 v)
-{
- if (!asn1_push_tag(data, ASN1_ENUMERATED)) return false;
- asn1_write_uint8(data, v);
- asn1_pop_tag(data);
- return !data->has_error;
-}
-
-bool ber_write_OID_String(DATA_BLOB *blob, const char *OID)
-{
- uint_t v, v2;
- const char *p = (const char *)OID;
- char *newp;
- int i;
-
- v = strtoul(p, &newp, 10);
- if (newp[0] != '.') return false;
- p = newp + 1;
-
- v2 = strtoul(p, &newp, 10);
- if (newp[0] != '.') return false;
- p = newp + 1;
-
- /*the ber representation can't use more space then the string one */
- *blob = data_blob(NULL, strlen(OID));
- if (!blob->data) return false;
-
- blob->data[0] = 40*v + v2;
-
- i = 1;
- while (*p) {
- v = strtoul(p, &newp, 10);
- if (newp[0] == '.') {
- p = newp + 1;
- } else if (newp[0] == '\0') {
- p = newp;
- } else {
- data_blob_free(blob);
- return false;
- }
- if (v >= (1<<28)) blob->data[i++] = (0x80 | ((v>>28)&0x7f));
- if (v >= (1<<21)) blob->data[i++] = (0x80 | ((v>>21)&0x7f));
- if (v >= (1<<14)) blob->data[i++] = (0x80 | ((v>>14)&0x7f));
- if (v >= (1<<7)) blob->data[i++] = (0x80 | ((v>>7)&0x7f));
- blob->data[i++] = (v&0x7f);
- }
-
- blob->length = i;
-
- return true;
-}
-
-/* read an object ID from a data blob */
-bool ber_read_OID_String(TALLOC_CTX *mem_ctx, DATA_BLOB blob, const char **OID)
-{
- int i;
- uint8_t *b;
- uint_t v;
- char *tmp_oid = NULL;
-
- if (blob.length < 2) return false;
-
- b = blob.data;
-
- tmp_oid = talloc_asprintf(mem_ctx, "%u", b[0]/40);
- if (!tmp_oid) goto nomem;
- tmp_oid = talloc_asprintf_append_buffer(tmp_oid, ".%u", b[0]%40);
- if (!tmp_oid) goto nomem;
-
- for(i = 1, v = 0; i < blob.length; i++) {
- v = (v<<7) | (b[i]&0x7f);
- if ( ! (b[i] & 0x80)) {
- tmp_oid = talloc_asprintf_append_buffer(tmp_oid, ".%u", v);
- v = 0;
- }
- if (!tmp_oid) goto nomem;
- }
-
- if (v != 0) {
- talloc_free(tmp_oid);
- return false;
- }
-
- *OID = tmp_oid;
- return true;
-
-nomem:
- return false;
-}
-
-
diff --git a/source3/libsmb/cliconnect.c b/source3/libsmb/cliconnect.c
index 8ef14d7973..1fd6f20d9d 100644
--- a/source3/libsmb/cliconnect.c
+++ b/source3/libsmb/cliconnect.c
@@ -833,7 +833,7 @@ ADS_STATUS cli_session_setup_spnego(struct cli_state *cli, const char *user,
strcmp(OIDs[i], OID_KERBEROS5) == 0) {
cli->got_kerberos_mechanism = True;
}
- free(OIDs[i]);
+ talloc_free(OIDs[i]);
}
DEBUG(3,("got principal=%s\n", principal ? principal : "<null>"));
@@ -854,7 +854,7 @@ ADS_STATUS cli_session_setup_spnego(struct cli_state *cli, const char *user,
ret = kerberos_kinit_password(user, pass, 0 /* no time correction for now */, NULL);
if (ret){
- SAFE_FREE(principal);
+ TALLOC_FREE(principal);
DEBUG(0, ("Kinit failed: %s\n", error_message(ret)));
if (cli->fallback_after_kerberos)
goto ntlmssp;
@@ -866,7 +866,7 @@ ADS_STATUS cli_session_setup_spnego(struct cli_state *cli, const char *user,
we have a valid host NetBIOS name.
*/
if (strequal(principal, ADS_IGNORE_PRINCIPAL)) {
- SAFE_FREE(principal);
+ TALLOC_FREE(principal);
}
if (principal == NULL &&
@@ -897,8 +897,9 @@ ADS_STATUS cli_session_setup_spnego(struct cli_state *cli, const char *user,
realm = kerberos_get_default_realm_from_ccache();
}
if (realm && *realm) {
- if (asprintf(&principal, "%s$@%s",
- machine, realm) < 0) {
+ principal = talloc_asprintf(NULL, "%s$@%s",
+ machine, realm);
+ if (!principal) {
SAFE_FREE(machine);
SAFE_FREE(realm);
return ADS_ERROR_NT(NT_STATUS_NO_MEMORY);
@@ -915,14 +916,14 @@ ADS_STATUS cli_session_setup_spnego(struct cli_state *cli, const char *user,
rc = cli_session_setup_kerberos(cli, principal,
dest_realm);
if (ADS_ERR_OK(rc) || !cli->fallback_after_kerberos) {
- SAFE_FREE(principal);
+ TALLOC_FREE(principal);
return rc;
}
}
}
#endif
- SAFE_FREE(principal);
+ TALLOC_FREE(principal);
ntlmssp:
diff --git a/source3/libsmb/clikrb5.c b/source3/libsmb/clikrb5.c
index 790e8d5369..5bcc678847 100644
--- a/source3/libsmb/clikrb5.c
+++ b/source3/libsmb/clikrb5.c
@@ -340,7 +340,7 @@ bool unwrap_edata_ntstatus(TALLOC_CTX *mem_ctx,
}
asn1_start_tag(&data, ASN1_CONTEXT(2));
- asn1_read_OctetString(&data, &edata_contents);
+ asn1_read_OctetString(&data, NULL, &edata_contents);
asn1_end_tag(&data);
asn1_end_tag(&data);
asn1_end_tag(&data);
@@ -378,7 +378,7 @@ bool unwrap_pac(TALLOC_CTX *mem_ctx, DATA_BLOB *auth_data, DATA_BLOB *unwrapped_
asn1_end_tag(&data);
asn1_start_tag(&data, ASN1_CONTEXT(1));
- asn1_read_OctetString(&data, &pac_contents);
+ asn1_read_OctetString(&data, NULL, &pac_contents);
asn1_end_tag(&data);
asn1_end_tag(&data);
asn1_end_tag(&data);
diff --git a/source3/libsmb/clispnego.c b/source3/libsmb/clispnego.c
index fa9dba098f..d45213cd9e 100644
--- a/source3/libsmb/clispnego.c
+++ b/source3/libsmb/clispnego.c
@@ -123,7 +123,7 @@ DATA_BLOB gen_negTokenInit(const char *OID, DATA_BLOB blob)
OIDs (the mechanisms) and a principal name string
*/
bool spnego_parse_negTokenInit(DATA_BLOB blob,
- char *OIDs[ASN1_MAX_OIDS],
+ char *OIDs[ASN1_MAX_OIDS],
char **principal)
{
int i;
@@ -140,8 +140,8 @@ bool spnego_parse_negTokenInit(DATA_BLOB blob,
asn1_start_tag(&data,ASN1_CONTEXT(0));
asn1_start_tag(&data,ASN1_SEQUENCE(0));
for (i=0; asn1_tag_remaining(&data) > 0 && i < ASN1_MAX_OIDS-1; i++) {
- char *oid_str = NULL;
- asn1_read_OID(&data,&oid_str);
+ const char *oid_str = NULL;
+ asn1_read_OID(&data,NULL,&oid_str);
OIDs[i] = oid_str;
}
OIDs[i] = NULL;
@@ -153,7 +153,7 @@ bool spnego_parse_negTokenInit(DATA_BLOB blob,
asn1_start_tag(&data, ASN1_CONTEXT(3));
asn1_start_tag(&data, ASN1_SEQUENCE(0));
asn1_start_tag(&data, ASN1_CONTEXT(0));
- asn1_read_GeneralString(&data,principal);
+ asn1_read_GeneralString(&data,NULL,principal);
asn1_end_tag(&data);
asn1_end_tag(&data);
asn1_end_tag(&data);
@@ -167,9 +167,9 @@ bool spnego_parse_negTokenInit(DATA_BLOB blob,
ret = !data.has_error;
if (data.has_error) {
int j;
- SAFE_FREE(*principal);
+ TALLOC_FREE(*principal);
for(j = 0; j < i && j < ASN1_MAX_OIDS-1; j++) {
- SAFE_FREE(OIDs[j]);
+ TALLOC_FREE(OIDs[j]);
}
}
@@ -224,7 +224,7 @@ DATA_BLOB gen_negTokenTarg(const char *OIDs[], DATA_BLOB blob)
/*
parse a negTokenTarg packet giving a list of OIDs and a security blob
*/
-bool parse_negTokenTarg(DATA_BLOB blob, char *OIDs[ASN1_MAX_OIDS], DATA_BLOB *secblob)
+bool parse_negTokenTarg(DATA_BLOB blob, const char *OIDs[ASN1_MAX_OIDS], DATA_BLOB *secblob)
{
int i;
ASN1_DATA data;
@@ -238,8 +238,8 @@ bool parse_negTokenTarg(DATA_BLOB blob, char *OIDs[ASN1_MAX_OIDS], DATA_BLOB *se
asn1_start_tag(&data, ASN1_CONTEXT(0));
asn1_start_tag(&data, ASN1_SEQUENCE(0));
for (i=0; asn1_tag_remaining(&data) > 0 && i < ASN1_MAX_OIDS-1; i++) {
- char *oid_str = NULL;
- asn1_read_OID(&data,&oid_str);
+ const char *oid_str = NULL;
+ asn1_read_OID(&data,NULL,&oid_str);
OIDs[i] = oid_str;
}
OIDs[i] = NULL;
@@ -247,7 +247,7 @@ bool parse_negTokenTarg(DATA_BLOB blob, char *OIDs[ASN1_MAX_OIDS], DATA_BLOB *se
asn1_end_tag(&data);
/* Skip any optional req_flags that are sent per RFC 4178 */
- if (asn1_check_tag(&data, ASN1_CONTEXT(1))) {
+ if (asn1_peek_tag(&data, ASN1_CONTEXT(1))) {
uint8 flags;
asn1_start_tag(&data, ASN1_CONTEXT(1));
@@ -259,7 +259,7 @@ bool parse_negTokenTarg(DATA_BLOB blob, char *OIDs[ASN1_MAX_OIDS], DATA_BLOB *se
}
asn1_start_tag(&data, ASN1_CONTEXT(2));
- asn1_read_OctetString(&data,secblob);
+ asn1_read_OctetString(&data,NULL,secblob);
asn1_end_tag(&data);
asn1_end_tag(&data);
@@ -271,7 +271,7 @@ bool parse_negTokenTarg(DATA_BLOB blob, char *OIDs[ASN1_MAX_OIDS], DATA_BLOB *se
int j;
data_blob_free(secblob);
for(j = 0; j < i && j < ASN1_MAX_OIDS-1; j++) {
- SAFE_FREE(OIDs[j]);
+ TALLOC_FREE(OIDs[j]);
}
DEBUG(1,("Failed to parse negTokenTarg at offset %d\n", (int)data.ofs));
asn1_free(&data);
@@ -407,13 +407,13 @@ bool spnego_parse_challenge(const DATA_BLOB blob,
asn1_end_tag(&data);
asn1_start_tag(&data,ASN1_CONTEXT(2));
- asn1_read_OctetString(&data, chal1);
+ asn1_read_OctetString(&data, NULL, chal1);
asn1_end_tag(&data);
/* the second challenge is optional (XP doesn't send it) */
if (asn1_tag_remaining(&data)) {
asn1_start_tag(&data,ASN1_CONTEXT(3));
- asn1_read_OctetString(&data, chal2);
+ asn1_read_OctetString(&data, NULL, chal2);
asn1_end_tag(&data);
}
@@ -468,7 +468,7 @@ bool spnego_parse_auth(DATA_BLOB blob, DATA_BLOB *auth)
asn1_start_tag(&data, ASN1_CONTEXT(1));
asn1_start_tag(&data, ASN1_SEQUENCE(0));
asn1_start_tag(&data, ASN1_CONTEXT(2));
- asn1_read_OctetString(&data,auth);
+ asn1_read_OctetString(&data, NULL, auth);
asn1_end_tag(&data);
asn1_end_tag(&data);
asn1_end_tag(&data);
@@ -564,7 +564,7 @@ bool spnego_parse_auth_response(DATA_BLOB blob, NTSTATUS nt_status,
if (asn1_tag_remaining(&data)) {
asn1_start_tag(&data,ASN1_CONTEXT(2));
- asn1_read_OctetString(&data, auth);
+ asn1_read_OctetString(&data, NULL, auth);
asn1_end_tag(&data);
}
} else if (negResult == SPNEGO_NEG_RESULT_INCOMPLETE) {
@@ -578,7 +578,7 @@ bool spnego_parse_auth_response(DATA_BLOB blob, NTSTATUS nt_status,
if (asn1_tag_remaining(&data)) {
DATA_BLOB mechList = data_blob_null;
asn1_start_tag(&data, ASN1_CONTEXT(3));
- asn1_read_OctetString(&data, &mechList);
+ asn1_read_OctetString(&data, NULL, &mechList);
asn1_end_tag(&data);
data_blob_free(&mechList);
DEBUG(5,("spnego_parse_auth_response received mechListMIC, "
diff --git a/source3/libsmb/spnego.c b/source3/libsmb/spnego.c
index 57b2d8060b..70fd441c9e 100644
--- a/source3/libsmb/spnego.c
+++ b/source3/libsmb/spnego.c
@@ -41,17 +41,17 @@ static bool read_negTokenInit(ASN1_DATA *asn1, negTokenInit_t *token)
asn1_start_tag(asn1, ASN1_CONTEXT(0));
asn1_start_tag(asn1, ASN1_SEQUENCE(0));
- token->mechTypes = SMB_MALLOC_P(const char *);
+ token->mechTypes = TALLOC_P(NULL, const char *);
for (i = 0; !asn1->has_error &&
0 < asn1_tag_remaining(asn1); i++) {
- char *p_oid = NULL;
+ const char *p_oid = NULL;
token->mechTypes =
- SMB_REALLOC_ARRAY(token->mechTypes, const char *, i + 2);
+ TALLOC_REALLOC_ARRAY(token->mechTypes, const char *, i + 2);
if (!token->mechTypes) {
asn1->has_error = True;
return False;
}
- asn1_read_OID(asn1, &p_oid);
+ asn1_read_OID(asn1, NULL, &p_oid);
token->mechTypes[i] = p_oid;
}
token->mechTypes[i] = NULL;
@@ -69,14 +69,14 @@ static bool read_negTokenInit(ASN1_DATA *asn1, negTokenInit_t *token)
/* Read mechToken */
case ASN1_CONTEXT(2):
asn1_start_tag(asn1, ASN1_CONTEXT(2));
- asn1_read_OctetString(asn1, &token->mechToken);
+ asn1_read_OctetString(asn1, NULL, &token->mechToken);
asn1_end_tag(asn1);
break;
/* Read mecListMIC */
case ASN1_CONTEXT(3):
asn1_start_tag(asn1, ASN1_CONTEXT(3));
if (asn1->data[asn1->ofs] == ASN1_OCTET_STRING) {
- asn1_read_OctetString(asn1,
+ asn1_read_OctetString(asn1, NULL,
&token->mechListMIC);
} else {
/* RFC 2478 says we have an Octet String here,
@@ -84,13 +84,13 @@ static bool read_negTokenInit(ASN1_DATA *asn1, negTokenInit_t *token)
char *mechListMIC;
asn1_push_tag(asn1, ASN1_SEQUENCE(0));
asn1_push_tag(asn1, ASN1_CONTEXT(0));
- asn1_read_GeneralString(asn1, &mechListMIC);
+ asn1_read_GeneralString(asn1, NULL, &mechListMIC);
asn1_pop_tag(asn1);
asn1_pop_tag(asn1);
token->mechListMIC =
data_blob(mechListMIC, strlen(mechListMIC));
- SAFE_FREE(mechListMIC);
+ TALLO_FREE(mechListMIC);
}
asn1_end_tag(asn1);
break;
@@ -187,17 +187,17 @@ static bool read_negTokenTarg(ASN1_DATA *asn1, negTokenTarg_t *token)
break;
case ASN1_CONTEXT(1):
asn1_start_tag(asn1, ASN1_CONTEXT(1));
- asn1_read_OID(asn1, &token->supportedMech);
+ asn1_read_OID(asn1, NULL, &token->supportedMech);
asn1_end_tag(asn1);
break;
case ASN1_CONTEXT(2):
asn1_start_tag(asn1, ASN1_CONTEXT(2));
- asn1_read_OctetString(asn1, &token->responseToken);
+ asn1_read_OctetString(asn1, NULL, &token->responseToken);
asn1_end_tag(asn1);
break;
case ASN1_CONTEXT(3):
asn1_start_tag(asn1, ASN1_CONTEXT(3));
- asn1_read_OctetString(asn1, &token->mechListMIC);
+ asn1_read_OctetString(asn1, NULL, &token->mechListMIC);
asn1_end_tag(asn1);
break;
default:
@@ -322,16 +322,16 @@ bool free_spnego_data(SPNEGO_DATA *spnego)
if (spnego->negTokenInit.mechTypes) {
int i;
for (i = 0; spnego->negTokenInit.mechTypes[i]; i++) {
- free(CONST_DISCARD(char *,spnego->negTokenInit.mechTypes[i]));
+ talloc_free(CONST_DISCARD(char *,spnego->negTokenInit.mechTypes[i]));
}
- free(spnego->negTokenInit.mechTypes);
+ talloc_free(spnego->negTokenInit.mechTypes);
}
data_blob_free(&spnego->negTokenInit.mechToken);
data_blob_free(&spnego->negTokenInit.mechListMIC);
break;
case SPNEGO_NEG_TOKEN_TARG:
if (spnego->negTokenTarg.supportedMech) {
- free(spnego->negTokenTarg.supportedMech);
+ talloc_free(spnego->negTokenTarg.supportedMech);
}
data_blob_free(&spnego->negTokenTarg.responseToken);
data_blob_free(&spnego->negTokenTarg.mechListMIC);
diff --git a/source3/rpc_server/srv_pipe.c b/source3/rpc_server/srv_pipe.c
index be7d3db444..2c31d7b3f1 100644
--- a/source3/rpc_server/srv_pipe.c
+++ b/source3/rpc_server/srv_pipe.c
@@ -1168,7 +1168,7 @@ static bool pipe_spnego_auth_bind_negotiate(pipes_struct *p, prs_struct *rpc_in_
for (i=0;OIDs[i];i++) {
DEBUG(3,("pipe_spnego_auth_bind_negotiate: Got OID %s\n", OIDs[i]));
- SAFE_FREE(OIDs[i]);
+ TALLOC_FREE(OIDs[i]);
}
DEBUG(3,("pipe_spnego_auth_bind_negotiate: Got secblob of size %lu\n", (unsigned long)secblob.length));
diff --git a/source3/smbd/sesssetup.c b/source3/smbd/sesssetup.c
index 845bf75310..c0a4696754 100644
--- a/source3/smbd/sesssetup.c
+++ b/source3/smbd/sesssetup.c
@@ -746,7 +746,7 @@ NTSTATUS parse_spnego_mechanisms(DATA_BLOB blob_in,
for (i=0;OIDs[i];i++) {
DEBUG(5,("parse_spnego_mechanisms: Got OID %s\n", OIDs[i]));
- free(OIDs[i]);
+ talloc_free(OIDs[i]);
}
return ret;
}