libaddns/dns.h

説明を見る。
00001 /*
00002   Linux DNS client library implementation
00003 
00004   Copyright (C) 2006 Krishna Ganugapati <krishnag@centeris.com>
00005   Copyright (C) 2006 Gerald Carter <jerry@samba.org>
00006 
00007      ** NOTE! The following LGPL license applies to the libaddns
00008      ** library. This does NOT imply that all of Samba is released
00009      ** under the LGPL
00010 
00011   This library is free software; you can redistribute it and/or
00012   modify it under the terms of the GNU Lesser General Public
00013   License as published by the Free Software Foundation; either
00014   version 2.1 of the License, or (at your option) any later version.
00015 
00016   This library is distributed in the hope that it will be useful,
00017   but WITHOUT ANY WARRANTY; without even the implied warranty of
00018   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019   Lesser General Public License for more details.
00020 
00021   You should have received a copy of the GNU Lesser General Public
00022   License along with this library; if not, write to the Free Software
00023   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  
00024   02110-1301  USA
00025 */
00026 
00027 #ifndef _DNS_H
00028 #define _DNS_H
00029 
00030 #include "config.h"
00031 
00032 #include <stdio.h>
00033 #include <stdlib.h>
00034 #include <fcntl.h>
00035 #include <time.h>
00036 #include <string.h>
00037 #include <errno.h>
00038 #include <netdb.h>
00039 #include <sys/types.h>
00040 #include <sys/socket.h>
00041 #include <netinet/in.h>
00042 #include <arpa/inet.h>
00043 #include <stdarg.h>
00044 
00045 #ifdef HAVE_UUID_UUID_H
00046 #include <uuid/uuid.h>
00047 #endif
00048 
00049 #ifdef HAVE_KRB5_H
00050 #include <krb5.h>
00051 #endif
00052 
00053 #ifdef HAVE_INTTYPES_H
00054 #include <inttypes.h>
00055 
00056 #ifndef int16
00057 #define int16 int16_t
00058 #endif
00059 
00060 #ifndef uint16
00061 #define uint16 uint16_t
00062 #endif
00063 
00064 #ifndef int32
00065 #define int32 int32_t
00066 #endif
00067 
00068 #ifndef uint32
00069 #define uint32 uint32_t
00070 #endif
00071 #endif
00072 
00073 #ifdef HAVE_KRB5_H
00074 #include <krb5.h>
00075 #endif
00076 
00077 #if HAVE_GSSAPI_H
00078 #include <gssapi.h>
00079 #elif HAVE_GSSAPI_GSSAPI_H
00080 #include <gssapi/gssapi.h>
00081 #elif HAVE_GSSAPI_GSSAPI_GENERIC_H
00082 #include <gssapi/gssapi_generic.h>
00083 #endif
00084 
00085 #if defined(HAVE_GSSAPI_H) || defined(HAVE_GSSAPI_GSSAPI_H) || defined(HAVE_GSSAPI_GSSAPI_GENERIC_H)
00086 #define HAVE_GSSAPI_SUPPORT    1
00087 #endif
00088 
00089 #include <talloc.h>
00090 
00091 void *_talloc_zero_zeronull(const void *ctx, size_t size, const char *name);
00092 void *_talloc_memdup_zeronull(const void *t, const void *p, size_t size, const char *name);
00093 void *_talloc_array_zeronull(const void *ctx, size_t el_size, unsigned count, const char *name);
00094 void *_talloc_zero_array_zeronull(const void *ctx, size_t el_size, unsigned count, const char *name);
00095 void *talloc_zeronull(const void *context, size_t size, const char *name);
00096 
00097 #define TALLOC(ctx, size) talloc_zeronull(ctx, size, __location__)
00098 #define TALLOC_P(ctx, type) (type *)talloc_zeronull(ctx, sizeof(type), #type)
00099 #define TALLOC_ARRAY(ctx, type, count) (type *)_talloc_array_zeronull(ctx, sizeof(type), count, #type)
00100 #define TALLOC_MEMDUP(ctx, ptr, size) _talloc_memdup_zeronull(ctx, ptr, size, __location__)
00101 #define TALLOC_ZERO(ctx, size) _talloc_zero_zeronull(ctx, size, __location__)
00102 #define TALLOC_ZERO_P(ctx, type) (type *)_talloc_zero_zeronull(ctx, sizeof(type), #type)
00103 #define TALLOC_ZERO_ARRAY(ctx, type, count) (type *)_talloc_zero_array_zeronull(ctx, sizeof(type), count, #type)
00104 #define TALLOC_REALLOC(ctx, ptr, count) _talloc_realloc(ctx, ptr, count, __location__)
00105 #define TALLOC_REALLOC_ARRAY(ctx, ptr, type, count) (type *)_talloc_realloc_array(ctx, ptr, sizeof(type), count, #type)
00106 #define talloc_destroy(ctx) talloc_free(ctx)
00107 #define TALLOC_FREE(ctx) do { if ((ctx) != NULL) {talloc_free(ctx); ctx=NULL;} } while(0)
00108 #define TALLOC_SIZE(ctx, size) talloc_zeronull(ctx, size, __location__)
00109 #define TALLOC_ZERO_SIZE(ctx, size) _talloc_zero_zeronull(ctx, size, __location__)
00110 
00111 /*******************************************************************
00112    Type definitions for int16, int32, uint16 and uint32.  Needed
00113    for Samba coding style
00114 *******************************************************************/
00115 
00116 #ifndef uint8
00117 #  define uint8 unsigned char
00118 #endif
00119 
00120 #if !defined(int16) && !defined(HAVE_INT16_FROM_RPC_RPC_H)
00121 #  if (SIZEOF_SHORT == 4)
00122 #    define int16 __ERROR___CANNOT_DETERMINE_TYPE_FOR_INT16;
00123 #  else /* SIZEOF_SHORT != 4 */
00124 #    define int16 short
00125 #  endif /* SIZEOF_SHORT != 4 */
00126    /* needed to work around compile issue on HP-UX 11.x */
00127 #  define _INT16        1
00128 #endif
00129 
00130 /*
00131  * Note we duplicate the size tests in the unsigned
00132  * case as int16 may be a typedef from rpc/rpc.h
00133  */
00134 
00135 #if !defined(uint16) && !defined(HAVE_UINT16_FROM_RPC_RPC_H)
00136 #  if (SIZEOF_SHORT == 4)
00137 #    define uint16 __ERROR___CANNOT_DETERMINE_TYPE_FOR_INT16;
00138 #  else /* SIZEOF_SHORT != 4 */
00139 #    define uint16 unsigned short
00140 #  endif /* SIZEOF_SHORT != 4 */
00141 #endif
00142 
00143 #if !defined(int32) && !defined(HAVE_INT32_FROM_RPC_RPC_H)
00144 #  if (SIZEOF_INT == 4)
00145 #    define int32 int
00146 #  elif (SIZEOF_LONG == 4)
00147 #    define int32 long
00148 #  elif (SIZEOF_SHORT == 4)
00149 #    define int32 short
00150 #  else
00151      /* uggh - no 32 bit type?? probably a CRAY. just hope this works ... */
00152 #    define int32 int
00153 #  endif
00154    /* needed to work around compile issue on HP-UX 11.x */
00155 #  define _INT32        1
00156 #endif
00157 
00158 /*
00159  * Note we duplicate the size tests in the unsigned
00160  * case as int32 may be a typedef from rpc/rpc.h
00161  */
00162 
00163 #if !defined(uint32) && !defined(HAVE_UINT32_FROM_RPC_RPC_H)
00164 #  if (SIZEOF_INT == 4)
00165 #    define uint32 unsigned int
00166 #  elif (SIZEOF_LONG == 4)
00167 #    define uint32 unsigned long
00168 #  elif (SIZEOF_SHORT == 4)
00169 #    define uint32 unsigned short
00170 #  else
00171       /* uggh - no 32 bit type?? probably a CRAY. just hope this works ... */
00172 #    define uint32 unsigned
00173 #  endif
00174 #endif
00175 
00176 /*
00177  * check for 8 byte long long
00178  */
00179 
00180 #if !defined(uint64)
00181 #  if (SIZEOF_LONG == 8)
00182 #    define uint64 unsigned long
00183 #  elif (SIZEOF_LONG_LONG == 8)
00184 #    define uint64 unsigned long long
00185 #  endif /* don't lie.  If we don't have it, then don't use it */
00186 #endif
00187 
00188 /* needed on Sun boxes */
00189 #ifndef INADDR_NONE
00190 #define INADDR_NONE          0xFFFFFFFF
00191 #endif
00192 
00193 #include "dnserr.h"
00194 
00195 
00196 #define DNS_TCP                 1
00197 #define DNS_UDP                 2
00198 
00199 #define DNS_OPCODE_UPDATE       1
00200 
00201 /* DNS Class Types */
00202 
00203 #define DNS_CLASS_IN            1
00204 #define DNS_CLASS_ANY           255
00205 #define DNS_CLASS_NONE          254
00206 
00207 /* DNS RR Types */
00208 
00209 #define DNS_RR_A                1
00210 
00211 #define DNS_TCP_PORT            53
00212 #define DNS_UDP_PORT            53
00213 
00214 #define QTYPE_A         1
00215 #define QTYPE_NS        2
00216 #define QTYPE_MD        3
00217 #define QTYPE_CNAME     5
00218 #define QTYPE_SOA       6
00219 #define QTYPE_ANY       255
00220 #define QTYPE_TKEY      249
00221 #define QTYPE_TSIG      250
00222 
00223 /*
00224 MF              4 a mail forwarder (Obsolete - use MX)
00225 CNAME           5 the canonical name for an alias
00226 SOA             6 marks the start of a zone of authority
00227 MB              7 a mailbox domain name (EXPERIMENTAL)
00228 MG              8 a mail group member (EXPERIMENTAL)
00229 MR              9 a mail rename domain name (EXPERIMENTAL)
00230 NULL            10 a null RR (EXPERIMENTAL)
00231 WKS             11 a well known service description
00232 PTR             12 a domain name pointer
00233 HINFO           13 host information
00234 MINFO           14 mailbox or mail list information
00235 MX              15 mail exchange
00236 TXT             16 text strings
00237 */
00238 
00239 #define QR_QUERY         0x0000
00240 #define QR_RESPONSE      0x0001
00241 
00242 #define OPCODE_QUERY 0x00
00243 #define OPCODE_IQUERY   0x01
00244 #define OPCODE_STATUS   0x02
00245 
00246 #define AA                      1
00247 
00248 #define RECURSION_DESIRED       0x01
00249 
00250 #define RCODE_NOERROR          0
00251 #define RCODE_FORMATERROR      1
00252 #define RCODE_SERVER_FAILURE   2
00253 #define RCODE_NAME_ERROR       3
00254 #define RCODE_NOTIMPLEMENTED   4
00255 #define RCODE_REFUSED          5
00256 
00257 #define SENDBUFFER_SIZE         65536
00258 #define RECVBUFFER_SIZE         65536
00259 
00260 /*
00261  * TKEY Modes from rfc2930
00262  */
00263 
00264 #define DNS_TKEY_MODE_SERVER   1
00265 #define DNS_TKEY_MODE_DH       2
00266 #define DNS_TKEY_MODE_GSSAPI   3
00267 #define DNS_TKEY_MODE_RESOLVER 4
00268 #define DNS_TKEY_MODE_DELETE   5
00269 
00270 
00271 #define DNS_ONE_DAY_IN_SECS     86400
00272 #define DNS_TEN_HOURS_IN_SECS   36000
00273 
00274 #define SOCKET_ERROR            -1
00275 #define INVALID_SOCKET          -1
00276 
00277 #define  DNS_NO_ERROR           0
00278 #define  DNS_FORMAT_ERROR       1
00279 #define  DNS_SERVER_FAILURE     2
00280 #define  DNS_NAME_ERROR         3
00281 #define  DNS_NOT_IMPLEMENTED    4
00282 #define  DNS_REFUSED            5
00283 
00284 typedef long HANDLE;
00285 
00286 #ifndef _UPPER_BOOL
00287 typedef int BOOL;
00288 #define _UPPER_BOOL
00289 #endif
00290 
00291 
00292 enum dns_ServerType { DNS_SRV_ANY, DNS_SRV_WIN2000, DNS_SRV_WIN2003 };
00293 
00294 struct dns_domain_label {
00295         struct dns_domain_label *next;
00296         char *label;
00297         size_t len;
00298 };
00299 
00300 struct dns_domain_name {
00301         struct dns_domain_label *pLabelList;
00302 };
00303 
00304 struct dns_question {
00305         struct dns_domain_name *name;
00306         uint16 q_type;
00307         uint16 q_class;
00308 };
00309 
00310 /*
00311  * Before changing the definition of dns_zone, look
00312  * dns_marshall_update_request(), we rely on this being the same as
00313  * dns_question right now.
00314  */
00315 
00316 struct dns_zone {
00317         struct dns_domain_name *name;
00318         uint16 z_type;
00319         uint16 z_class;
00320 };
00321 
00322 struct dns_rrec {
00323         struct dns_domain_name *name;
00324         uint16 type;
00325         uint16 r_class;
00326         uint32 ttl;
00327         uint16 data_length;
00328         uint8 *data;
00329 };
00330 
00331 struct dns_tkey_record {
00332         struct dns_domain_name *algorithm;
00333         time_t inception;
00334         time_t expiration;
00335         uint16 mode;
00336         uint16 error;
00337         uint16 key_length;
00338         uint8 *key;
00339 };
00340 
00341 struct dns_request {
00342         uint16 id;
00343         uint16 flags;
00344         uint16 num_questions;
00345         uint16 num_answers;
00346         uint16 num_auths;
00347         uint16 num_additionals;
00348         struct dns_question **questions;
00349         struct dns_rrec **answers;
00350         struct dns_rrec **auths;
00351         struct dns_rrec **additionals;
00352 };
00353 
00354 /*
00355  * Before changing the definition of dns_update_request, look
00356  * dns_marshall_update_request(), we rely on this being the same as
00357  * dns_request right now.
00358  */
00359 
00360 struct dns_update_request {
00361         uint16 id;
00362         uint16 flags;
00363         uint16 num_zones;
00364         uint16 num_preqs;
00365         uint16 num_updates;
00366         uint16 num_additionals;
00367         struct dns_zone **zones;
00368         struct dns_rrec **preqs;
00369         struct dns_rrec **updates;
00370         struct dns_rrec **additionals;
00371 };
00372 
00373 struct dns_connection {
00374         int32 hType;
00375         int s;
00376         struct sockaddr RecvAddr;
00377 };
00378 
00379 struct dns_buffer {
00380         uint8 *data;
00381         size_t size;
00382         size_t offset;
00383         DNS_ERROR error;
00384 };
00385 
00386 /* from dnsutils.c */
00387 
00388 DNS_ERROR dns_domain_name_from_string( TALLOC_CTX *mem_ctx,
00389                                        const char *pszDomainName,
00390                                        struct dns_domain_name **presult );
00391 char *dns_generate_keyname( TALLOC_CTX *mem_ctx );
00392 
00393 /* from dnsrecord.c */
00394 
00395 DNS_ERROR dns_create_query( TALLOC_CTX *mem_ctx, const char *name,
00396                             uint16 q_type, uint16 q_class,
00397                             struct dns_request **preq );
00398 DNS_ERROR dns_create_update( TALLOC_CTX *mem_ctx, const char *name,
00399                              struct dns_update_request **preq );
00400 DNS_ERROR dns_create_probe(TALLOC_CTX *mem_ctx, const char *zone,
00401                            const char *host, int num_ips,
00402                            const struct in_addr *iplist,
00403                            struct dns_update_request **preq);
00404 DNS_ERROR dns_create_rrec(TALLOC_CTX *mem_ctx, const char *name,
00405                           uint16 type, uint16 r_class, uint32 ttl,
00406                           uint16 data_length, uint8 *data,
00407                           struct dns_rrec **prec);
00408 DNS_ERROR dns_add_rrec(TALLOC_CTX *mem_ctx, struct dns_rrec *rec,
00409                        uint16 *num_records, struct dns_rrec ***records);
00410 DNS_ERROR dns_create_tkey_record(TALLOC_CTX *mem_ctx, const char *keyname,
00411                                  const char *algorithm_name, time_t inception,
00412                                  time_t expiration, uint16 mode, uint16 error,
00413                                  uint16 key_length, const uint8 *key,
00414                                  struct dns_rrec **prec);
00415 DNS_ERROR dns_create_name_in_use_record(TALLOC_CTX *mem_ctx,
00416                                         const char *name,
00417                                         const struct in_addr *ip,
00418                                         struct dns_rrec **prec);
00419 DNS_ERROR dns_create_delete_record(TALLOC_CTX *mem_ctx, const char *name,
00420                                    uint16 type, uint16 r_class,
00421                                    struct dns_rrec **prec);
00422 DNS_ERROR dns_create_name_not_in_use_record(TALLOC_CTX *mem_ctx,
00423                                             const char *name, uint32 type,
00424                                             struct dns_rrec **prec);
00425 DNS_ERROR dns_create_a_record(TALLOC_CTX *mem_ctx, const char *host,
00426                               uint32 ttl, struct in_addr ip,
00427                               struct dns_rrec **prec);
00428 DNS_ERROR dns_unmarshall_tkey_record(TALLOC_CTX *mem_ctx, struct dns_rrec *rec,
00429                                      struct dns_tkey_record **ptkey);
00430 DNS_ERROR dns_create_tsig_record(TALLOC_CTX *mem_ctx, const char *keyname,
00431                                  const char *algorithm_name,
00432                                  time_t time_signed, uint16 fudge,
00433                                  uint16 mac_length, const uint8 *mac,
00434                                  uint16 original_id, uint16 error,
00435                                  struct dns_rrec **prec);
00436 DNS_ERROR dns_add_rrec(TALLOC_CTX *mem_ctx, struct dns_rrec *rec,
00437                        uint16 *num_records, struct dns_rrec ***records);
00438 
00439 /* from dnssock.c */
00440 
00441 DNS_ERROR dns_open_connection( const char *nameserver, int32 dwType,
00442                     TALLOC_CTX *mem_ctx,
00443                     struct dns_connection **conn );
00444 DNS_ERROR dns_send(struct dns_connection *conn, const struct dns_buffer *buf);
00445 DNS_ERROR dns_receive(TALLOC_CTX *mem_ctx, struct dns_connection *conn,
00446                       struct dns_buffer **presult);
00447 DNS_ERROR dns_transaction(TALLOC_CTX *mem_ctx, struct dns_connection *conn,
00448                           const struct dns_request *req,
00449                           struct dns_request **resp);
00450 DNS_ERROR dns_update_transaction(TALLOC_CTX *mem_ctx,
00451                                  struct dns_connection *conn,
00452                                  struct dns_update_request *up_req,
00453                                  struct dns_update_request **up_resp);
00454 
00455 /* from dnsmarshall.c */
00456 
00457 struct dns_buffer *dns_create_buffer(TALLOC_CTX *mem_ctx);
00458 void dns_marshall_buffer(struct dns_buffer *buf, const uint8 *data,
00459                          size_t len);
00460 void dns_marshall_uint16(struct dns_buffer *buf, uint16 val);
00461 void dns_marshall_uint32(struct dns_buffer *buf, uint32 val);
00462 void dns_unmarshall_buffer(struct dns_buffer *buf, uint8 *data,
00463                            size_t len);
00464 void dns_unmarshall_uint16(struct dns_buffer *buf, uint16 *val);
00465 void dns_unmarshall_uint32(struct dns_buffer *buf, uint32 *val);
00466 void dns_unmarshall_domain_name(TALLOC_CTX *mem_ctx,
00467                                 struct dns_buffer *buf,
00468                                 struct dns_domain_name **pname);
00469 void dns_marshall_domain_name(struct dns_buffer *buf,
00470                               const struct dns_domain_name *name);
00471 void dns_unmarshall_domain_name(TALLOC_CTX *mem_ctx,
00472                                 struct dns_buffer *buf,
00473                                 struct dns_domain_name **pname);
00474 DNS_ERROR dns_marshall_request(TALLOC_CTX *mem_ctx,
00475                                const struct dns_request *req,
00476                                struct dns_buffer **pbuf);
00477 DNS_ERROR dns_unmarshall_request(TALLOC_CTX *mem_ctx,
00478                                  struct dns_buffer *buf,
00479                                  struct dns_request **preq);
00480 DNS_ERROR dns_marshall_update_request(TALLOC_CTX *mem_ctx,
00481                                       struct dns_update_request *update,
00482                                       struct dns_buffer **pbuf);
00483 DNS_ERROR dns_unmarshall_update_request(TALLOC_CTX *mem_ctx,
00484                                         struct dns_buffer *buf,
00485                                         struct dns_update_request **pupreq);
00486 struct dns_request *dns_update2request(struct dns_update_request *update);
00487 struct dns_update_request *dns_request2update(struct dns_request *request);
00488 uint16 dns_response_code(uint16 flags);
00489 
00490 /* from dnsgss.c */
00491 
00492 #ifdef HAVE_GSSAPI_SUPPORT
00493 
00494 void display_status( const char *msg, OM_uint32 maj_stat, OM_uint32 min_stat ); 
00495 DNS_ERROR dns_negotiate_sec_ctx( const char *target_realm,
00496                                  const char *servername,
00497                                  const char *keyname,
00498                                  gss_ctx_id_t *gss_ctx,
00499                                  enum dns_ServerType srv_type );
00500 DNS_ERROR dns_sign_update(struct dns_update_request *req,
00501                           gss_ctx_id_t gss_ctx,
00502                           const char *keyname,
00503                           const char *algorithmname,
00504                           time_t time_signed, uint16 fudge);
00505 DNS_ERROR dns_create_update_request(TALLOC_CTX *mem_ctx,
00506                                     const char *domainname,
00507                                     const char *hostname,
00508                                     const struct in_addr *ip_addr,
00509                                     size_t num_adds,
00510                                     struct dns_update_request **preq);
00511 
00512 #endif  /* HAVE_GSSAPI_SUPPORT */
00513 
00514 #endif  /* _DNS_H */

Sambaに対してSat Aug 29 21:23:00 2009に生成されました。  doxygen 1.4.7