/usr/include/dnscore/dnsname.h is in libyadifa-dev 2.1.6-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 | /*------------------------------------------------------------------------------
*
* Copyright (c) 2011-2016, EURid. All rights reserved.
* The YADIFA TM software product is provided under the BSD 3-clause license:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of EURid nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*------------------------------------------------------------------------------
*
*/
/** @defgroup dnscore
* @ingroup dnscore
* @brief Functions used to manipulate dns formatted names and labels
*
* DNS names are stored in many ways:
* _ C string : ASCII with a '\0' sentinel
* _ DNS wire : label_length_byte + label_bytes) ending with a label_length_byte with a value of 0
* _ simple array of pointers to labels
* _ simple stack of pointers to labels (so the same as above, but with the order reversed)
* _ sized array of pointers to labels
* _ sized stack of pointers to labels (so the same as above, but with the order reversed)
*
* @{
*/
#pragma once
#include <dnscore/sys_types.h>
#include <dnscore/rfc.h>
/**
* The maximum number of domains-subdomains handled by the database.
* This should not be set to a value greater than 128 (128 covers (\001 'a') * 255 )
*
* Recommended value: 128
*
*/
#define SRV_UNDERSCORE_SUPPORT 1
#define DNSNAME_MAX_SECTIONS ((MAX_DOMAIN_LENGTH + 1) / 2)
// dns equal chars comparison should give 0x00 or 0x20
// the '_' breaks this so there is a slightly different (slightly slower) way to handle it
// IMPORTANT NOTE 1 : MACROS ARE WRITTEN TO USE THEIR PARAMETERS EXACTLY ONCE
// IMPORTANT NOTE 2 : LOCASEEQUAL only works on the DNS chars AND with the first parameter being a lo-case string (like in the database)
#if SRV_UNDERSCORE_SUPPORT == 0
#define LOCASE(c__) ((char)(c__)|(char)0x20)
static inline bool LOCASEEQUALS(char ca__,char cb__)
{
return ((((char)(ca__)-(char)(cb__))&0xdf) == 0);
}
static inline bool LOCASEEQUALSBY2(const u8* name_a, const u8* name_b)
{
return (((GET_U16_AT(name_a[0]) - GET_U16_AT(name_b[0])) & ((u16)0xdfdf)) == 0);
}
static inline bool LOCASEEQUALSBY3(const u8* name_a, const u8* name_b)
{
return LOCASEEQUALSBY2(name_a, name_b) && LOCASEEQUALS(name_a[2], name_b[2]);
}
static inline bool LOCASEEQUALSBY4(const u8* name_a, const u8* name_b)
{
return (((GET_U32_AT(name_a[0]) - GET_U32_AT(name_b[0])) & ((u16)0xdfdfdfdf)) == 0);
}
#else // slightly modified to take '_' into account
#define LOCASE(c__) (((((char)(c__)+(char)0x01)|(char)0x20))-(char)0x01)
static inline bool LOCASEEQUALS(u8 a, u8 b)
{
return ((((u8)(a+0x01)-(u8)(b+0x01))&0xdf) == 0);
}
static inline bool LOCASEEQUALSBY2(const u8* name_a, const u8* name_b)
{
return (( ( (GET_U16_AT(name_a[0]) + 0x0101) - (GET_U16_AT(name_b[0]) + 0x0101)) & ((u16)0xdfdf)) == 0);
}
static inline bool LOCASEEQUALSBY3(const u8* name_a, const u8* name_b)
{
return LOCASEEQUALSBY2(name_a, name_b) && LOCASEEQUALS(name_a[2], name_b[2]);
}
static inline bool LOCASEEQUALSBY4(const u8* name_a, const u8* name_b)
{
return (( ( (GET_U32_AT(name_a[0]) + 0x01010101) - (GET_U32_AT(name_b[0]) + 0x01010101)) & ((u32)0xdfdfdfdf)) == 0);
}
#endif
#define ZDB_NAME_TAG 0x454d414e42445a /* "ZDBNAME" */
#define ZDB_LABEL_TAG 0x4c424c42445a /* "ZDBLBL" */
#ifdef __cplusplus
extern "C"
{
#endif
/*
* A dnslabel_array is basically a dnslabel*[]
* There are two kind of arrays :
*
* dnslabel_stack:
*
* [0000] "." label
* [0001] "tdl" label
* [0002] "domain" label <- top
*
* dnslabel_vector:
*
* [0000] "domain" label
* [0001] "tdl" label
* [0002] "." label <- top
*
*/
/*
* The plan was to typedef an array into a stack or a vector.
* But in order to help the compiler complaining about mixing both,
* I have to define them separatly
*
*/
typedef u8* dnslabel_stack[DNSNAME_MAX_SECTIONS];
/* This + 1 is just to make sure both are different to the compiler's eyes */
typedef u8* dnslabel_vector[DNSNAME_MAX_SECTIONS + 1];
typedef u8** dnslabel_stack_reference;
typedef u8** dnslabel_vector_reference;
typedef u8*const* const_dnslabel_stack_reference;
typedef u8*const* const_dnslabel_vector_reference;
#ifdef DEBUG
#define DEBUG_RESET_dnsname(name) memset(&(name),0x5b,sizeof(dnsname_stack))
#else
#define DEBUG_RESET_dnsname(name)
#endif
typedef struct dnsname_stack dnsname_stack;
struct dnsname_stack
{
s32 size;
dnslabel_stack labels;
};
typedef struct dnsname_vector dnsname_vector;
struct dnsname_vector
{
s32 size;
dnslabel_vector labels;
};
/*****************************************************************************
*
* BUFFER
*
*****************************************************************************/
/** @brief Converts a C string to a dns name.
*
* Converts a C string to a dns name.
*
* @param[in] name_parm a pointer to a buffer that will get the full dns name
* @param[in] str a pointer to the source c-string
*
* @return Returns the length of the string up to the last '\0'
*/
/* TWO use */
ya_result cstr_to_dnsname(u8* name_parm, const char* str);
/** @brief Converts a C string to a lower-case dns name.
*
* Converts a C string to a lower-case dns name.
*
* @param[in] name_parm a pointer to a buffer that will get the full dns name
* @param[in] str a pointer to the source c-string
*
* @return Returns the length of the string up to the last '\0'
*/
ya_result cstr_to_locase_dnsname(u8* name_parm, const char* str);
/** @brief Converts a text buffer to a dns name.
*
* Converts a text buffer to a dns name.
*
* @param[in] name_parm a pointer to a buffer that will get the full dns name
* @param[in] str a pointer to the source buffer
* @param[in] str_len the length of the source buffer
*
* @return Returns the length of the string up to the last '\0'
*/
ya_result charp_to_dnsname(u8* name_parm, const char* str, u32 str_len);
/** @brief Converts a text buffer to a lower-case dns name.
*
* Converts a text buffer to a lower-case dns name.
*
* @param[in] name_parm a pointer to a buffer that will get the full dns name
* @param[in] str a pointer to the source buffer
* @param[in] str_len the length of the source buffer
*
* @return Returns the length of the string up to the last '\0'
*/
ya_result charp_to_locase_dnsname(u8* name_parm, const char* str, u32 str_len);
/** @brief Converts a text buffer to a lower-case dns name and checks for validity
*
* Converts a text buffer to a lower-case dns name.
*
* @param[in] name_parm a pointer to a buffer that will get the full dns name
* @param[in] str a pointer to the source buffer
* @param[in] str_len the length of the source buffer
*
* @return Returns the length of the string up to the last '\0'
*/
ya_result charp_to_locase_dnsname_with_check(u8* name_parm, const char* str, u32 str_len);
/**
* @brief Converts a C string to a dns name and checks for validity
*
* Converts a C string to a dns name.
*
* @param[in] name_parm a pointer to a buffer that will get the full dns name
* @param[in] str a pointer to the source c-string
*
* @return Returns the length of the string up to the last '\0'
*/
ya_result cstr_to_dnsname_with_check(u8* name_parm, const char* str);
/**
* @brief Converts a C string to a dns rname and checks for validity
*
* Converts a C string to a dns rname.
*
* @param[in] name_parm a pointer to a buffer that will get the full dns name
* @param[in] str a pointer to the source c-string
*
* @return Returns the length of the string up to the last '\0'
*/
ya_result cstr_to_dnsrname_with_check(u8* name_parm, const char* str);
ya_result cstr_to_dnsname_with_check_len(u8* name_parm, const char* text, u32 text_len);
ya_result cstr_to_locase_dnsname_with_check_len(u8* name_parm, const char* text, u32 text_len);
ya_result cstr_to_dnsname_with_check_len_with_origin(u8* name_parm, const char* text, u32 text_len, const u8 *origin);
ya_result cstr_to_locase_dnsname_with_check_len_with_origin(u8* name_parm, const char* text, u32 text_len, const u8 *origin);
/* ONE use */
ya_result cstr_get_dnsname_len(const char* str);
/** @brief Converts a dns name to a C string
*
* Converts a dns name to a C string
*
* @param[in] name a pointer to the source dns name
* @param[in] str a pointer to a buffer that will get the c-string
*
* @return Returns the length of the string
*/
/* SIX uses */
u32 dnsname_to_cstr(char* str, const u8* name);
/** @brief Tests if two DNS labels are equals
*
* Tests if two DNS labels are equals
*
* @param[in] name_a a pointer to a dnsname to compare
* @param[in] name_b a pointer to a dnsname to compare
*
* @return Returns TRUE if names are equal, else FALSE.
*/
/* ELEVEN uses */
bool dnslabel_equals(const u8* name_a, const u8* name_b);
int dnsname_compare(const u8* name_a, const u8* name_b);
bool dnsname_is_subdomain(const u8* subdomain, const u8* domain);
/** @brief Tests if two DNS labels are (case-insensitive) equals
*
* Tests if two DNS labels are (case-insensitive) equals
*
* @param[in] name_a a pointer to a lo-case dnsname to compare
* @param[in] name_b a pointer to a any-case dnsname to compare
*
* @return Returns TRUE if names are equal, else FALSE.
*/
bool dnslabel_equals_ignorecase_left(const u8* name_a, const u8* name_b);
/** @brief Tests if two DNS names are equals
*
* Tests if two DNS labels are equals
*
* @param[in] name_a a pointer to a dnsname to compare
* @param[in] name_b a pointer to a dnsname to compare
*
* @return Returns TRUE if names are equal, else FALSE.
*/
/* TWO uses */
bool dnsname_equals(const u8* name_a, const u8* name_b);
/** @brief Tests if two DNS names are (ignore case) equals
*
* Tests if two DNS labels are (ignore case) equals
*
* @param[in] name_a a pointer to a dnsname to compare
* @param[in] name_b a pointer to a dnsname to compare
*
* @return Returns TRUE if names are equal, else FALSE.
*/
/* TWO uses */
bool dnsname_equals_ignorecase(const u8* name_a, const u8* name_b);
/** @brief Returns the full length of a dns name
*
* Returns the full length of a dns name
*
* @param[in] name a pointer to the dnsname
*
* @return The length of the dnsname, "." ( zero ) included
*/
/* SEVENTEEN uses (more or less) */
u32 dnsname_len(const u8* name);
/* ONE use */
u32 dnsname_getdepth(const u8* name);
/* ONE use */
u32 dnsname_copy(u8* dst, const u8* src);
/* malloc & copies a dnsname */
u8* dnsname_dup(const u8* src);
/** @brief Canonizes a dns name.
*
* Canonizes a dns name. (Lo-case)
*
* @param[in] src a pointer to the dns name
* @param[out] dst a pointer to a buffer that will hold the canonized dns name
*
* @return The length of the dns name
*/
/* TWELVE uses */
u32 dnsname_canonize(const u8* src, u8* dst);
/**
* char DNS charset test
*
* @param c
* @return TRUE iff c in in the DNS charset
*
*/
bool dnsname_is_charspace(u8 c);
/**
* label DNS charset test
*
* @param label
* @return TRUE iff each char in the label in in the DNS charset
*
*/
bool dnslabel_verify_charspace(const u8 *label);
/**
* dns name DNS charset test
*
* @param name_wire
* @return TRUE if each char in the name is in the DNS charset
*
*/
bool dnsname_verify_charspace(const u8 *name_wire);
/**
* label DNS charset test and set to lower case
*
* @param label
* @return TRUE iff each char in the label in in the DNS charset
*
*/
bool dnslabel_locase_verify_charspace(u8 *label);
/**
* dns name DNS charset test and set to lower case
*
* LOCASE is done using |32
*
* @param name_wire
* @return TRUE iff each char in the name in in the DNS charset
*
*/
bool dnsname_locase_verify_charspace(u8 *name_wire);
/**
* dns name DNS charset test and set to lower case
*
* LOCASE is done using tolower(c)
*
* @param name_wire
* @return TRUE iff each char in the name in in the DNS charset
*
*/
bool dnsname_locase_verify_extended_charspace(u8 *name_wire);
/*****************************************************************************
*
* VECTOR
*
*****************************************************************************/
/* ONE use */
u32 dnslabel_vector_to_cstr(const_dnslabel_vector_reference name, s32 top, char *str);
/* TWO use */
u32 dnslabel_vector_to_dnsname(const_dnslabel_vector_reference name, s32 top, u8 *str_start);
/* ONE use */
u32 dnslabel_vector_dnslabel_to_dnsname(const u8 *prefix, const dnsname_vector *namestack, s32 bottom, u8 *str);
static inline u32
dnslabel_copy(u8 *target, const u8 *src)
{
u32 len = src[0] + 1;
memcpy(target, src, len);
return len;
}
u32 dnslabel_vector_len(const_dnslabel_vector_reference name, s32 top);
/* ONE use */
u32 dnsname_vector_sub_to_dnsname(const dnsname_vector *name, s32 from, u8 *name_start);
/** @brief Divides a name into sections
*
* Divides a name into sections.
* Writes a pointer to each label of the dnsname into an array
* "." is never put in there.
*
* @param[in] name a pointer to the dnsname
* @param[out] sections a pointer to the target array of pointers
*
* @return The index of the top-level label ("." is never put in there)
*/
/* TWO uses */
s32 dnsname_to_dnslabel_vector(const u8* dns_name, dnslabel_vector_reference labels);
s32 dnsname_to_dnslabel_stack(const u8* dns_name, dnslabel_stack_reference labels);
/** @brief Divides a name into sections
*
* Divides a name into sections.
* Writes a pointer to each label of the dnsname into an array
* "." is never put in there.
*
* @param[in] name a pointer to the dnsname
* @param[out] sections a pointer to the target array of pointers
*
* @return The index of the top-level label ("." is never put in there)
*/
/* TWENTY-ONE uses */
s32 dnsname_to_dnsname_vector(const u8* dns_name, dnsname_vector* name);
u32 dnsname_vector_copy(dnsname_vector *dst, const dnsname_vector* src);
u32 dnsname_vector_len(dnsname_vector *name_vector);
/*****************************************************************************
*
* STACK
*
*****************************************************************************/
/** @brief Converts a stack of dns labels to a C string
*
* Converts a stack of dns labels to a C string
*
* @param[in] name a pointer to the dnslabel stack
* @param[in] top the index of the top of the stack
* @param[in] str a pointer to a buffer that will get the c-string
*
* @return Returns the length of the string
*/
/* ONE use */
u32 dnslabel_stack_to_cstr(const const_dnslabel_stack_reference name, s32 top, char* str);
/* ONE use */
u32 dnslabel_stack_to_dnsname(const const_dnslabel_stack_reference name, s32 top, u8* str_start);
/* ONE use */
u32 dnsname_stack_to_dnsname(const dnsname_stack* name_stack, u8* name_start);
/* ONE use, returns the fqdn len */
u32 dnsname_stack_len(const dnsname_stack* name_stack);
/* TWO uses (debug) */
u32 dnsname_stack_to_cstr(const dnsname_stack* name, char* str);
/* ONE use */
bool dnsname_equals_dnsname_stack(const u8* str, const dnsname_stack* name);
bool dnsname_under_dnsname_stack(const u8* str, const dnsname_stack* name);
/* FOUR uses */
s32 dnsname_stack_push_label(dnsname_stack* dns_name, u8* dns_label);
/* FOUR uses */
s32 dnsname_stack_pop_label(dnsname_stack* name);
s32 dnsname_to_dnsname_stack(const u8* dns_name, dnsname_stack* name);
/** @brief Allocates and duplicates a name with ZALLOC.
*
* Allocates and duplicates a name ZALLOC.
*
* @param[in] name a pointer to the dnsname
*
* @return A new instance of the dnsname.
*/
u8 *dnsname_zdup(const u8 *name);
void dnsname_zfree(u8 *name);
/** @brief Allocates and duplicates a label with ZALLOC.
*
* Allocates and duplicates a label with ZALLOC.
*
* @param[in] name a pointer to the label
*
* @return A new instance of the label
*/
u8 *dnslabel_zdup(const u8 *name);
void dnslabel_zfree(u8 *name);
#ifdef __cplusplus
}
#endif
/** @} */
|