libaddns: add dns_errstr().
authorGünther Deschner <gd@samba.org>
Fri, 19 Nov 2010 12:34:18 +0000 (13:34 +0100)
committerGünther Deschner <gd@samba.org>
Mon, 22 Nov 2010 10:25:18 +0000 (11:25 +0100)
Guenther

source3/Makefile.in
source3/libaddns/dns.h
source3/libaddns/error.c [new file with mode: 0644]
source3/libaddns/wscript_build

index 60361e7..faeb3e7 100644 (file)
@@ -497,7 +497,7 @@ PARAM_OBJ = $(PARAM_WITHOUT_REG_OBJ) $(PARAM_REG_ADD_OBJ)
 KRBCLIENT_OBJ = libads/kerberos.o libads/ads_status.o
 
 LIBADDNS_OBJ0 = libaddns/dnsrecord.o libaddns/dnsutils.o  libaddns/dnssock.o \
-              libaddns/dnsgss.o libaddns/dnsmarshall.o
+              libaddns/dnsgss.o libaddns/dnsmarshall.o libaddns/error.o
 LIBADDNS_OBJ = $(LIBADDNS_OBJ0) $(SOCKET_WRAPPER_OBJ)
 
 GPEXT_OBJ = ../libgpo/gpext/gpext.o @GPEXT_STATIC@
index 72cba07..29f1ed3 100644 (file)
@@ -517,6 +517,7 @@ DNS_ERROR dns_unmarshall_update_request(TALLOC_CTX *mem_ctx,
 struct dns_request *dns_update2request(struct dns_update_request *update);
 struct dns_update_request *dns_request2update(struct dns_request *request);
 uint16 dns_response_code(uint16 flags);
+const char *dns_errstr(DNS_ERROR err);
 
 /* from dnsgss.c */
 
diff --git a/source3/libaddns/error.c b/source3/libaddns/error.c
new file mode 100644 (file)
index 0000000..361388c
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+  Linux DNS client library implementation
+  Copyright (C) 2010 Guenther Deschner
+
+     ** NOTE! The following LGPL license applies to the libaddns
+     ** library. This does NOT imply that all of Samba is released
+     ** under the LGPL
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License as published by the Free Software Foundation; either
+  version 2.1 of the License, or (at your option) any later version.
+
+  This library 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
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "dns.h"
+#include "dnserr.h"
+
+typedef struct {
+       const char *dns_errstr;
+       DNS_ERROR dns_errcode;
+} dns_err_code_struct;
+
+static const dns_err_code_struct dns_errs[] =
+{
+       { "ERROR_DNS_SUCCESS", ERROR_DNS_SUCCESS },
+       { "ERROR_DNS_RECORD_NOT_FOUND", ERROR_DNS_RECORD_NOT_FOUND },
+       { "ERROR_DNS_BAD_RESPONSE", ERROR_DNS_BAD_RESPONSE },
+       { "ERROR_DNS_INVALID_PARAMETER", ERROR_DNS_INVALID_PARAMETER },
+       { "ERROR_DNS_NO_MEMORY", ERROR_DNS_NO_MEMORY },
+       { "ERROR_DNS_INVALID_NAME_SERVER", ERROR_DNS_INVALID_NAME_SERVER },
+       { "ERROR_DNS_CONNECTION_FAILED", ERROR_DNS_CONNECTION_FAILED },
+       { "ERROR_DNS_GSS_ERROR", ERROR_DNS_GSS_ERROR },
+       { "ERROR_DNS_INVALID_NAME", ERROR_DNS_INVALID_NAME },
+       { "ERROR_DNS_INVALID_MESSAGE", ERROR_DNS_INVALID_MESSAGE },
+       { "ERROR_DNS_SOCKET_ERROR", ERROR_DNS_SOCKET_ERROR },
+       { "ERROR_DNS_UPDATE_FAILED", ERROR_DNS_UPDATE_FAILED },
+       { NULL, ERROR_DNS_SUCCESS },
+};
+
+const char *dns_errstr(DNS_ERROR err)
+{
+       int i;
+
+       for (i=0; dns_errs[i].dns_errstr != NULL; i++) {
+               if (ERR_DNS_EQUAL(err, dns_errs[i].dns_errcode)) {
+                       return dns_errs[i].dns_errstr;
+               }
+       }
+
+       return NULL;
+}
index 63d7661..c4c83a9 100644 (file)
@@ -1,7 +1,7 @@
 #!/usr/bin/env python
 
 bld.SAMBA_LIBRARY('libaddns',
-                   source='dnsrecord.c dnsutils.c dnssock.c dnsgss.c dnsmarshall.c',
+                   source='dnsrecord.c dnsutils.c dnssock.c dnsgss.c dnsmarshall.c error.c',
                    public_deps='talloc krb5 k5crypto com_err gssapi gssapi_krb5',
                    private_library=True,
                    vars=locals())