Print this page
9886 libresolv2: fix fallthrough in ns_sprintrrf()
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libresolv2/common/nameser/ns_print.c
+++ new/usr/src/lib/libresolv2/common/nameser/ns_print.c
1 1 /*
2 2 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
3 3 * Copyright (c) 1996-1999 by Internet Software Consortium.
4 4 *
5 5 * Permission to use, copy, modify, and distribute this software for any
6 6 * purpose with or without fee is hereby granted, provided that the above
7 7 * copyright notice and this permission notice appear in all copies.
8 8 *
9 9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
10 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
12 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
15 15 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 16 */
17 17
18 18 #include "port_before.h"
19 19
20 20 #include <sys/types.h>
21 21 #include <sys/socket.h>
22 22
23 23 #include <netinet/in.h>
24 24 #include <arpa/nameser.h>
25 25 #include <arpa/inet.h>
26 26
27 27 #include <isc/assertions.h>
28 28 #include <isc/dst.h>
29 29 #include <errno.h>
30 30 #include <resolv.h>
31 31 #include <string.h>
32 32 #include <ctype.h>
33 33
34 34 #include "port_after.h"
35 35
36 36 #ifdef SPRINTF_CHAR
37 37 # define SPRINTF(x) strlen(sprintf/**/x)
38 38 #else
39 39 # define SPRINTF(x) ((size_t)sprintf x)
40 40 #endif
41 41
42 42 /* Forward. */
43 43
44 44 static size_t prune_origin(const char *name, const char *origin);
45 45 static int charstr(const u_char *rdata, const u_char *edata,
46 46 char **buf, size_t *buflen);
47 47 static int addname(const u_char *msg, size_t msglen,
48 48 const u_char **p, const char *origin,
49 49 char **buf, size_t *buflen);
50 50 static void addlen(size_t len, char **buf, size_t *buflen);
51 51 static int addstr(const char *src, size_t len,
52 52 char **buf, size_t *buflen);
53 53 static int addtab(size_t len, size_t target, int spaced,
54 54 char **buf, size_t *buflen);
55 55
56 56 /* Macros. */
57 57
58 58 #define T(x) \
59 59 do { \
60 60 if ((x) < 0) \
61 61 return (-1); \
62 62 } while (0)
63 63
64 64 static const char base32hex[] =
65 65 "0123456789ABCDEFGHIJKLMNOPQRSTUV=0123456789abcdefghijklmnopqrstuv";
66 66
67 67 /* Public. */
68 68
69 69 /*%
70 70 * Convert an RR to presentation format.
71 71 *
72 72 * return:
73 73 *\li Number of characters written to buf, or -1 (check errno).
74 74 */
75 75 int
76 76 ns_sprintrr(const ns_msg *handle, const ns_rr *rr,
77 77 const char *name_ctx, const char *origin,
78 78 char *buf, size_t buflen)
79 79 {
80 80 int n;
81 81
82 82 n = ns_sprintrrf(ns_msg_base(*handle), ns_msg_size(*handle),
83 83 ns_rr_name(*rr), ns_rr_class(*rr), ns_rr_type(*rr),
84 84 ns_rr_ttl(*rr), ns_rr_rdata(*rr), ns_rr_rdlen(*rr),
85 85 name_ctx, origin, buf, buflen);
86 86 return (n);
87 87 }
88 88
89 89 /*%
90 90 * Convert the fields of an RR into presentation format.
91 91 *
92 92 * return:
93 93 *\li Number of characters written to buf, or -1 (check errno).
94 94 */
95 95 int
96 96 ns_sprintrrf(const u_char *msg, size_t msglen,
97 97 const char *name, ns_class class, ns_type type,
98 98 u_long ttl, const u_char *rdata, size_t rdlen,
99 99 const char *name_ctx, const char *origin,
100 100 char *buf, size_t buflen)
101 101 {
102 102 const char *obuf = buf;
103 103 const u_char *edata = rdata + rdlen;
104 104 int spaced = 0;
105 105
106 106 const char *comment;
107 107 char tmp[100];
108 108 int len, x;
109 109
110 110 /*
111 111 * Owner.
112 112 */
113 113 if (name_ctx != NULL && ns_samename(name_ctx, name) == 1) {
114 114 T(addstr("\t\t\t", 3, &buf, &buflen));
115 115 } else {
116 116 len = prune_origin(name, origin);
117 117 if (*name == '\0') {
118 118 goto root;
119 119 } else if (len == 0) {
120 120 T(addstr("@\t\t\t", 4, &buf, &buflen));
121 121 } else {
122 122 T(addstr(name, len, &buf, &buflen));
123 123 /* Origin not used or not root, and no trailing dot? */
124 124 if (((origin == NULL || origin[0] == '\0') ||
125 125 (origin[0] != '.' && origin[1] != '\0' &&
126 126 name[len] == '\0')) && name[len - 1] != '.') {
127 127 root:
128 128 T(addstr(".", 1, &buf, &buflen));
129 129 len++;
130 130 }
131 131 T(spaced = addtab(len, 24, spaced, &buf, &buflen));
132 132 }
133 133 }
134 134
135 135 /*
136 136 * TTL, Class, Type.
137 137 */
138 138 T(x = ns_format_ttl(ttl, buf, buflen));
139 139 addlen(x, &buf, &buflen);
140 140 len = SPRINTF((tmp, " %s %s", p_class(class), p_type(type)));
141 141 T(addstr(tmp, len, &buf, &buflen));
142 142 T(spaced = addtab(x + len, 16, spaced, &buf, &buflen));
143 143
144 144 /*
145 145 * RData.
146 146 */
147 147 switch (type) {
148 148 case ns_t_a:
149 149 if (rdlen != (size_t)NS_INADDRSZ)
150 150 goto formerr;
151 151 (void) inet_ntop(AF_INET, rdata, buf, buflen);
152 152 addlen(strlen(buf), &buf, &buflen);
153 153 break;
154 154
155 155 case ns_t_cname:
156 156 case ns_t_mb:
157 157 case ns_t_mg:
158 158 case ns_t_mr:
159 159 case ns_t_ns:
160 160 case ns_t_ptr:
161 161 case ns_t_dname:
162 162 T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
163 163 break;
164 164
165 165 case ns_t_hinfo:
166 166 case ns_t_isdn:
167 167 /* First word. */
168 168 T(len = charstr(rdata, edata, &buf, &buflen));
169 169 if (len == 0)
170 170 goto formerr;
171 171 rdata += len;
172 172 T(addstr(" ", 1, &buf, &buflen));
173 173
174 174
175 175 /* Second word, optional in ISDN records. */
176 176 if (type == ns_t_isdn && rdata == edata)
177 177 break;
178 178
179 179 T(len = charstr(rdata, edata, &buf, &buflen));
180 180 if (len == 0)
181 181 goto formerr;
182 182 rdata += len;
183 183 break;
184 184
185 185 case ns_t_soa: {
186 186 u_long t;
187 187
188 188 /* Server name. */
189 189 T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
190 190 T(addstr(" ", 1, &buf, &buflen));
191 191
192 192 /* Administrator name. */
193 193 T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
194 194 T(addstr(" (\n", 3, &buf, &buflen));
195 195 spaced = 0;
196 196
197 197 if ((edata - rdata) != 5*NS_INT32SZ)
198 198 goto formerr;
199 199
200 200 /* Serial number. */
201 201 t = ns_get32(rdata); rdata += NS_INT32SZ;
202 202 T(addstr("\t\t\t\t\t", 5, &buf, &buflen));
203 203 len = SPRINTF((tmp, "%lu", t));
204 204 T(addstr(tmp, len, &buf, &buflen));
205 205 T(spaced = addtab(len, 16, spaced, &buf, &buflen));
206 206 T(addstr("; serial\n", 9, &buf, &buflen));
207 207 spaced = 0;
208 208
209 209 /* Refresh interval. */
210 210 t = ns_get32(rdata); rdata += NS_INT32SZ;
211 211 T(addstr("\t\t\t\t\t", 5, &buf, &buflen));
212 212 T(len = ns_format_ttl(t, buf, buflen));
213 213 addlen(len, &buf, &buflen);
214 214 T(spaced = addtab(len, 16, spaced, &buf, &buflen));
215 215 T(addstr("; refresh\n", 10, &buf, &buflen));
216 216 spaced = 0;
217 217
218 218 /* Retry interval. */
219 219 t = ns_get32(rdata); rdata += NS_INT32SZ;
220 220 T(addstr("\t\t\t\t\t", 5, &buf, &buflen));
221 221 T(len = ns_format_ttl(t, buf, buflen));
222 222 addlen(len, &buf, &buflen);
223 223 T(spaced = addtab(len, 16, spaced, &buf, &buflen));
224 224 T(addstr("; retry\n", 8, &buf, &buflen));
225 225 spaced = 0;
226 226
227 227 /* Expiry. */
228 228 t = ns_get32(rdata); rdata += NS_INT32SZ;
229 229 T(addstr("\t\t\t\t\t", 5, &buf, &buflen));
230 230 T(len = ns_format_ttl(t, buf, buflen));
231 231 addlen(len, &buf, &buflen);
232 232 T(spaced = addtab(len, 16, spaced, &buf, &buflen));
233 233 T(addstr("; expiry\n", 9, &buf, &buflen));
234 234 spaced = 0;
235 235
236 236 /* Minimum TTL. */
237 237 t = ns_get32(rdata); rdata += NS_INT32SZ;
238 238 T(addstr("\t\t\t\t\t", 5, &buf, &buflen));
239 239 T(len = ns_format_ttl(t, buf, buflen));
240 240 addlen(len, &buf, &buflen);
241 241 T(addstr(" )", 2, &buf, &buflen));
242 242 T(spaced = addtab(len, 16, spaced, &buf, &buflen));
243 243 T(addstr("; minimum\n", 10, &buf, &buflen));
244 244
245 245 break;
246 246 }
247 247
248 248 case ns_t_mx:
249 249 case ns_t_afsdb:
250 250 case ns_t_rt:
251 251 case ns_t_kx: {
252 252 u_int t;
253 253
254 254 if (rdlen < (size_t)NS_INT16SZ)
255 255 goto formerr;
256 256
257 257 /* Priority. */
258 258 t = ns_get16(rdata);
259 259 rdata += NS_INT16SZ;
260 260 len = SPRINTF((tmp, "%u ", t));
261 261 T(addstr(tmp, len, &buf, &buflen));
262 262
263 263 /* Target. */
264 264 T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
265 265
266 266 break;
267 267 }
268 268
269 269 case ns_t_px: {
270 270 u_int t;
271 271
272 272 if (rdlen < (size_t)NS_INT16SZ)
273 273 goto formerr;
274 274
275 275 /* Priority. */
276 276 t = ns_get16(rdata);
277 277 rdata += NS_INT16SZ;
278 278 len = SPRINTF((tmp, "%u ", t));
279 279 T(addstr(tmp, len, &buf, &buflen));
280 280
281 281 /* Name1. */
282 282 T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
283 283 T(addstr(" ", 1, &buf, &buflen));
284 284
285 285 /* Name2. */
286 286 T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
287 287
288 288 break;
289 289 }
290 290
291 291 case ns_t_x25:
292 292 T(len = charstr(rdata, edata, &buf, &buflen));
293 293 if (len == 0)
294 294 goto formerr;
295 295 rdata += len;
296 296 break;
297 297
298 298 case ns_t_txt:
299 299 case ns_t_spf:
300 300 while (rdata < edata) {
301 301 T(len = charstr(rdata, edata, &buf, &buflen));
302 302 if (len == 0)
303 303 goto formerr;
304 304 rdata += len;
305 305 if (rdata < edata)
306 306 T(addstr(" ", 1, &buf, &buflen));
307 307 }
308 308 break;
309 309
310 310 case ns_t_nsap: {
311 311 char t[2+255*3];
312 312
313 313 (void) inet_nsap_ntoa(rdlen, rdata, t);
314 314 T(addstr(t, strlen(t), &buf, &buflen));
315 315 break;
316 316 }
317 317
318 318 case ns_t_aaaa:
319 319 if (rdlen != (size_t)NS_IN6ADDRSZ)
320 320 goto formerr;
321 321 (void) inet_ntop(AF_INET6, rdata, buf, buflen);
322 322 addlen(strlen(buf), &buf, &buflen);
323 323 break;
324 324
325 325 case ns_t_loc: {
326 326 char t[255];
327 327
328 328 /* XXX protocol format checking? */
329 329 (void) loc_ntoa(rdata, t);
330 330 T(addstr(t, strlen(t), &buf, &buflen));
331 331 break;
332 332 }
333 333
334 334 case ns_t_naptr: {
335 335 u_int order, preference;
336 336 char t[50];
337 337
338 338 if (rdlen < 2U*NS_INT16SZ)
339 339 goto formerr;
340 340
341 341 /* Order, Precedence. */
342 342 order = ns_get16(rdata); rdata += NS_INT16SZ;
343 343 preference = ns_get16(rdata); rdata += NS_INT16SZ;
344 344 len = SPRINTF((t, "%u %u ", order, preference));
345 345 T(addstr(t, len, &buf, &buflen));
346 346
347 347 /* Flags. */
348 348 T(len = charstr(rdata, edata, &buf, &buflen));
349 349 if (len == 0)
350 350 goto formerr;
351 351 rdata += len;
352 352 T(addstr(" ", 1, &buf, &buflen));
353 353
354 354 /* Service. */
355 355 T(len = charstr(rdata, edata, &buf, &buflen));
356 356 if (len == 0)
357 357 goto formerr;
358 358 rdata += len;
359 359 T(addstr(" ", 1, &buf, &buflen));
360 360
361 361 /* Regexp. */
362 362 T(len = charstr(rdata, edata, &buf, &buflen));
363 363 if (len < 0)
364 364 return (-1);
365 365 if (len == 0)
366 366 goto formerr;
367 367 rdata += len;
368 368 T(addstr(" ", 1, &buf, &buflen));
369 369
370 370 /* Server. */
371 371 T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
372 372 break;
373 373 }
374 374
375 375 case ns_t_srv: {
376 376 u_int priority, weight, port;
377 377 char t[50];
378 378
379 379 if (rdlen < 3U*NS_INT16SZ)
380 380 goto formerr;
381 381
382 382 /* Priority, Weight, Port. */
383 383 priority = ns_get16(rdata); rdata += NS_INT16SZ;
384 384 weight = ns_get16(rdata); rdata += NS_INT16SZ;
385 385 port = ns_get16(rdata); rdata += NS_INT16SZ;
386 386 len = SPRINTF((t, "%u %u %u ", priority, weight, port));
387 387 T(addstr(t, len, &buf, &buflen));
388 388
389 389 /* Server. */
390 390 T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
391 391 break;
392 392 }
393 393
394 394 case ns_t_minfo:
395 395 case ns_t_rp:
396 396 /* Name1. */
397 397 T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
398 398 T(addstr(" ", 1, &buf, &buflen));
399 399
400 400 /* Name2. */
401 401 T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
402 402
403 403 break;
404 404
405 405 case ns_t_wks: {
406 406 int n, lcnt;
407 407
408 408 if (rdlen < 1U + NS_INT32SZ)
409 409 goto formerr;
410 410
411 411 /* Address. */
412 412 (void) inet_ntop(AF_INET, rdata, buf, buflen);
413 413 addlen(strlen(buf), &buf, &buflen);
414 414 rdata += NS_INADDRSZ;
415 415
416 416 /* Protocol. */
417 417 len = SPRINTF((tmp, " %u ( ", *rdata));
418 418 T(addstr(tmp, len, &buf, &buflen));
419 419 rdata += NS_INT8SZ;
420 420
421 421 /* Bit map. */
422 422 n = 0;
423 423 lcnt = 0;
424 424 while (rdata < edata) {
425 425 u_int c = *rdata++;
426 426 do {
427 427 if (c & 0200) {
428 428 if (lcnt == 0) {
429 429 T(addstr("\n\t\t\t\t", 5,
430 430 &buf, &buflen));
431 431 lcnt = 10;
432 432 spaced = 0;
433 433 }
434 434 len = SPRINTF((tmp, "%d ", n));
435 435 T(addstr(tmp, len, &buf, &buflen));
436 436 lcnt--;
437 437 }
438 438 c <<= 1;
439 439 } while (++n & 07);
440 440 }
441 441 T(addstr(")", 1, &buf, &buflen));
442 442
443 443 break;
444 444 }
445 445
446 446 case ns_t_key:
447 447 case ns_t_dnskey: {
448 448 char base64_key[NS_MD5RSA_MAX_BASE64];
449 449 u_int keyflags, protocol, algorithm, key_id;
450 450 const char *leader;
451 451 int n;
452 452
453 453 if (rdlen < 0U + NS_INT16SZ + NS_INT8SZ + NS_INT8SZ)
454 454 goto formerr;
455 455
456 456 /* Key flags, Protocol, Algorithm. */
457 457 key_id = dst_s_dns_key_id(rdata, edata-rdata);
458 458 keyflags = ns_get16(rdata); rdata += NS_INT16SZ;
459 459 protocol = *rdata++;
460 460 algorithm = *rdata++;
461 461 len = SPRINTF((tmp, "0x%04x %u %u",
462 462 keyflags, protocol, algorithm));
463 463 T(addstr(tmp, len, &buf, &buflen));
464 464
465 465 /* Public key data. */
466 466 len = b64_ntop(rdata, edata - rdata,
467 467 base64_key, sizeof base64_key);
468 468 if (len < 0)
469 469 goto formerr;
470 470 if (len > 15) {
471 471 T(addstr(" (", 2, &buf, &buflen));
472 472 leader = "\n\t\t";
473 473 spaced = 0;
474 474 } else
475 475 leader = " ";
476 476 for (n = 0; n < len; n += 48) {
477 477 T(addstr(leader, strlen(leader), &buf, &buflen));
478 478 T(addstr(base64_key + n, MIN(len - n, 48),
479 479 &buf, &buflen));
480 480 }
481 481 if (len > 15)
482 482 T(addstr(" )", 2, &buf, &buflen));
483 483 n = SPRINTF((tmp, " ; key_tag= %u", key_id));
484 484 T(addstr(tmp, n, &buf, &buflen));
485 485
486 486 break;
487 487 }
488 488
489 489 case ns_t_sig:
490 490 case ns_t_rrsig: {
491 491 char base64_key[NS_MD5RSA_MAX_BASE64];
492 492 u_int type, algorithm, labels, footprint;
493 493 const char *leader;
494 494 u_long t;
495 495 int n;
496 496
497 497 if (rdlen < 22U)
498 498 goto formerr;
499 499
500 500 /* Type covered, Algorithm, Label count, Original TTL. */
501 501 type = ns_get16(rdata); rdata += NS_INT16SZ;
502 502 algorithm = *rdata++;
503 503 labels = *rdata++;
504 504 t = ns_get32(rdata); rdata += NS_INT32SZ;
505 505 len = SPRINTF((tmp, "%s %d %d %lu ",
506 506 p_type(type), algorithm, labels, t));
507 507 T(addstr(tmp, len, &buf, &buflen));
508 508 if (labels > (u_int)dn_count_labels(name))
509 509 goto formerr;
510 510
511 511 /* Signature expiry. */
512 512 t = ns_get32(rdata); rdata += NS_INT32SZ;
513 513 len = SPRINTF((tmp, "%s ", p_secstodate(t)));
514 514 T(addstr(tmp, len, &buf, &buflen));
515 515
516 516 /* Time signed. */
517 517 t = ns_get32(rdata); rdata += NS_INT32SZ;
518 518 len = SPRINTF((tmp, "%s ", p_secstodate(t)));
519 519 T(addstr(tmp, len, &buf, &buflen));
520 520
521 521 /* Signature Footprint. */
522 522 footprint = ns_get16(rdata); rdata += NS_INT16SZ;
523 523 len = SPRINTF((tmp, "%u ", footprint));
524 524 T(addstr(tmp, len, &buf, &buflen));
525 525
526 526 /* Signer's name. */
527 527 T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
528 528
529 529 /* Signature. */
530 530 len = b64_ntop(rdata, edata - rdata,
531 531 base64_key, sizeof base64_key);
532 532 if (len > 15) {
533 533 T(addstr(" (", 2, &buf, &buflen));
534 534 leader = "\n\t\t";
535 535 spaced = 0;
536 536 } else
537 537 leader = " ";
538 538 if (len < 0)
539 539 goto formerr;
540 540 for (n = 0; n < len; n += 48) {
541 541 T(addstr(leader, strlen(leader), &buf, &buflen));
542 542 T(addstr(base64_key + n, MIN(len - n, 48),
543 543 &buf, &buflen));
544 544 }
545 545 if (len > 15)
546 546 T(addstr(" )", 2, &buf, &buflen));
547 547 break;
548 548 }
549 549
550 550 case ns_t_nxt: {
551 551 int n, c;
552 552
553 553 /* Next domain name. */
554 554 T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
555 555
556 556 /* Type bit map. */
557 557 n = edata - rdata;
558 558 for (c = 0; c < n*8; c++)
559 559 if (NS_NXT_BIT_ISSET(c, rdata)) {
560 560 len = SPRINTF((tmp, " %s", p_type(c)));
561 561 T(addstr(tmp, len, &buf, &buflen));
562 562 }
563 563 break;
564 564 }
565 565
566 566 case ns_t_cert: {
567 567 u_int c_type, key_tag, alg;
568 568 int n;
569 569 unsigned int siz;
570 570 char base64_cert[8192], tmp[40];
571 571 const char *leader;
572 572
573 573 c_type = ns_get16(rdata); rdata += NS_INT16SZ;
574 574 key_tag = ns_get16(rdata); rdata += NS_INT16SZ;
575 575 alg = (u_int) *rdata++;
576 576
577 577 len = SPRINTF((tmp, "%d %d %d ", c_type, key_tag, alg));
578 578 T(addstr(tmp, len, &buf, &buflen));
579 579 siz = (edata-rdata)*4/3 + 4; /* "+4" accounts for trailing \0 */
580 580 if (siz > sizeof(base64_cert) * 3/4) {
581 581 const char *str = "record too long to print";
582 582 T(addstr(str, strlen(str), &buf, &buflen));
583 583 }
584 584 else {
585 585 len = b64_ntop(rdata, edata-rdata, base64_cert, siz);
586 586
587 587 if (len < 0)
588 588 goto formerr;
589 589 else if (len > 15) {
590 590 T(addstr(" (", 2, &buf, &buflen));
591 591 leader = "\n\t\t";
592 592 spaced = 0;
593 593 }
594 594 else
595 595 leader = " ";
596 596
597 597 for (n = 0; n < len; n += 48) {
598 598 T(addstr(leader, strlen(leader),
599 599 &buf, &buflen));
600 600 T(addstr(base64_cert + n, MIN(len - n, 48),
601 601 &buf, &buflen));
602 602 }
603 603 if (len > 15)
604 604 T(addstr(" )", 2, &buf, &buflen));
605 605 }
606 606 break;
607 607 }
608 608
609 609 case ns_t_tkey: {
610 610 /* KJD - need to complete this */
611 611 u_long t;
612 612 int mode, err, keysize;
613 613
614 614 /* Algorithm name. */
615 615 T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
616 616 T(addstr(" ", 1, &buf, &buflen));
617 617
618 618 /* Inception. */
619 619 t = ns_get32(rdata); rdata += NS_INT32SZ;
620 620 len = SPRINTF((tmp, "%s ", p_secstodate(t)));
621 621 T(addstr(tmp, len, &buf, &buflen));
622 622
623 623 /* Experation. */
624 624 t = ns_get32(rdata); rdata += NS_INT32SZ;
625 625 len = SPRINTF((tmp, "%s ", p_secstodate(t)));
626 626 T(addstr(tmp, len, &buf, &buflen));
627 627
628 628 /* Mode , Error, Key Size. */
629 629 /* Priority, Weight, Port. */
630 630 mode = ns_get16(rdata); rdata += NS_INT16SZ;
631 631 err = ns_get16(rdata); rdata += NS_INT16SZ;
632 632 keysize = ns_get16(rdata); rdata += NS_INT16SZ;
633 633 len = SPRINTF((tmp, "%u %u %u ", mode, err, keysize));
634 634 T(addstr(tmp, len, &buf, &buflen));
635 635
636 636 /* XXX need to dump key, print otherdata length & other data */
637 637 break;
638 638 }
639 639
640 640 case ns_t_tsig: {
641 641 /* BEW - need to complete this */
642 642 int n;
643 643
644 644 T(len = addname(msg, msglen, &rdata, origin, &buf, &buflen));
645 645 T(addstr(" ", 1, &buf, &buflen));
646 646 rdata += 8; /*%< time */
647 647 n = ns_get16(rdata); rdata += INT16SZ;
648 648 rdata += n; /*%< sig */
649 649 n = ns_get16(rdata); rdata += INT16SZ; /*%< original id */
650 650 sprintf(buf, "%d", ns_get16(rdata));
651 651 rdata += INT16SZ;
652 652 addlen(strlen(buf), &buf, &buflen);
653 653 break;
654 654 }
655 655
656 656 case ns_t_a6: {
657 657 struct in6_addr a;
658 658 int pbyte, pbit;
659 659
660 660 /* prefix length */
661 661 if (rdlen == 0U) goto formerr;
662 662 len = SPRINTF((tmp, "%d ", *rdata));
663 663 T(addstr(tmp, len, &buf, &buflen));
664 664 pbit = *rdata;
665 665 if (pbit > 128) goto formerr;
666 666 pbyte = (pbit & ~7) / 8;
667 667 rdata++;
668 668
669 669 /* address suffix: provided only when prefix len != 128 */
670 670 if (pbit < 128) {
671 671 if (rdata + pbyte >= edata) goto formerr;
672 672 memset(&a, 0, sizeof(a));
673 673 memcpy(&a.s6_addr[pbyte], rdata, sizeof(a) - pbyte);
674 674 (void) inet_ntop(AF_INET6, &a, buf, buflen);
675 675 addlen(strlen(buf), &buf, &buflen);
676 676 rdata += sizeof(a) - pbyte;
677 677 }
678 678
679 679 /* prefix name: provided only when prefix len > 0 */
680 680 if (pbit == 0)
681 681 break;
682 682 if (rdata >= edata) goto formerr;
683 683 T(addstr(" ", 1, &buf, &buflen));
684 684 T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
685 685
686 686 break;
687 687 }
688 688
689 689 case ns_t_opt: {
690 690 len = SPRINTF((tmp, "%u bytes", class));
691 691 T(addstr(tmp, len, &buf, &buflen));
692 692 break;
693 693 }
694 694
695 695 case ns_t_ds:
696 696 case ns_t_dlv:
697 697 case ns_t_sshfp: {
698 698 u_int t;
699 699
700 700 if (type == ns_t_ds || type == ns_t_dlv) {
701 701 if (rdlen < 4U) goto formerr;
702 702 t = ns_get16(rdata);
703 703 rdata += NS_INT16SZ;
704 704 len = SPRINTF((tmp, "%u ", t));
705 705 T(addstr(tmp, len, &buf, &buflen));
706 706 } else
707 707 if (rdlen < 2U) goto formerr;
708 708
709 709 len = SPRINTF((tmp, "%u ", *rdata));
710 710 T(addstr(tmp, len, &buf, &buflen));
711 711 rdata++;
712 712
713 713 len = SPRINTF((tmp, "%u ", *rdata));
714 714 T(addstr(tmp, len, &buf, &buflen));
715 715 rdata++;
716 716
717 717 while (rdata < edata) {
718 718 len = SPRINTF((tmp, "%02X", *rdata));
719 719 T(addstr(tmp, len, &buf, &buflen));
720 720 rdata++;
721 721 }
722 722 break;
723 723 }
724 724
725 725 case ns_t_nsec3:
726 726 case ns_t_nsec3param: {
727 727 u_int t, w, l, j, k, c;
728 728
729 729 len = SPRINTF((tmp, "%u ", *rdata));
730 730 T(addstr(tmp, len, &buf, &buflen));
731 731 rdata++;
732 732
733 733 len = SPRINTF((tmp, "%u ", *rdata));
734 734 T(addstr(tmp, len, &buf, &buflen));
735 735 rdata++;
736 736
737 737 t = ns_get16(rdata);
738 738 rdata += NS_INT16SZ;
739 739 len = SPRINTF((tmp, "%u ", t));
740 740 T(addstr(tmp, len, &buf, &buflen));
741 741
742 742 t = *rdata++;
743 743 if (t == 0) {
744 744 T(addstr("-", 1, &buf, &buflen));
745 745 } else {
746 746 while (t-- > 0) {
747 747 len = SPRINTF((tmp, "%02X", *rdata));
748 748 T(addstr(tmp, len, &buf, &buflen));
749 749 rdata++;
750 750 }
751 751 }
752 752 if (type == ns_t_nsec3param)
753 753 break;
754 754 T(addstr(" ", 1, &buf, &buflen));
755 755
756 756 t = *rdata++;
757 757 while (t > 0) {
758 758 switch (t) {
759 759 case 1:
760 760 tmp[0] = base32hex[((rdata[0]>>3)&0x1f)];
761 761 tmp[1] = base32hex[((rdata[0]<<2)&0x1c)];
762 762 tmp[2] = tmp[3] = tmp[4] = '=';
763 763 tmp[5] = tmp[6] = tmp[7] = '=';
764 764 break;
765 765 case 2:
766 766 tmp[0] = base32hex[((rdata[0]>>3)&0x1f)];
767 767 tmp[1] = base32hex[((rdata[0]<<2)&0x1c)|
768 768 ((rdata[1]>>6)&0x03)];
769 769 tmp[2] = base32hex[((rdata[1]>>1)&0x1f)];
770 770 tmp[3] = base32hex[((rdata[1]<<4)&0x10)];
771 771 tmp[4] = tmp[5] = tmp[6] = tmp[7] = '=';
772 772 break;
773 773 case 3:
774 774 tmp[0] = base32hex[((rdata[0]>>3)&0x1f)];
775 775 tmp[1] = base32hex[((rdata[0]<<2)&0x1c)|
776 776 ((rdata[1]>>6)&0x03)];
777 777 tmp[2] = base32hex[((rdata[1]>>1)&0x1f)];
778 778 tmp[3] = base32hex[((rdata[1]<<4)&0x10)|
779 779 ((rdata[2]>>4)&0x0f)];
780 780 tmp[4] = base32hex[((rdata[2]<<1)&0x1e)];
781 781 tmp[5] = tmp[6] = tmp[7] = '=';
782 782 break;
783 783 case 4:
784 784 tmp[0] = base32hex[((rdata[0]>>3)&0x1f)];
785 785 tmp[1] = base32hex[((rdata[0]<<2)&0x1c)|
786 786 ((rdata[1]>>6)&0x03)];
787 787 tmp[2] = base32hex[((rdata[1]>>1)&0x1f)];
788 788 tmp[3] = base32hex[((rdata[1]<<4)&0x10)|
789 789 ((rdata[2]>>4)&0x0f)];
790 790 tmp[4] = base32hex[((rdata[2]<<1)&0x1e)|
791 791 ((rdata[3]>>7)&0x01)];
792 792 tmp[5] = base32hex[((rdata[3]>>2)&0x1f)];
793 793 tmp[6] = base32hex[(rdata[3]<<3)&0x18];
794 794 tmp[7] = '=';
795 795 break;
796 796 default:
797 797 tmp[0] = base32hex[((rdata[0]>>3)&0x1f)];
798 798 tmp[1] = base32hex[((rdata[0]<<2)&0x1c)|
799 799 ((rdata[1]>>6)&0x03)];
800 800 tmp[2] = base32hex[((rdata[1]>>1)&0x1f)];
801 801 tmp[3] = base32hex[((rdata[1]<<4)&0x10)|
802 802 ((rdata[2]>>4)&0x0f)];
803 803 tmp[4] = base32hex[((rdata[2]<<1)&0x1e)|
804 804 ((rdata[3]>>7)&0x01)];
805 805 tmp[5] = base32hex[((rdata[3]>>2)&0x1f)];
806 806 tmp[6] = base32hex[((rdata[3]<<3)&0x18)|
807 807 ((rdata[4]>>5)&0x07)];
808 808 tmp[7] = base32hex[(rdata[4]&0x1f)];
809 809 break;
810 810 }
811 811 T(addstr(tmp, 8, &buf, &buflen));
812 812 if (t >= 5) {
813 813 rdata += 5;
814 814 t -= 5;
815 815 } else {
816 816 rdata += t;
817 817 t -= t;
818 818 }
819 819 }
820 820
821 821 while (rdata < edata) {
822 822 w = *rdata++;
823 823 l = *rdata++;
824 824 for (j = 0; j < l; j++) {
825 825 if (rdata[j] == 0)
826 826 continue;
827 827 for (k = 0; k < 8; k++) {
828 828 if ((rdata[j] & (0x80 >> k)) == 0)
829 829 continue;
830 830 c = w * 256 + j * 8 + k;
831 831 len = SPRINTF((tmp, " %s", p_type(c)));
832 832 T(addstr(tmp, len, &buf, &buflen));
833 833 }
834 834 }
835 835 rdata += l;
836 836 }
837 837 break;
838 838 }
839 839
840 840 case ns_t_nsec: {
841 841 u_int w, l, j, k, c;
842 842
843 843 T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
844 844
845 845 while (rdata < edata) {
846 846 w = *rdata++;
847 847 l = *rdata++;
848 848 for (j = 0; j < l; j++) {
849 849 if (rdata[j] == 0)
850 850 continue;
851 851 for (k = 0; k < 8; k++) {
852 852 if ((rdata[j] & (0x80 >> k)) == 0)
853 853 continue;
854 854 c = w * 256 + j * 8 + k;
855 855 len = SPRINTF((tmp, " %s", p_type(c)));
856 856 T(addstr(tmp, len, &buf, &buflen));
857 857 }
858 858 }
859 859 rdata += l;
860 860 }
861 861 break;
862 862 }
863 863
864 864 case ns_t_dhcid: {
865 865 int n;
866 866 unsigned int siz;
867 867 char base64_dhcid[8192];
868 868 const char *leader;
869 869
870 870 siz = (edata-rdata)*4/3 + 4; /* "+4" accounts for trailing \0 */
871 871 if (siz > sizeof(base64_dhcid) * 3/4) {
872 872 const char *str = "record too long to print";
873 873 T(addstr(str, strlen(str), &buf, &buflen));
874 874 } else {
875 875 len = b64_ntop(rdata, edata-rdata, base64_dhcid, siz);
876 876
877 877 if (len < 0)
878 878 goto formerr;
879 879
880 880 else if (len > 15) {
881 881 T(addstr(" (", 2, &buf, &buflen));
882 882 leader = "\n\t\t";
883 883 spaced = 0;
884 884 }
885 885 else
886 886 leader = " ";
↓ open down ↓ |
886 lines elided |
↑ open up ↑ |
887 887
888 888 for (n = 0; n < len; n += 48) {
889 889 T(addstr(leader, strlen(leader),
890 890 &buf, &buflen));
891 891 T(addstr(base64_dhcid + n, MIN(len - n, 48),
892 892 &buf, &buflen));
893 893 }
894 894 if (len > 15)
895 895 T(addstr(" )", 2, &buf, &buflen));
896 896 }
897 + break;
897 898 }
898 - /* FALLTHROUGH */
899 899
900 900 case ns_t_ipseckey: {
901 901 int n;
902 902 unsigned int siz;
903 903 char base64_key[8192];
904 904 const char *leader;
905 905
906 906 if (rdlen < 2)
907 907 goto formerr;
908 908
909 909 switch (rdata[1]) {
910 910 case 0:
911 911 case 3:
912 912 if (rdlen < 3)
913 913 goto formerr;
914 914 break;
915 915 case 1:
916 916 if (rdlen < 7)
917 917 goto formerr;
918 918 break;
919 919 case 2:
920 920 if (rdlen < 19)
921 921 goto formerr;
922 922 break;
923 923 default:
924 924 comment = "unknown IPSECKEY gateway type";
925 925 goto hexify;
926 926 }
927 927
928 928 len = SPRINTF((tmp, "%u ", *rdata));
929 929 T(addstr(tmp, len, &buf, &buflen));
930 930 rdata++;
931 931
932 932 len = SPRINTF((tmp, "%u ", *rdata));
933 933 T(addstr(tmp, len, &buf, &buflen));
934 934 rdata++;
935 935
936 936 len = SPRINTF((tmp, "%u ", *rdata));
937 937 T(addstr(tmp, len, &buf, &buflen));
938 938 rdata++;
939 939
940 940 switch (rdata[-2]) {
941 941 case 0:
942 942 T(addstr(".", 1, &buf, &buflen));
943 943 break;
944 944 case 1:
945 945 (void) inet_ntop(AF_INET, rdata, buf, buflen);
946 946 addlen(strlen(buf), &buf, &buflen);
947 947 rdata += 4;
948 948 break;
949 949 case 2:
950 950 (void) inet_ntop(AF_INET6, rdata, buf, buflen);
951 951 addlen(strlen(buf), &buf, &buflen);
952 952 rdata += 16;
953 953 break;
954 954 case 3:
955 955 T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
956 956 break;
957 957 }
958 958
959 959 if (rdata >= edata)
960 960 break;
961 961
962 962 siz = (edata-rdata)*4/3 + 4; /* "+4" accounts for trailing \0 */
963 963 if (siz > sizeof(base64_key) * 3/4) {
964 964 const char *str = "record too long to print";
965 965 T(addstr(str, strlen(str), &buf, &buflen));
966 966 } else {
967 967 len = b64_ntop(rdata, edata-rdata, base64_key, siz);
968 968
969 969 if (len < 0)
970 970 goto formerr;
971 971
972 972 else if (len > 15) {
973 973 T(addstr(" (", 2, &buf, &buflen));
974 974 leader = "\n\t\t";
975 975 spaced = 0;
976 976 }
977 977 else
978 978 leader = " ";
↓ open down ↓ |
70 lines elided |
↑ open up ↑ |
979 979
980 980 for (n = 0; n < len; n += 48) {
981 981 T(addstr(leader, strlen(leader),
982 982 &buf, &buflen));
983 983 T(addstr(base64_key + n, MIN(len - n, 48),
984 984 &buf, &buflen));
985 985 }
986 986 if (len > 15)
987 987 T(addstr(" )", 2, &buf, &buflen));
988 988 }
989 + break;
989 990 }
990 - /* FALLTHROUGH */
991 991
992 992 case ns_t_hip: {
993 993 unsigned int i, hip_len, algorithm, key_len;
994 994 char base64_key[NS_MD5RSA_MAX_BASE64];
995 995 unsigned int siz;
996 996 const char *leader = "\n\t\t\t\t\t";
997 997
998 998 hip_len = *rdata++;
999 999 algorithm = *rdata++;
1000 1000 key_len = ns_get16(rdata);
1001 1001 rdata += NS_INT16SZ;
1002 1002
1003 1003 siz = key_len*4/3 + 4; /* "+4" accounts for trailing \0 */
1004 1004 if (siz > sizeof(base64_key) * 3/4) {
1005 1005 const char *str = "record too long to print";
1006 1006 T(addstr(str, strlen(str), &buf, &buflen));
1007 1007 } else {
1008 1008 len = sprintf(tmp, "( %u ", algorithm);
1009 1009 T(addstr(tmp, len, &buf, &buflen));
1010 1010
1011 1011 for (i = 0; i < hip_len; i++) {
1012 1012 len = sprintf(tmp, "%02X", *rdata);
1013 1013 T(addstr(tmp, len, &buf, &buflen));
1014 1014 rdata++;
1015 1015 }
1016 1016 T(addstr(leader, strlen(leader), &buf, &buflen));
1017 1017
1018 1018 len = b64_ntop(rdata, key_len, base64_key, siz);
1019 1019 if (len < 0)
1020 1020 goto formerr;
1021 1021
1022 1022 T(addstr(base64_key, len, &buf, &buflen));
1023 1023
1024 1024 rdata += key_len;
1025 1025 while (rdata < edata) {
1026 1026 T(addstr(leader, strlen(leader), &buf, &buflen));
1027 1027 T(addname(msg, msglen, &rdata, origin,
1028 1028 &buf, &buflen));
1029 1029 }
1030 1030 T(addstr(" )", 2, &buf, &buflen));
1031 1031 }
1032 1032 break;
1033 1033 }
1034 1034
1035 1035 default:
1036 1036 comment = "unknown RR type";
1037 1037 goto hexify;
1038 1038 }
1039 1039 return (buf - obuf);
1040 1040 formerr:
1041 1041 comment = "RR format error";
1042 1042 hexify: {
1043 1043 int n, m;
1044 1044 char *p;
1045 1045
1046 1046 len = SPRINTF((tmp, "\\# %u%s\t; %s", (unsigned)(edata - rdata),
1047 1047 rdlen != 0U ? " (" : "", comment));
1048 1048 T(addstr(tmp, len, &buf, &buflen));
1049 1049 while (rdata < edata) {
1050 1050 p = tmp;
1051 1051 p += SPRINTF((p, "\n\t"));
1052 1052 spaced = 0;
1053 1053 n = MIN(16, edata - rdata);
1054 1054 for (m = 0; m < n; m++)
1055 1055 p += SPRINTF((p, "%02x ", rdata[m]));
1056 1056 T(addstr(tmp, p - tmp, &buf, &buflen));
1057 1057 if (n < 16) {
1058 1058 T(addstr(")", 1, &buf, &buflen));
1059 1059 T(addtab(p - tmp + 1, 48, spaced, &buf, &buflen));
1060 1060 }
1061 1061 p = tmp;
1062 1062 p += SPRINTF((p, "; "));
1063 1063 for (m = 0; m < n; m++)
1064 1064 *p++ = (isascii(rdata[m]) && isprint(rdata[m]))
1065 1065 ? rdata[m]
1066 1066 : '.';
1067 1067 T(addstr(tmp, p - tmp, &buf, &buflen));
1068 1068 rdata += n;
1069 1069 }
1070 1070 return (buf - obuf);
1071 1071 }
1072 1072 }
1073 1073
1074 1074 /* Private. */
1075 1075
1076 1076 /*%
1077 1077 * size_t
1078 1078 * prune_origin(name, origin)
1079 1079 * Find out if the name is at or under the current origin.
1080 1080 * return:
1081 1081 * Number of characters in name before start of origin,
1082 1082 * or length of name if origin does not match.
1083 1083 * notes:
1084 1084 * This function should share code with samedomain().
1085 1085 */
1086 1086 static size_t
1087 1087 prune_origin(const char *name, const char *origin) {
1088 1088 const char *oname = name;
1089 1089
1090 1090 while (*name != '\0') {
1091 1091 if (origin != NULL && ns_samename(name, origin) == 1)
1092 1092 return (name - oname - (name > oname));
1093 1093 while (*name != '\0') {
1094 1094 if (*name == '\\') {
1095 1095 name++;
1096 1096 /* XXX need to handle \nnn form. */
1097 1097 if (*name == '\0')
1098 1098 break;
1099 1099 } else if (*name == '.') {
1100 1100 name++;
1101 1101 break;
1102 1102 }
1103 1103 name++;
1104 1104 }
1105 1105 }
1106 1106 return (name - oname);
1107 1107 }
1108 1108
1109 1109 /*%
1110 1110 * int
1111 1111 * charstr(rdata, edata, buf, buflen)
1112 1112 * Format a <character-string> into the presentation buffer.
1113 1113 * return:
1114 1114 * Number of rdata octets consumed
1115 1115 * 0 for protocol format error
1116 1116 * -1 for output buffer error
1117 1117 * side effects:
1118 1118 * buffer is advanced on success.
1119 1119 */
1120 1120 static int
1121 1121 charstr(const u_char *rdata, const u_char *edata, char **buf, size_t *buflen) {
1122 1122 const u_char *odata = rdata;
1123 1123 size_t save_buflen = *buflen;
1124 1124 char *save_buf = *buf;
1125 1125
1126 1126 if (addstr("\"", 1, buf, buflen) < 0)
1127 1127 goto enospc;
1128 1128 if (rdata < edata) {
1129 1129 int n = *rdata;
1130 1130
1131 1131 if (rdata + 1 + n <= edata) {
1132 1132 rdata++;
1133 1133 while (n-- > 0) {
1134 1134 if (strchr("\n\"\\", *rdata) != NULL)
1135 1135 if (addstr("\\", 1, buf, buflen) < 0)
1136 1136 goto enospc;
1137 1137 if (addstr((const char *)rdata, 1,
1138 1138 buf, buflen) < 0)
1139 1139 goto enospc;
1140 1140 rdata++;
1141 1141 }
1142 1142 }
1143 1143 }
1144 1144 if (addstr("\"", 1, buf, buflen) < 0)
1145 1145 goto enospc;
1146 1146 return (rdata - odata);
1147 1147 enospc:
1148 1148 errno = ENOSPC;
1149 1149 *buf = save_buf;
1150 1150 *buflen = save_buflen;
1151 1151 return (-1);
1152 1152 }
1153 1153
1154 1154 static int
1155 1155 addname(const u_char *msg, size_t msglen,
1156 1156 const u_char **pp, const char *origin,
1157 1157 char **buf, size_t *buflen)
1158 1158 {
1159 1159 size_t newlen, save_buflen = *buflen;
1160 1160 char *save_buf = *buf;
1161 1161 int n;
1162 1162
1163 1163 n = dn_expand(msg, msg + msglen, *pp, *buf, *buflen);
1164 1164 if (n < 0)
1165 1165 goto enospc; /*%< Guess. */
1166 1166 newlen = prune_origin(*buf, origin);
1167 1167 if (**buf == '\0') {
1168 1168 goto root;
1169 1169 } else if (newlen == 0U) {
1170 1170 /* Use "@" instead of name. */
1171 1171 if (newlen + 2 > *buflen)
1172 1172 goto enospc; /* No room for "@\0". */
1173 1173 (*buf)[newlen++] = '@';
1174 1174 (*buf)[newlen] = '\0';
1175 1175 } else {
1176 1176 if (((origin == NULL || origin[0] == '\0') ||
1177 1177 (origin[0] != '.' && origin[1] != '\0' &&
1178 1178 (*buf)[newlen] == '\0')) && (*buf)[newlen - 1] != '.') {
1179 1179 /* No trailing dot. */
1180 1180 root:
1181 1181 if (newlen + 2 > *buflen)
1182 1182 goto enospc; /* No room for ".\0". */
1183 1183 (*buf)[newlen++] = '.';
1184 1184 (*buf)[newlen] = '\0';
1185 1185 }
1186 1186 }
1187 1187 *pp += n;
1188 1188 addlen(newlen, buf, buflen);
1189 1189 **buf = '\0';
1190 1190 return (newlen);
1191 1191 enospc:
1192 1192 errno = ENOSPC;
1193 1193 *buf = save_buf;
1194 1194 *buflen = save_buflen;
1195 1195 return (-1);
1196 1196 }
1197 1197
1198 1198 static void
1199 1199 addlen(size_t len, char **buf, size_t *buflen) {
1200 1200 INSIST(len <= *buflen);
1201 1201 *buf += len;
1202 1202 *buflen -= len;
1203 1203 }
1204 1204
1205 1205 static int
1206 1206 addstr(const char *src, size_t len, char **buf, size_t *buflen) {
1207 1207 if (len >= *buflen) {
1208 1208 errno = ENOSPC;
1209 1209 return (-1);
1210 1210 }
1211 1211 memcpy(*buf, src, len);
1212 1212 addlen(len, buf, buflen);
1213 1213 **buf = '\0';
1214 1214 return (0);
1215 1215 }
1216 1216
1217 1217 static int
1218 1218 addtab(size_t len, size_t target, int spaced, char **buf, size_t *buflen) {
1219 1219 size_t save_buflen = *buflen;
1220 1220 char *save_buf = *buf;
1221 1221 int t;
1222 1222
1223 1223 if (spaced || len >= target - 1) {
1224 1224 T(addstr(" ", 2, buf, buflen));
1225 1225 spaced = 1;
1226 1226 } else {
1227 1227 for (t = (target - len - 1) / 8; t >= 0; t--)
1228 1228 if (addstr("\t", 1, buf, buflen) < 0) {
1229 1229 *buflen = save_buflen;
1230 1230 *buf = save_buf;
1231 1231 return (-1);
1232 1232 }
1233 1233 spaced = 0;
1234 1234 }
1235 1235 return (spaced);
1236 1236 }
1237 1237
1238 1238 /*! \file */
↓ open down ↓ |
238 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX