| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#include "config.h" |
| 23 |
#include <errno.h> |
| 24 |
#include <stdio.h> |
| 25 |
#include <string.h> |
| 26 |
#include <stdlib.h> |
| 27 |
#include <sys/wait.h> |
| 28 |
|
| 29 |
#define TRACE_HOME |
| 30 |
#include "trace.h" |
| 31 |
#include "ini_configobj.h" |
| 32 |
#include "ini_config_priv.h" |
| 33 |
#include "collection_tools.h" |
| 34 |
#include "ini_configmod.h" |
| 35 |
#include "path_utils.h" |
| 36 |
|
| 37 |
int verbose = 0; |
| 38 |
|
| 39 |
#define WRAP_SIZE 80 |
| 40 |
|
| 41 |
#define INIOUT(foo) \ |
| 42 |
do { \ |
| 43 |
if (verbose) { printf("%30s(%4d): ",__FUNCTION__,__LINE__); foo; } \ |
| 44 |
} while(0) |
| 45 |
|
| 46 |
typedef int (*test_fn)(void); |
| 47 |
|
| 48 |
static void print_configuration(struct ini_cfgobj *in_cfg, |
| 49 |
FILE *file) |
| 50 |
{ |
| 51 |
int error; |
| 52 |
struct simplebuffer *sbobj = NULL; |
| 53 |
uint32_t left = 0; |
| 54 |
|
| 55 |
error = simplebuffer_alloc(&sbobj); |
| 56 |
if (error) { |
| 57 |
printf("Failed to allocate buffer. Error %d.\n", error); |
| 58 |
return; |
| 59 |
} |
| 60 |
|
| 61 |
error = ini_config_serialize(in_cfg, sbobj); |
| 62 |
if (error) { |
| 63 |
printf("Failed to serialize. Error %d.\n", error); |
| 64 |
simplebuffer_free(sbobj); |
| 65 |
return; |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
left = simplebuffer_get_len(sbobj); |
| 70 |
while (left > 0) { |
| 71 |
error = simplebuffer_write(fileno(file), sbobj, &left); |
| 72 |
if (error) { |
| 73 |
printf("Failed to write back the configuration %d.\n", error); |
| 74 |
simplebuffer_free(sbobj); |
| 75 |
return; |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
simplebuffer_free(sbobj); |
| 80 |
return; |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
static int basic_test(void) |
| 87 |
{ |
| 88 |
int error = EOK; |
| 89 |
char indir[PATH_MAX]; |
| 90 |
char srcname[PATH_MAX]; |
| 91 |
char resname[PATH_MAX]; |
| 92 |
char command[PATH_MAX * 3]; |
| 93 |
char *builddir = NULL; |
| 94 |
char *srcdir = NULL; |
| 95 |
struct ini_cfgobj *in_cfg = NULL; |
| 96 |
char bin1[] = { 1, 2, 3 }; |
| 97 |
char bin2[] = { 10, 11, 12 }; |
| 98 |
FILE *file = NULL; |
| 99 |
const char *comment1[] = { "// This is a real file with some comments", |
| 100 |
"" }; |
| 101 |
const char *comment2[] = { "", |
| 102 |
"/**/" }; |
| 103 |
const char *comment3[] = { "", |
| 104 |
"/* Service section defines", |
| 105 |
" * which service are allowed.", |
| 106 |
" */ " |
| 107 |
}; |
| 108 |
const char *sec_com[] = { "" }; |
| 109 |
const char *const_str_arr[] = { "dp", "nss", "pam", "info" }; |
| 110 |
char **str_arr = (char **)(intptr_t)const_str_arr; |
| 111 |
|
| 112 |
INIOUT(printf("<==== Start ====>\n")); |
| 113 |
|
| 114 |
srcdir = getenv("srcdir"); |
| 115 |
builddir = getenv("builddir"); |
| 116 |
|
| 117 |
snprintf(indir, PATH_MAX, "%s/ini/ini.d", |
| 118 |
(srcdir == NULL) ? "." : srcdir); |
| 119 |
|
| 120 |
snprintf(srcname, PATH_MAX, "%s/ini/ini.d/real.conf", |
| 121 |
(srcdir == NULL) ? "." : srcdir); |
| 122 |
|
| 123 |
snprintf(resname, PATH_MAX, "%s/real.conf.manual", |
| 124 |
(builddir == NULL) ? "." : builddir); |
| 125 |
|
| 126 |
|
| 127 |
error = ini_config_create(&in_cfg); |
| 128 |
if (error) { |
| 129 |
INIOUT(printf("Failed to create collection. Error %d.\n", error)); |
| 130 |
return error; |
| 131 |
} |
| 132 |
|
| 133 |
if ((error = ini_config_add_section( |
| 134 |
in_cfg, |
| 135 |
"config", |
| 136 |
comment1, |
| 137 |
2, |
| 138 |
COL_DSP_END, |
| 139 |
NULL, |
| 140 |
0)) || |
| 141 |
(error = ini_config_add_str_value( |
| 142 |
in_cfg, |
| 143 |
"config", |
| 144 |
"version", |
| 145 |
"0.1", |
| 146 |
NULL, |
| 147 |
0, |
| 148 |
WRAP_SIZE, |
| 149 |
COL_DSP_END, |
| 150 |
NULL, |
| 151 |
0, |
| 152 |
INI_VA_NOCHECK)) || |
| 153 |
(error = ini_config_add_section( |
| 154 |
in_cfg, |
| 155 |
"monitor", |
| 156 |
comment2, |
| 157 |
2, |
| 158 |
COL_DSP_END, |
| 159 |
NULL, |
| 160 |
0)) || |
| 161 |
(error = ini_config_add_str_value( |
| 162 |
in_cfg, |
| 163 |
"monitor", |
| 164 |
"description", |
| 165 |
"Monitor Configuration", |
| 166 |
NULL, |
| 167 |
0, |
| 168 |
WRAP_SIZE, |
| 169 |
COL_DSP_END, |
| 170 |
NULL, |
| 171 |
0, |
| 172 |
INI_VA_NOCHECK)) || |
| 173 |
(error = ini_config_add_int_value( |
| 174 |
in_cfg, |
| 175 |
"monitor", |
| 176 |
"sbusTimeout", |
| 177 |
10, |
| 178 |
NULL, |
| 179 |
0, |
| 180 |
WRAP_SIZE, |
| 181 |
COL_DSP_END, |
| 182 |
NULL, |
| 183 |
0, |
| 184 |
INI_VA_NOCHECK)) || |
| 185 |
(error = ini_config_add_str_value( |
| 186 |
in_cfg, |
| 187 |
"monitor", |
| 188 |
"sbusAddress", |
| 189 |
"unix:path=/var/lib/sss/pipes/private/dbus", |
| 190 |
NULL, |
| 191 |
0, |
| 192 |
WRAP_SIZE, |
| 193 |
COL_DSP_END, |
| 194 |
NULL, |
| 195 |
0, |
| 196 |
INI_VA_NOCHECK)) || |
| 197 |
(error = ini_config_add_unsigned_value( |
| 198 |
in_cfg, |
| 199 |
"monitor", |
| 200 |
"servicePingTime", |
| 201 |
10, |
| 202 |
NULL, |
| 203 |
0, |
| 204 |
WRAP_SIZE, |
| 205 |
COL_DSP_END, |
| 206 |
NULL, |
| 207 |
0, |
| 208 |
INI_VA_NOCHECK)) || |
| 209 |
(error = ini_config_add_str_value( |
| 210 |
in_cfg, |
| 211 |
"monitor", |
| 212 |
"bad_number", |
| 213 |
"5a", |
| 214 |
NULL, |
| 215 |
0, |
| 216 |
WRAP_SIZE, |
| 217 |
COL_DSP_END, |
| 218 |
NULL, |
| 219 |
0, |
| 220 |
INI_VA_NOCHECK)) || |
| 221 |
(error = ini_config_add_section( |
| 222 |
in_cfg, |
| 223 |
"services", |
| 224 |
comment3, |
| 225 |
4, |
| 226 |
COL_DSP_END, |
| 227 |
NULL, |
| 228 |
0)) || |
| 229 |
(error = ini_config_add_str_value( |
| 230 |
in_cfg, |
| 231 |
"services", |
| 232 |
"description", |
| 233 |
"Local service configuration", |
| 234 |
NULL, |
| 235 |
0, |
| 236 |
WRAP_SIZE, |
| 237 |
COL_DSP_END, |
| 238 |
NULL, |
| 239 |
0, |
| 240 |
INI_VA_NOCHECK)) || |
| 241 |
(error = ini_config_add_str_arr_value( |
| 242 |
in_cfg, |
| 243 |
"services", |
| 244 |
"activeServices", |
| 245 |
str_arr, |
| 246 |
4, |
| 247 |
',', |
| 248 |
NULL, |
| 249 |
0, |
| 250 |
WRAP_SIZE, |
| 251 |
COL_DSP_END, |
| 252 |
NULL, |
| 253 |
0, |
| 254 |
INI_VA_NOCHECK)) || |
| 255 |
(error = ini_config_add_section( |
| 256 |
in_cfg, |
| 257 |
"services/dp", |
| 258 |
sec_com, |
| 259 |
1, |
| 260 |
COL_DSP_END, |
| 261 |
NULL, |
| 262 |
0)) || |
| 263 |
(error = ini_config_add_str_value( |
| 264 |
in_cfg, |
| 265 |
"services/dp", |
| 266 |
"description", |
| 267 |
"Data Provider Configuration", |
| 268 |
NULL, |
| 269 |
0, |
| 270 |
WRAP_SIZE, |
| 271 |
COL_DSP_END, |
| 272 |
NULL, |
| 273 |
0, |
| 274 |
INI_VA_NOCHECK)) || |
| 275 |
(error = ini_config_add_str_value( |
| 276 |
in_cfg, |
| 277 |
"services/dp", |
| 278 |
"command", |
| 279 |
"/usr/libexec/sssd/sssd_dp", |
| 280 |
NULL, |
| 281 |
0, |
| 282 |
WRAP_SIZE, |
| 283 |
COL_DSP_END, |
| 284 |
NULL, |
| 285 |
0, |
| 286 |
INI_VA_NOCHECK)) || |
| 287 |
(error = ini_config_add_section( |
| 288 |
in_cfg, |
| 289 |
"services/nss", |
| 290 |
sec_com, |
| 291 |
1, |
| 292 |
COL_DSP_END, |
| 293 |
NULL, |
| 294 |
0)) || |
| 295 |
(error = ini_config_add_str_value( |
| 296 |
in_cfg, |
| 297 |
"services/nss", |
| 298 |
"description", |
| 299 |
"NSS Responder Configuration", |
| 300 |
NULL, |
| 301 |
0, |
| 302 |
WRAP_SIZE, |
| 303 |
COL_DSP_END, |
| 304 |
NULL, |
| 305 |
0, |
| 306 |
INI_VA_NOCHECK)) || |
| 307 |
(error = ini_config_add_str_value( |
| 308 |
in_cfg, |
| 309 |
"services/nss", |
| 310 |
"unixSocket", |
| 311 |
"/var/lib/sss/pipes/nss", |
| 312 |
NULL, |
| 313 |
0, |
| 314 |
WRAP_SIZE, |
| 315 |
COL_DSP_END, |
| 316 |
NULL, |
| 317 |
0, |
| 318 |
INI_VA_NOCHECK)) || |
| 319 |
(error = ini_config_add_str_value( |
| 320 |
in_cfg, |
| 321 |
"services/nss", |
| 322 |
"command", |
| 323 |
"/usr/libexec/sssd/sssd_nss", |
| 324 |
NULL, |
| 325 |
0, |
| 326 |
WRAP_SIZE, |
| 327 |
COL_DSP_END, |
| 328 |
NULL, |
| 329 |
0, |
| 330 |
INI_VA_NOCHECK)) || |
| 331 |
(error = ini_config_add_section( |
| 332 |
in_cfg, |
| 333 |
"services/pam", |
| 334 |
sec_com, |
| 335 |
1, |
| 336 |
COL_DSP_END, |
| 337 |
NULL, |
| 338 |
0)) || |
| 339 |
(error = ini_config_add_str_value( |
| 340 |
in_cfg, |
| 341 |
"services/pam", |
| 342 |
"description", |
| 343 |
"PAM Responder Configuration", |
| 344 |
NULL, |
| 345 |
0, |
| 346 |
WRAP_SIZE, |
| 347 |
COL_DSP_END, |
| 348 |
NULL, |
| 349 |
0, |
| 350 |
INI_VA_NOCHECK)) || |
| 351 |
(error = ini_config_add_str_value( |
| 352 |
in_cfg, |
| 353 |
"services/pam", |
| 354 |
"unixSocket", |
| 355 |
"/var/lib/sss/pipes/pam", |
| 356 |
NULL, |
| 357 |
0, |
| 358 |
WRAP_SIZE, |
| 359 |
COL_DSP_END, |
| 360 |
NULL, |
| 361 |
0, |
| 362 |
INI_VA_NOCHECK)) || |
| 363 |
(error = ini_config_add_str_value( |
| 364 |
in_cfg, |
| 365 |
"services/pam", |
| 366 |
"command", |
| 367 |
"/usr/libexec/sssd/sssd_pam", |
| 368 |
NULL, |
| 369 |
0, |
| 370 |
WRAP_SIZE, |
| 371 |
COL_DSP_FRONT, |
| 372 |
NULL, |
| 373 |
0, |
| 374 |
INI_VA_NOCHECK)) || |
| 375 |
(error = ini_config_add_section( |
| 376 |
in_cfg, |
| 377 |
"services/info", |
| 378 |
sec_com, |
| 379 |
1, |
| 380 |
COL_DSP_END, |
| 381 |
NULL, |
| 382 |
0)) || |
| 383 |
(error = ini_config_add_str_value( |
| 384 |
in_cfg, |
| 385 |
"services/info", |
| 386 |
"description", |
| 387 |
"InfoPipe Configuration", |
| 388 |
NULL, |
| 389 |
0, |
| 390 |
WRAP_SIZE, |
| 391 |
COL_DSP_END, |
| 392 |
NULL, |
| 393 |
0, |
| 394 |
INI_VA_NOCHECK)) || |
| 395 |
(error = ini_config_add_str_value( |
| 396 |
in_cfg, |
| 397 |
"services/info", |
| 398 |
"command", |
| 399 |
"./sbin/sssd_info", |
| 400 |
NULL, |
| 401 |
0, |
| 402 |
WRAP_SIZE, |
| 403 |
COL_DSP_END, |
| 404 |
NULL, |
| 405 |
0, |
| 406 |
INI_VA_NOCHECK)) || |
| 407 |
(error = ini_config_add_section( |
| 408 |
in_cfg, |
| 409 |
"domains", |
| 410 |
sec_com, |
| 411 |
1, |
| 412 |
COL_DSP_END, |
| 413 |
NULL, |
| 414 |
0)) || |
| 415 |
(error = ini_config_add_str_value( |
| 416 |
in_cfg, |
| 417 |
"domains", |
| 418 |
"domainsOrder", |
| 419 |
" , LOCAL, , EXAMPLE.COM" |
| 420 |
", , SOMEOTHER.COM , ,", |
| 421 |
NULL, |
| 422 |
0, |
| 423 |
WRAP_SIZE, |
| 424 |
COL_DSP_END, |
| 425 |
NULL, |
| 426 |
0, |
| 427 |
INI_VA_NOCHECK)) || |
| 428 |
(error = ini_config_add_str_value( |
| 429 |
in_cfg, |
| 430 |
"domains", |
| 431 |
"badarray", |
| 432 |
" , , , , ,", |
| 433 |
NULL, |
| 434 |
0, |
| 435 |
WRAP_SIZE, |
| 436 |
COL_DSP_END, |
| 437 |
NULL, |
| 438 |
0, |
| 439 |
INI_VA_NOCHECK)) || |
| 440 |
(error = ini_config_add_str_value( |
| 441 |
in_cfg, |
| 442 |
"domains", |
| 443 |
"somearray", |
| 444 |
",", |
| 445 |
NULL, |
| 446 |
0, |
| 447 |
WRAP_SIZE, |
| 448 |
COL_DSP_END, |
| 449 |
NULL, |
| 450 |
0, |
| 451 |
INI_VA_NOCHECK)) || |
| 452 |
(error = ini_config_add_str_value( |
| 453 |
in_cfg, |
| 454 |
"domains", |
| 455 |
"someotherarray", |
| 456 |
", ;", |
| 457 |
NULL, |
| 458 |
0, |
| 459 |
WRAP_SIZE, |
| 460 |
COL_DSP_END, |
| 461 |
NULL, |
| 462 |
0, |
| 463 |
INI_VA_NOCHECK)) || |
| 464 |
(error = ini_config_add_str_value( |
| 465 |
in_cfg, |
| 466 |
"domains", |
| 467 |
"justdelim", |
| 468 |
":;,;", |
| 469 |
NULL, |
| 470 |
0, |
| 471 |
WRAP_SIZE, |
| 472 |
COL_DSP_END, |
| 473 |
NULL, |
| 474 |
0, |
| 475 |
INI_VA_NOCHECK)) || |
| 476 |
(error = ini_config_add_str_value( |
| 477 |
in_cfg, |
| 478 |
"domains", |
| 479 |
"yetanother", |
| 480 |
"", |
| 481 |
NULL, |
| 482 |
0, |
| 483 |
WRAP_SIZE, |
| 484 |
COL_DSP_END, |
| 485 |
NULL, |
| 486 |
0, |
| 487 |
INI_VA_NOCHECK)) || |
| 488 |
(error = ini_config_add_section( |
| 489 |
in_cfg, |
| 490 |
"domains/LOCAL", |
| 491 |
sec_com, |
| 492 |
1, |
| 493 |
COL_DSP_END, |
| 494 |
NULL, |
| 495 |
0)) || |
| 496 |
(error = ini_config_add_str_value( |
| 497 |
in_cfg, |
| 498 |
"domains/LOCAL", |
| 499 |
"description", |
| 500 |
"Reserved domain for local configurations", |
| 501 |
NULL, |
| 502 |
0, |
| 503 |
WRAP_SIZE, |
| 504 |
COL_DSP_END, |
| 505 |
NULL, |
| 506 |
0, |
| 507 |
INI_VA_NOCHECK)) || |
| 508 |
(error = ini_config_add_str_value( |
| 509 |
in_cfg, |
| 510 |
"domains/LOCAL", |
| 511 |
"legacy", |
| 512 |
"FALSE", |
| 513 |
NULL, |
| 514 |
0, |
| 515 |
WRAP_SIZE, |
| 516 |
COL_DSP_END, |
| 517 |
NULL, |
| 518 |
0, |
| 519 |
INI_VA_NOCHECK)) || |
| 520 |
(error = ini_config_add_long_value( |
| 521 |
in_cfg, |
| 522 |
"domains/LOCAL", |
| 523 |
"enumerate", |
| 524 |
3, |
| 525 |
NULL, |
| 526 |
0, |
| 527 |
WRAP_SIZE, |
| 528 |
COL_DSP_END, |
| 529 |
NULL, |
| 530 |
0, |
| 531 |
INI_VA_NOCHECK)) || |
| 532 |
(error = ini_config_add_section( |
| 533 |
in_cfg, |
| 534 |
"domains/EXAMPLE.COM", |
| 535 |
sec_com, |
| 536 |
1, |
| 537 |
COL_DSP_END, |
| 538 |
NULL, |
| 539 |
0)) || |
| 540 |
(error = ini_config_add_str_value( |
| 541 |
in_cfg, |
| 542 |
"domains/EXAMPLE.COM", |
| 543 |
"description", |
| 544 |
"Example domain served by IPA ", |
| 545 |
NULL, |
| 546 |
0, |
| 547 |
WRAP_SIZE, |
| 548 |
COL_DSP_END, |
| 549 |
NULL, |
| 550 |
0, |
| 551 |
INI_VA_NOCHECK)) || |
| 552 |
(error = ini_config_add_str_value( |
| 553 |
in_cfg, |
| 554 |
"domains/EXAMPLE.COM", |
| 555 |
"provider", |
| 556 |
"ipa", |
| 557 |
NULL, |
| 558 |
0, |
| 559 |
WRAP_SIZE, |
| 560 |
COL_DSP_END, |
| 561 |
NULL, |
| 562 |
0, |
| 563 |
INI_VA_NOCHECK)) || |
| 564 |
(error = ini_config_add_str_value( |
| 565 |
in_cfg, |
| 566 |
"domains/EXAMPLE.COM", |
| 567 |
"server", |
| 568 |
"ipaserver1.example.com", |
| 569 |
NULL, |
| 570 |
0, |
| 571 |
WRAP_SIZE, |
| 572 |
COL_DSP_END, |
| 573 |
NULL, |
| 574 |
0, |
| 575 |
INI_VA_NOCHECK)) || |
| 576 |
(error = ini_config_add_str_value( |
| 577 |
in_cfg, |
| 578 |
"domains/EXAMPLE.COM", |
| 579 |
"server", |
| 580 |
"ipabackupserver.example.com", |
| 581 |
NULL, |
| 582 |
0, |
| 583 |
WRAP_SIZE, |
| 584 |
COL_DSP_END, |
| 585 |
NULL, |
| 586 |
0, |
| 587 |
INI_VA_NOCHECK)) || |
| 588 |
(error = ini_config_add_str_value( |
| 589 |
in_cfg, |
| 590 |
"domains/EXAMPLE.COM", |
| 591 |
"legacy", |
| 592 |
"FALSE", |
| 593 |
NULL, |
| 594 |
0, |
| 595 |
WRAP_SIZE, |
| 596 |
COL_DSP_END, |
| 597 |
NULL, |
| 598 |
0, |
| 599 |
INI_VA_NOCHECK)) || |
| 600 |
(error = ini_config_add_str_value( |
| 601 |
in_cfg, |
| 602 |
"domains/EXAMPLE.COM", |
| 603 |
"server", |
| 604 |
"otheripabackupserver.example.com", |
| 605 |
NULL, |
| 606 |
0, |
| 607 |
WRAP_SIZE, |
| 608 |
COL_DSP_END, |
| 609 |
NULL, |
| 610 |
0, |
| 611 |
INI_VA_NOCHECK)) || |
| 612 |
(error = ini_config_add_int64_value( |
| 613 |
in_cfg, |
| 614 |
"domains/EXAMPLE.COM", |
| 615 |
"enumerate", |
| 616 |
0, |
| 617 |
NULL, |
| 618 |
0, |
| 619 |
WRAP_SIZE, |
| 620 |
COL_DSP_END, |
| 621 |
NULL, |
| 622 |
0, |
| 623 |
INI_VA_NOCHECK)) || |
| 624 |
(error = ini_config_add_bin_value( |
| 625 |
in_cfg, |
| 626 |
"domains/EXAMPLE.COM", |
| 627 |
"binary_test", |
| 628 |
bin1, |
| 629 |
3, |
| 630 |
NULL, |
| 631 |
0, |
| 632 |
WRAP_SIZE, |
| 633 |
COL_DSP_END, |
| 634 |
NULL, |
| 635 |
0, |
| 636 |
INI_VA_NOCHECK)) || |
| 637 |
(error = ini_config_add_bin_value( |
| 638 |
in_cfg, |
| 639 |
"domains/EXAMPLE.COM", |
| 640 |
"binary_test_two", |
| 641 |
bin2, |
| 642 |
3, |
| 643 |
NULL, |
| 644 |
0, |
| 645 |
WRAP_SIZE, |
| 646 |
COL_DSP_END, |
| 647 |
NULL, |
| 648 |
0, |
| 649 |
INI_VA_NOCHECK)) || |
| 650 |
(error = ini_config_add_str_value( |
| 651 |
in_cfg, |
| 652 |
"domains/EXAMPLE.COM", |
| 653 |
"long_array", |
| 654 |
"1 2; 4' ;8p .16/ 32?", |
| 655 |
NULL, |
| 656 |
0, |
| 657 |
WRAP_SIZE, |
| 658 |
COL_DSP_END, |
| 659 |
NULL, |
| 660 |
0, |
| 661 |
INI_VA_NOCHECK)) || |
| 662 |
(error = ini_config_add_str_value( |
| 663 |
in_cfg, |
| 664 |
"domains/EXAMPLE.COM", |
| 665 |
"double_array", |
| 666 |
"1.1 2.222222; .4' . ;8p .16/ -32?", |
| 667 |
NULL, |
| 668 |
0, |
| 669 |
WRAP_SIZE, |
| 670 |
COL_DSP_END, |
| 671 |
NULL, |
| 672 |
0, |
| 673 |
INI_VA_NOCHECK)) || |
| 674 |
(error = ini_config_add_str_value( |
| 675 |
in_cfg, |
| 676 |
"domains/EXAMPLE.COM", |
| 677 |
"server", |
| 678 |
"yetanotheripabackupserver.example.com", |
| 679 |
NULL, |
| 680 |
0, |
| 681 |
WRAP_SIZE, |
| 682 |
COL_DSP_END, |
| 683 |
NULL, |
| 684 |
0, |
| 685 |
INI_VA_NOCHECK)) || |
| 686 |
(error = ini_config_add_str_value( |
| 687 |
in_cfg, |
| 688 |
"domains/EXAMPLE.COM", |
| 689 |
"empty_value", |
| 690 |
"", |
| 691 |
NULL, |
| 692 |
0, |
| 693 |
WRAP_SIZE, |
| 694 |
COL_DSP_END, |
| 695 |
NULL, |
| 696 |
0, |
| 697 |
INI_VA_NOCHECK)) || |
| 698 |
(error = ini_config_add_str_value( |
| 699 |
in_cfg, |
| 700 |
"domains/EXAMPLE.COM", |
| 701 |
"space_value", |
| 702 |
"\" \"", |
| 703 |
NULL, |
| 704 |
0, |
| 705 |
WRAP_SIZE, |
| 706 |
COL_DSP_END, |
| 707 |
NULL, |
| 708 |
0, |
| 709 |
INI_VA_NOCHECK)) || |
| 710 |
(error = ini_config_add_int32_value( |
| 711 |
in_cfg, |
| 712 |
"domains/EXAMPLE.COM", |
| 713 |
"int32_t", |
| 714 |
-1000000000, |
| 715 |
NULL, |
| 716 |
0, |
| 717 |
WRAP_SIZE, |
| 718 |
COL_DSP_END, |
| 719 |
NULL, |
| 720 |
0, |
| 721 |
INI_VA_NOCHECK)) || |
| 722 |
(error = ini_config_add_uint32_value( |
| 723 |
in_cfg, |
| 724 |
"domains/EXAMPLE.COM", |
| 725 |
"uint32_t", |
| 726 |
3000000000u, |
| 727 |
NULL, |
| 728 |
0, |
| 729 |
WRAP_SIZE, |
| 730 |
COL_DSP_END, |
| 731 |
NULL, |
| 732 |
0, |
| 733 |
INI_VA_NOCHECK)) || |
| 734 |
(error = ini_config_add_int64_value( |
| 735 |
in_cfg, |
| 736 |
"domains/EXAMPLE.COM", |
| 737 |
"int64_t", |
| 738 |
-1000000000123, |
| 739 |
NULL, |
| 740 |
0, |
| 741 |
WRAP_SIZE, |
| 742 |
COL_DSP_END, |
| 743 |
NULL, |
| 744 |
0, |
| 745 |
INI_VA_NOCHECK)) || |
| 746 |
(error = ini_config_add_uint64_value( |
| 747 |
in_cfg, |
| 748 |
"domains/EXAMPLE.COM", |
| 749 |
"uint64_t", |
| 750 |
9223375036854775931u, |
| 751 |
NULL, |
| 752 |
0, |
| 753 |
WRAP_SIZE, |
| 754 |
COL_DSP_END, |
| 755 |
NULL, |
| 756 |
0, |
| 757 |
INI_VA_NOCHECK))) { |
| 758 |
INIOUT(printf("Failed to create configuration. Error %d.\n", error)); |
| 759 |
print_configuration(in_cfg, stdout); |
| 760 |
ini_config_destroy(in_cfg); |
| 761 |
return error; |
| 762 |
} |
| 763 |
|
| 764 |
file = fopen(resname, "w"); |
| 765 |
print_configuration(in_cfg, file); |
| 766 |
fclose(file); |
| 767 |
ini_config_destroy(in_cfg); |
| 768 |
|
| 769 |
snprintf(command, PATH_MAX * 3, "diff -wi %s %s", srcname, resname); |
| 770 |
error = system(command); |
| 771 |
INIOUT(printf("Comparison of %s %s returned: %d\n", |
| 772 |
srcname, resname, error)); |
| 773 |
|
| 774 |
if ((error) || (WEXITSTATUS(error))) { |
| 775 |
printf("Failed to run diff command %d %d.\n", error, |
| 776 |
WEXITSTATUS(error)); |
| 777 |
return -1; |
| 778 |
} |
| 779 |
|
| 780 |
|
| 781 |
INIOUT(printf("<==== End ====>\n")); |
| 782 |
|
| 783 |
return EOK; |
| 784 |
} |
| 785 |
|
| 786 |
|
| 787 |
static void make_results(const char *path) |
| 788 |
{ |
| 789 |
FILE *file = NULL; |
| 790 |
|
| 791 |
file = fopen(path, "w"); |
| 792 |
|
| 793 |
fprintf(file, "// This is a test\n" |
| 794 |
"[one]\n" |
| 795 |
"key1 = value1\n" |
| 796 |
"key1 = value1a\n" |
| 797 |
"key1 = value1a_bis\n" |
| 798 |
"// This is a test\n" |
| 799 |
"key1 = value1b\n" |
| 800 |
"key2 = value2\n" |
| 801 |
"key3 = value3\n"); |
| 802 |
fclose(file); |
| 803 |
} |
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
static int dup_test(void) |
| 808 |
{ |
| 809 |
int error = EOK; |
| 810 |
char srcname[PATH_MAX]; |
| 811 |
char resname[PATH_MAX]; |
| 812 |
char command[PATH_MAX * 3]; |
| 813 |
char *builddir = NULL; |
| 814 |
struct ini_cfgobj *in_cfg = NULL; |
| 815 |
FILE *file = NULL; |
| 816 |
const char *comment[] = { "// This is a test", NULL }; |
| 817 |
|
| 818 |
INIOUT(printf("<==== Start ====>\n")); |
| 819 |
|
| 820 |
builddir = getenv("builddir"); |
| 821 |
|
| 822 |
snprintf(srcname, PATH_MAX, "%s/modtest.conf.exp", |
| 823 |
(builddir == NULL) ? "." : builddir); |
| 824 |
|
| 825 |
snprintf(resname, PATH_MAX, "%s/modtest.conf.real", |
| 826 |
(builddir == NULL) ? "." : builddir); |
| 827 |
|
| 828 |
make_results(srcname); |
| 829 |
|
| 830 |
|
| 831 |
error = ini_config_create(&in_cfg); |
| 832 |
if (error) { |
| 833 |
INIOUT(printf("Failed to create collection. Error %d.\n", error)); |
| 834 |
return error; |
| 835 |
} |
| 836 |
|
| 837 |
if ((error = ini_config_add_section( |
| 838 |
in_cfg, |
| 839 |
"one", |
| 840 |
NULL, |
| 841 |
0, |
| 842 |
COL_DSP_END, |
| 843 |
NULL, |
| 844 |
0)) || |
| 845 |
(error = ini_config_add_str_value( |
| 846 |
in_cfg, |
| 847 |
"one", |
| 848 |
"key2", |
| 849 |
"value2", |
| 850 |
NULL, |
| 851 |
0, |
| 852 |
WRAP_SIZE, |
| 853 |
COL_DSP_FRONT, |
| 854 |
NULL, |
| 855 |
0, |
| 856 |
INI_VA_NOCHECK)) || |
| 857 |
(error = ini_config_add_str_value( |
| 858 |
in_cfg, |
| 859 |
"one", |
| 860 |
"key1", |
| 861 |
"value1a", |
| 862 |
NULL, |
| 863 |
0, |
| 864 |
WRAP_SIZE, |
| 865 |
COL_DSP_BEFORE, |
| 866 |
"key2", |
| 867 |
0, |
| 868 |
INI_VA_NOCHECK)) || |
| 869 |
(error = ini_config_add_str_value( |
| 870 |
in_cfg, |
| 871 |
"one", |
| 872 |
"key3", |
| 873 |
"value3", |
| 874 |
NULL, |
| 875 |
0, |
| 876 |
WRAP_SIZE, |
| 877 |
COL_DSP_AFTER, |
| 878 |
"key2", |
| 879 |
0, |
| 880 |
INI_VA_NOCHECK)) || |
| 881 |
(error = ini_config_add_str_value( |
| 882 |
in_cfg, |
| 883 |
"one", |
| 884 |
"key1", |
| 885 |
"value1", |
| 886 |
NULL, |
| 887 |
0, |
| 888 |
WRAP_SIZE, |
| 889 |
COL_DSP_FIRSTDUP, |
| 890 |
"key1", |
| 891 |
0, |
| 892 |
INI_VA_NOCHECK)) || |
| 893 |
(error = ini_config_add_str_value( |
| 894 |
in_cfg, |
| 895 |
"one", |
| 896 |
"key1", |
| 897 |
"value1b", |
| 898 |
NULL, |
| 899 |
0, |
| 900 |
WRAP_SIZE, |
| 901 |
COL_DSP_LASTDUP, |
| 902 |
"key1", |
| 903 |
0, |
| 904 |
INI_VA_NOCHECK)) || |
| 905 |
(error = ini_config_add_str_value( |
| 906 |
in_cfg, |
| 907 |
"one", |
| 908 |
"key1", |
| 909 |
"value1c", |
| 910 |
NULL, |
| 911 |
0, |
| 912 |
WRAP_SIZE, |
| 913 |
COL_DSP_LASTDUP, |
| 914 |
"key1", |
| 915 |
0, |
| 916 |
INI_VA_NOCHECK)) || |
| 917 |
(error = ini_config_add_str_value( |
| 918 |
in_cfg, |
| 919 |
"one", |
| 920 |
"key1", |
| 921 |
"value1a_bis", |
| 922 |
NULL, |
| 923 |
0, |
| 924 |
WRAP_SIZE, |
| 925 |
COL_DSP_NDUPNS, |
| 926 |
"key1", |
| 927 |
2, |
| 928 |
INI_VA_NOCHECK))) { |
| 929 |
INIOUT(printf("Failed to create configuration. Error %d.\n", error)); |
| 930 |
print_configuration(in_cfg, stdout); |
| 931 |
ini_config_destroy(in_cfg); |
| 932 |
return error; |
| 933 |
} |
| 934 |
|
| 935 |
|
| 936 |
if (EEXIST != ini_config_add_section( |
| 937 |
in_cfg, |
| 938 |
"one", |
| 939 |
NULL, |
| 940 |
0, |
| 941 |
COL_DSP_END, |
| 942 |
NULL, |
| 943 |
0)) { |
| 944 |
INIOUT(printf("Expected error. Got %d.\n", error)); |
| 945 |
print_configuration(in_cfg, stdout); |
| 946 |
ini_config_destroy(in_cfg); |
| 947 |
return error; |
| 948 |
} |
| 949 |
|
| 950 |
if ((error = ini_config_comment_section(in_cfg, |
| 951 |
"one", |
| 952 |
comment, |
| 953 |
1))) { |
| 954 |
INIOUT(printf("Failed to add a comment %d.\n", error)); |
| 955 |
print_configuration(in_cfg, stdout); |
| 956 |
ini_config_destroy(in_cfg); |
| 957 |
return error; |
| 958 |
} |
| 959 |
|
| 960 |
if ((error = ini_config_add_section( |
| 961 |
in_cfg, |
| 962 |
"two", |
| 963 |
NULL, |
| 964 |
0, |
| 965 |
COL_DSP_FRONT, |
| 966 |
NULL, |
| 967 |
0)) || |
| 968 |
(error = ini_config_add_str_value( |
| 969 |
in_cfg, |
| 970 |
"two", |
| 971 |
"key2", |
| 972 |
"value2", |
| 973 |
NULL, |
| 974 |
0, |
| 975 |
WRAP_SIZE, |
| 976 |
COL_DSP_FRONT, |
| 977 |
NULL, |
| 978 |
0, |
| 979 |
INI_VA_NOCHECK)) || |
| 980 |
(error = ini_config_add_str_value( |
| 981 |
in_cfg, |
| 982 |
"two", |
| 983 |
"key1", |
| 984 |
"value1a", |
| 985 |
NULL, |
| 986 |
0, |
| 987 |
WRAP_SIZE, |
| 988 |
COL_DSP_BEFORE, |
| 989 |
"key2", |
| 990 |
0, |
| 991 |
INI_VA_NOCHECK)) || |
| 992 |
(error = ini_config_add_str_value( |
| 993 |
in_cfg, |
| 994 |
"two", |
| 995 |
"key3", |
| 996 |
"value3", |
| 997 |
NULL, |
| 998 |
0, |
| 999 |
WRAP_SIZE, |
| 1000 |
COL_DSP_AFTER, |
| 1001 |
"key2", |
| 1002 |
0, |
| 1003 |
INI_VA_NOCHECK)) || |
| 1004 |
(error = ini_config_add_str_value( |
| 1005 |
in_cfg, |
| 1006 |
"two", |
| 1007 |
"key1", |
| 1008 |
"value1", |
| 1009 |
NULL, |
| 1010 |
0, |
| 1011 |
WRAP_SIZE, |
| 1012 |
COL_DSP_FIRSTDUP, |
| 1013 |
"key1", |
| 1014 |
0, |
| 1015 |
INI_VA_NOCHECK)) || |
| 1016 |
(error = ini_config_add_str_value( |
| 1017 |
in_cfg, |
| 1018 |
"two", |
| 1019 |
"key1", |
| 1020 |
"value1b", |
| 1021 |
NULL, |
| 1022 |
0, |
| 1023 |
WRAP_SIZE, |
| 1024 |
COL_DSP_LASTDUP, |
| 1025 |
"key1", |
| 1026 |
0, |
| 1027 |
INI_VA_NOCHECK)) || |
| 1028 |
(error = ini_config_add_str_value( |
| 1029 |
in_cfg, |
| 1030 |
"two", |
| 1031 |
"key1", |
| 1032 |
"value1c", |
| 1033 |
NULL, |
| 1034 |
0, |
| 1035 |
WRAP_SIZE, |
| 1036 |
COL_DSP_LASTDUP, |
| 1037 |
"key1", |
| 1038 |
0, |
| 1039 |
INI_VA_NOCHECK)) || |
| 1040 |
(error = ini_config_add_str_value( |
| 1041 |
in_cfg, |
| 1042 |
"two", |
| 1043 |
"key1", |
| 1044 |
"value1a_bis", |
| 1045 |
NULL, |
| 1046 |
0, |
| 1047 |
WRAP_SIZE, |
| 1048 |
COL_DSP_NDUPNS, |
| 1049 |
"key1", |
| 1050 |
2, |
| 1051 |
INI_VA_NOCHECK))) { |
| 1052 |
INIOUT(printf("Failed to add another section. Error %d.\n", error)); |
| 1053 |
print_configuration(in_cfg, stdout); |
| 1054 |
ini_config_destroy(in_cfg); |
| 1055 |
return error; |
| 1056 |
} |
| 1057 |
|
| 1058 |
|
| 1059 |
if ((error = ini_config_rename_section(in_cfg, |
| 1060 |
"two", |
| 1061 |
"three"))) { |
| 1062 |
INIOUT(printf("Failed to rename a section %d.\n", error)); |
| 1063 |
print_configuration(in_cfg, stdout); |
| 1064 |
ini_config_destroy(in_cfg); |
| 1065 |
return error; |
| 1066 |
} |
| 1067 |
|
| 1068 |
|
| 1069 |
if ((error = ini_config_delete_section_by_position(in_cfg, |
| 1070 |
COL_DSP_BEFORE, |
| 1071 |
"one", |
| 1072 |
0))) { |
| 1073 |
INIOUT(printf("Failed to delete a section %d.\n", error)); |
| 1074 |
print_configuration(in_cfg, stdout); |
| 1075 |
ini_config_destroy(in_cfg); |
| 1076 |
return error; |
| 1077 |
} |
| 1078 |
|
| 1079 |
|
| 1080 |
if ((error = ini_config_update_comment(in_cfg, |
| 1081 |
"one", |
| 1082 |
"key1", |
| 1083 |
comment, |
| 1084 |
1, |
| 1085 |
3))) { |
| 1086 |
INIOUT(printf("Failed to update comment %d.\n", error)); |
| 1087 |
print_configuration(in_cfg, stdout); |
| 1088 |
ini_config_destroy(in_cfg); |
| 1089 |
return error; |
| 1090 |
} |
| 1091 |
|
| 1092 |
|
| 1093 |
if ((error = ini_config_delete_value(in_cfg, |
| 1094 |
"one", |
| 1095 |
COL_DSP_NDUP, |
| 1096 |
"key1", |
| 1097 |
4))) { |
| 1098 |
INIOUT(printf("Failed to delete the key %d.\n", error)); |
| 1099 |
print_configuration(in_cfg, stdout); |
| 1100 |
ini_config_destroy(in_cfg); |
| 1101 |
return error; |
| 1102 |
} |
| 1103 |
|
| 1104 |
file = fopen(resname, "w"); |
| 1105 |
print_configuration(in_cfg, file); |
| 1106 |
fclose(file); |
| 1107 |
ini_config_destroy(in_cfg); |
| 1108 |
|
| 1109 |
snprintf(command, PATH_MAX * 3, "diff -wi %s %s", srcname, resname); |
| 1110 |
error = system(command); |
| 1111 |
INIOUT(printf("Comparison of %s %s returned: %d\n", |
| 1112 |
srcname, resname, error)); |
| 1113 |
|
| 1114 |
if ((error) || (WEXITSTATUS(error))) { |
| 1115 |
printf("Failed to run diff command %d %d.\n", error, |
| 1116 |
WEXITSTATUS(error)); |
| 1117 |
return -1; |
| 1118 |
} |
| 1119 |
|
| 1120 |
|
| 1121 |
INIOUT(printf("<==== End ====>\n")); |
| 1122 |
|
| 1123 |
return EOK; |
| 1124 |
} |
| 1125 |
|
| 1126 |
int main(int argc, char *argv[]) |
| 1127 |
{ |
| 1128 |
int error = EOK; |
| 1129 |
test_fn tests[] = { basic_test, |
| 1130 |
dup_test, |
| 1131 |
NULL }; |
| 1132 |
test_fn t; |
| 1133 |
int i = 0; |
| 1134 |
char *var; |
| 1135 |
|
| 1136 |
if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = 1; |
| 1137 |
else { |
| 1138 |
var = getenv("COMMON_TEST_VERBOSE"); |
| 1139 |
if (var) verbose = 1; |
| 1140 |
} |
| 1141 |
|
| 1142 |
INIOUT(printf("Start\n")); |
| 1143 |
|
| 1144 |
while ((t = tests[i++])) { |
| 1145 |
error = t(); |
| 1146 |
if (error) { |
| 1147 |
printf("Failed with error %d!\n", error); |
| 1148 |
return error; |
| 1149 |
} |
| 1150 |
} |
| 1151 |
|
| 1152 |
INIOUT(printf("Success!\n")); |
| 1153 |
return 0; |
| 1154 |
} |