Changeset 223 for branches/samba-3.3.x/source/lib/smbconf
- Timestamp:
- May 24, 2009, 7:51:24 AM (16 years ago)
- Location:
- branches/samba-3.3.x/source/lib/smbconf
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/samba-3.3.x/source/lib/smbconf/smbconf.c
r206 r223 44 44 45 45 /** 46 * Tell whether the backend requires messaging to be set up 47 * for the backend to work correctly. 48 */ 49 bool smbconf_backend_requires_messaging(struct smbconf_ctx *ctx) 50 { 51 return ctx->ops->requires_messaging(ctx); 52 } 53 54 /** 55 * Tell whether the source is writeable. 56 */ 57 bool smbconf_is_writeable(struct smbconf_ctx *ctx) 58 { 59 return ctx->ops->is_writeable(ctx); 60 } 61 62 /** 46 63 * Close the configuration. 47 64 */ 48 65 void smbconf_shutdown(struct smbconf_ctx *ctx) 49 66 { 50 TALLOC_FREE(ctx);67 talloc_free(ctx); 51 68 } 52 69 … … 141 158 142 159 done: 143 TALLOC_FREE(tmp_ctx);160 talloc_free(tmp_ctx); 144 161 return werr; 145 162 } … … 187 204 struct smbconf_service **service) 188 205 { 189 if (!smbconf_share_exists(ctx, servicename)) {190 return WERR_NO_SUCH_SERVICE;191 }192 193 206 return ctx->ops->get_share(ctx, mem_ctx, servicename, service); 194 207 } … … 214 227 const char *valstr) 215 228 { 216 if (!smbconf_share_exists(ctx, service)) {217 return WERR_NO_SUCH_SERVICE;218 }219 220 229 return ctx->ops->set_parameter(ctx, service, param, valstr); 221 230 } … … 253 262 } 254 263 255 if (!smbconf_share_exists(ctx, service)) {256 return WERR_NO_SUCH_SERVICE;257 }258 259 264 return ctx->ops->get_parameter(ctx, mem_ctx, service, param, valstr); 260 265 } … … 287 292 const char *service, const char *param) 288 293 { 289 if (!smbconf_share_exists(ctx, service)) {290 return WERR_NO_SUCH_SERVICE;291 }292 293 294 return ctx->ops->delete_parameter(ctx, service, param); 294 295 } … … 317 318 uint32_t *num_includes, char ***includes) 318 319 { 319 if (!smbconf_share_exists(ctx, service)) {320 return WERR_NO_SUCH_SERVICE;321 }322 323 320 return ctx->ops->get_includes(ctx, mem_ctx, service, num_includes, 324 321 includes); … … 344 341 uint32_t num_includes, const char **includes) 345 342 { 346 if (!smbconf_share_exists(ctx, service)) {347 return WERR_NO_SUCH_SERVICE;348 }349 350 343 return ctx->ops->set_includes(ctx, service, num_includes, includes); 351 344 } … … 369 362 WERROR smbconf_delete_includes(struct smbconf_ctx *ctx, const char *service) 370 363 { 371 if (!smbconf_share_exists(ctx, service)) {372 return WERR_NO_SUCH_SERVICE;373 }374 375 364 return ctx->ops->delete_includes(ctx, service); 376 365 } … … 387 376 return werr; 388 377 } 378 379 WERROR smbconf_transaction_start(struct smbconf_ctx *ctx) 380 { 381 return ctx->ops->transaction_start(ctx); 382 } 383 384 WERROR smbconf_transaction_commit(struct smbconf_ctx *ctx) 385 { 386 return ctx->ops->transaction_commit(ctx); 387 } 388 389 WERROR smbconf_transaction_cancel(struct smbconf_ctx *ctx) 390 { 391 return ctx->ops->transaction_cancel(ctx); 392 } -
branches/samba-3.3.x/source/lib/smbconf/smbconf.h
r206 r223 35 35 }; 36 36 37 38 /**39 * intialization dispatcher function.40 * takes source string in the form of "backend:path"41 */42 WERROR smbconf_init(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,43 const char *source);44 45 /**46 * initialization functions for the available modules47 */48 49 WERROR smbconf_init_reg(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx,50 const char *path);51 52 WERROR smbconf_init_txt(TALLOC_CTX *mem_ctx,53 struct smbconf_ctx **conf_ctx,54 const char *path);55 56 37 /* 57 38 * the smbconf API functions 58 39 */ 40 bool smbconf_backend_requires_messaging(struct smbconf_ctx *ctx); 41 bool smbconf_is_writeable(struct smbconf_ctx *ctx); 59 42 void smbconf_shutdown(struct smbconf_ctx *ctx); 60 43 bool smbconf_changed(struct smbconf_ctx *ctx, struct smbconf_csn *csn, … … 112 95 WERROR smbconf_delete_global_includes(struct smbconf_ctx *ctx); 113 96 97 WERROR smbconf_transaction_start(struct smbconf_ctx *ctx); 98 WERROR smbconf_transaction_commit(struct smbconf_ctx *ctx); 99 WERROR smbconf_transaction_cancel(struct smbconf_ctx *ctx); 100 114 101 #endif /* _LIBSMBCONF_H_ */ -
branches/samba-3.3.x/source/lib/smbconf/smbconf_init.c
r206 r223 19 19 20 20 #include "includes.h" 21 #include "smbconf_private.h" 22 23 #define INCLUDES_VALNAME "includes" 24 21 #include "lib/smbconf/smbconf_private.h" 22 #include "lib/smbconf/smbconf_txt.h" 23 #include "lib/smbconf/smbconf_reg.h" 25 24 26 25 /** … … 76 75 /* 77 76 * If no separator was given in the source, and the string is 78 * not a know backend, assume file backend and use the source77 * not a known backend, assume file backend and use the source 79 78 * string as a path argument. 80 79 */ … … 83 82 /* 84 83 * Separator was specified but this is not a known backend. 85 * Can't handle this. 84 * As a last resort, try to interpret the original source 85 * string as a file name that contains a ":" sign. 86 * This may occur with an include directive like this: 87 * 'include = /path/to/file.%T' 86 88 */ 87 DEBUG(1, ("smbconf_init: ERROR - unknown backend '%s' given\n", 88 backend)); 89 werr = WERR_INVALID_PARAM; 89 werr = smbconf_init_txt(mem_ctx, conf_ctx, source); 90 90 } 91 91 92 92 done: 93 TALLOC_FREE(tmp_ctx);93 talloc_free(tmp_ctx); 94 94 return werr; 95 95 } -
branches/samba-3.3.x/source/lib/smbconf/smbconf_private.h
r206 r223 24 24 WERROR (*init)(struct smbconf_ctx *ctx, const char *path); 25 25 int (*shutdown)(struct smbconf_ctx *ctx); 26 bool (*requires_messaging)(struct smbconf_ctx *ctx); 27 bool (*is_writeable)(struct smbconf_ctx *ctx); 26 28 WERROR (*open_conf)(struct smbconf_ctx *ctx); 27 29 int (*close_conf)(struct smbconf_ctx *ctx); … … 61 63 WERROR (*delete_includes)(struct smbconf_ctx *ctx, 62 64 const char *service); 65 WERROR (*transaction_start)(struct smbconf_ctx *ctx); 66 WERROR (*transaction_commit)(struct smbconf_ctx *ctx); 67 WERROR (*transaction_cancel)(struct smbconf_ctx *ctx); 63 68 }; 64 69 -
branches/samba-3.3.x/source/lib/smbconf/smbconf_reg.c
r206 r223 19 19 20 20 #include "includes.h" 21 #include " smbconf_private.h"21 #include "lib/smbconf/smbconf_private.h" 22 22 23 23 #define INCLUDES_VALNAME "includes" 24 24 25 25 struct reg_private_data { 26 NT_USER_TOKEN *token;26 struct registry_key *base_key; 27 27 bool open; /* did _we_ open the registry? */ 28 28 }; … … 73 73 74 74 /** 75 * Open a registry key specified by "path"76 */77 static WERROR smbconf_reg_open_path(TALLOC_CTX *mem_ctx,78 struct smbconf_ctx *ctx,79 const char *path,80 uint32 desired_access,81 struct registry_key **key)82 {83 WERROR werr = WERR_OK;84 85 if (ctx == NULL) {86 DEBUG(1, ("Error: configuration is not open!\n"));87 werr = WERR_INVALID_PARAM;88 goto done;89 }90 91 if (rpd(ctx)->token == NULL) {92 DEBUG(1, ("Error: token missing from smbconf_ctx. "93 "was smbconf_init() called?\n"));94 werr = WERR_INVALID_PARAM;95 goto done;96 }97 98 werr = ctx->ops->open_conf(ctx);99 if (!W_ERROR_IS_OK(werr)) {100 DEBUG(1, ("Error opening the registry.\n"));101 goto done;102 }103 104 if (path == NULL) {105 DEBUG(1, ("Error: NULL path string given\n"));106 werr = WERR_INVALID_PARAM;107 goto done;108 }109 110 werr = reg_open_path(mem_ctx, path, desired_access, rpd(ctx)->token,111 key);112 113 if (!W_ERROR_IS_OK(werr)) {114 DEBUG(5, ("Error opening registry path '%s': %s\n",115 path, dos_errstr(werr)));116 }117 118 done:119 return werr;120 }121 122 /**123 75 * Open a subkey of the base key (i.e a service) 124 76 */ … … 129 81 struct registry_key **key) 130 82 { 131 WERROR werr = WERR_OK; 132 char *path = NULL; 83 WERROR werr; 133 84 134 85 if (servicename == NULL) { 135 path = talloc_strdup(mem_ctx, ctx->path); 136 } else { 137 path = talloc_asprintf(mem_ctx, "%s\\%s", ctx->path, 138 servicename); 139 } 140 if (path == NULL) { 141 werr = WERR_NOMEM; 142 goto done; 143 } 144 145 werr = smbconf_reg_open_path(mem_ctx, ctx, path, desired_access, key); 146 147 done: 148 TALLOC_FREE(path); 149 return werr; 150 } 151 152 /** 153 * open the base key 154 */ 155 static WERROR smbconf_reg_open_base_key(TALLOC_CTX *mem_ctx, 156 struct smbconf_ctx *ctx, 157 uint32 desired_access, 158 struct registry_key **key) 159 { 160 return smbconf_reg_open_path(mem_ctx, ctx, ctx->path, desired_access, 161 key); 86 *key = rpd(ctx)->base_key; 87 return WERR_OK; 88 } 89 werr = reg_openkey(mem_ctx, rpd(ctx)->base_key, servicename, 90 desired_access, key); 91 92 if (W_ERROR_EQUAL(werr, WERR_BADFILE)) { 93 werr = WERR_NO_SUCH_SERVICE; 94 } 95 96 return werr; 162 97 } 163 98 … … 177 112 } 178 113 179 TALLOC_FREE(ctx);114 talloc_free(ctx); 180 115 return ret; 181 116 } … … 190 125 { 191 126 WERROR werr = WERR_OK; 192 struct registry_key *create_parent = NULL;193 127 TALLOC_CTX *create_ctx; 194 128 enum winreg_CreateAction action = REG_ACTION_NONE; … … 199 133 create_ctx = talloc_stackframe(); 200 134 201 werr = smbconf_reg_open_base_key(create_ctx, ctx, REG_KEY_WRITE, 202 &create_parent); 203 if (!W_ERROR_IS_OK(werr)) { 204 goto done; 205 } 206 207 werr = reg_createkey(mem_ctx, create_parent, subkeyname, 135 werr = reg_createkey(mem_ctx, rpd(ctx)->base_key, subkeyname, 208 136 REG_KEY_WRITE, newkey, &action); 209 137 if (W_ERROR_IS_OK(werr) && (action != REG_CREATED_NEW_KEY)) { … … 216 144 } 217 145 218 done: 219 TALLOC_FREE(create_ctx); 146 talloc_free(create_ctx); 220 147 return werr; 221 148 } … … 332 259 333 260 done: 334 TALLOC_FREE(tmp_ctx);261 talloc_free(tmp_ctx); 335 262 return werr; 336 263 } … … 437 364 438 365 done: 439 TALLOC_FREE(tmp_ctx);366 talloc_free(tmp_ctx); 440 367 return werr; 441 368 } … … 534 461 535 462 done: 536 TALLOC_FREE(tmp_ctx);463 talloc_free(tmp_ctx); 537 464 return werr; 538 465 } … … 593 520 594 521 done: 595 TALLOC_FREE(mem_ctx);522 talloc_free(mem_ctx); 596 523 return werr; 597 524 } … … 609 536 { 610 537 WERROR werr = WERR_OK; 538 struct nt_user_token *token; 611 539 612 540 if (path == NULL) { … … 621 549 ctx->data = TALLOC_ZERO_P(ctx, struct reg_private_data); 622 550 623 werr = ntstatus_to_werror(registry_create_admin_token(ctx, 624 &(rpd(ctx)->token))); 551 werr = ntstatus_to_werror(registry_create_admin_token(ctx, &token)); 625 552 if (!W_ERROR_IS_OK(werr)) { 626 553 DEBUG(1, ("Error creating admin token\n")); … … 634 561 } 635 562 563 werr = ctx->ops->open_conf(ctx); 564 if (!W_ERROR_IS_OK(werr)) { 565 DEBUG(1, ("Error opening the registry.\n")); 566 goto done; 567 } 568 569 werr = reg_open_path(ctx, ctx->path, 570 SEC_RIGHTS_ENUM_SUBKEYS | REG_KEY_WRITE, 571 token, &rpd(ctx)->base_key); 572 if (!W_ERROR_IS_OK(werr)) { 573 goto done; 574 } 575 636 576 done: 637 577 return werr; … … 641 581 { 642 582 return ctx->ops->close_conf(ctx); 583 } 584 585 static bool smbconf_reg_requires_messaging(struct smbconf_ctx *ctx) 586 { 587 #ifdef CLUSTER_SUPPORT 588 if (lp_clustering() && lp_parm_bool(-1, "ctdb", "registry.tdb", true)) { 589 return true; 590 } 591 #endif 592 return false; 593 } 594 595 static bool smbconf_reg_is_writeable(struct smbconf_ctx *ctx) 596 { 597 /* 598 * The backend has write support. 599 * 600 * TODO: add access checks whether the concrete 601 * config source is really writeable by the calling user. 602 */ 603 return true; 643 604 } 644 605 … … 703 664 TALLOC_CTX* mem_ctx = talloc_stackframe(); 704 665 enum winreg_CreateAction action; 666 struct nt_user_token *token; 667 668 werr = ntstatus_to_werror(registry_create_admin_token(ctx, &token)); 669 if (!W_ERROR_IS_OK(werr)) { 670 DEBUG(1, ("Error creating admin token\n")); 671 goto done; 672 } 705 673 706 674 path = talloc_strdup(mem_ctx, ctx->path); … … 711 679 p = strrchr(path, '\\'); 712 680 *p = '\0'; 713 werr = smbconf_reg_open_path(mem_ctx, ctx, path, REG_KEY_WRITE,714 681 werr = reg_open_path(mem_ctx, path, REG_KEY_WRITE, token, 682 &parent_key); 715 683 716 684 if (!W_ERROR_IS_OK(werr)) { … … 728 696 729 697 done: 730 TALLOC_FREE(mem_ctx);698 talloc_free(mem_ctx); 731 699 return werr; 732 700 } … … 745 713 TALLOC_CTX *tmp_ctx = NULL; 746 714 WERROR werr = WERR_OK; 747 struct registry_key *key = NULL;748 715 char *subkey_name = NULL; 749 716 char **tmp_share_names = NULL; … … 757 724 758 725 /* if there are values in the base key, return NULL as share name */ 759 werr = smbconf_reg_open_base_key(tmp_ctx, ctx, 760 SEC_RIGHTS_ENUM_SUBKEYS, &key); 761 if (!W_ERROR_IS_OK(werr)) { 762 goto done; 763 } 764 765 if (smbconf_reg_key_has_values(key)) { 726 727 if (smbconf_reg_key_has_values(rpd(ctx)->base_key)) { 766 728 werr = smbconf_add_string_to_array(tmp_ctx, &tmp_share_names, 767 729 0, NULL); … … 783 745 784 746 for (count = 0; 785 werr = reg_enumkey(tmp_ctx, key, count, &subkey_name, NULL), 747 werr = reg_enumkey(tmp_ctx, rpd(ctx)->base_key, count, 748 &subkey_name, NULL), 786 749 W_ERROR_IS_OK(werr); 787 750 count++) … … 813 776 814 777 done: 815 TALLOC_FREE(tmp_ctx);778 talloc_free(tmp_ctx); 816 779 return werr; 817 780 } … … 834 797 } 835 798 836 TALLOC_FREE(mem_ctx);799 talloc_free(mem_ctx); 837 800 return ret; 838 801 } … … 845 808 { 846 809 WERROR werr; 847 TALLOC_CTX *mem_ctx = talloc_stackframe();848 810 struct registry_key *key = NULL; 849 811 850 812 if (servicename == NULL) { 851 werr = smbconf_reg_open_base_key(mem_ctx, ctx, REG_KEY_WRITE, 852 &key); 853 } else { 854 werr = smbconf_reg_create_service_key(mem_ctx, ctx, 855 servicename, &key); 856 } 857 858 TALLOC_FREE(mem_ctx); 813 return WERR_OK; 814 } 815 816 werr = smbconf_reg_create_service_key(talloc_tos(), ctx, 817 servicename, &key); 818 819 talloc_free(key); 859 820 return werr; 860 821 } … … 903 864 904 865 done: 905 TALLOC_FREE(tmp_ctx);866 talloc_free(tmp_ctx); 906 867 return werr; 907 868 } … … 914 875 { 915 876 WERROR werr = WERR_OK; 916 struct registry_key *key = NULL;917 877 TALLOC_CTX *mem_ctx = talloc_stackframe(); 918 878 919 werr = smbconf_reg_open_base_key(mem_ctx, ctx, REG_KEY_WRITE, &key);920 if (!W_ERROR_IS_OK(werr)) {921 goto done;922 }923 924 879 if (servicename != NULL) { 925 werr = reg_deletekey_recursive(key, key, servicename); 880 werr = reg_deletekey_recursive(mem_ctx, rpd(ctx)->base_key, 881 servicename); 926 882 } else { 927 werr = smbconf_reg_delete_values(key); 928 } 929 930 done: 931 TALLOC_FREE(mem_ctx); 883 werr = smbconf_reg_delete_values(rpd(ctx)->base_key); 884 } 885 886 talloc_free(mem_ctx); 932 887 return werr; 933 888 } … … 954 909 955 910 done: 956 TALLOC_FREE(mem_ctx);911 talloc_free(mem_ctx); 957 912 return werr; 958 913 } … … 999 954 1000 955 done: 1001 TALLOC_FREE(key);1002 TALLOC_FREE(value);956 talloc_free(key); 957 talloc_free(value); 1003 958 return werr; 1004 959 } … … 1034 989 1035 990 done: 1036 TALLOC_FREE(mem_ctx);991 talloc_free(mem_ctx); 1037 992 return werr; 1038 993 } … … 1058 1013 1059 1014 done: 1060 TALLOC_FREE(tmp_ctx);1015 talloc_free(tmp_ctx); 1061 1016 return werr; 1062 1017 } … … 1088 1043 1089 1044 done: 1090 TALLOC_FREE(tmp_ctx);1045 talloc_free(tmp_ctx); 1091 1046 return werr; 1092 1047 } … … 1113 1068 1114 1069 done: 1115 TALLOC_FREE(tmp_ctx); 1116 return werr; 1070 talloc_free(tmp_ctx); 1071 return werr; 1072 } 1073 1074 static WERROR smbconf_reg_transaction_start(struct smbconf_ctx *ctx) 1075 { 1076 return regdb_transaction_start(); 1077 } 1078 1079 static WERROR smbconf_reg_transaction_commit(struct smbconf_ctx *ctx) 1080 { 1081 return regdb_transaction_commit(); 1082 } 1083 1084 static WERROR smbconf_reg_transaction_cancel(struct smbconf_ctx *ctx) 1085 { 1086 return regdb_transaction_cancel(); 1117 1087 } 1118 1088 … … 1120 1090 .init = smbconf_reg_init, 1121 1091 .shutdown = smbconf_reg_shutdown, 1092 .requires_messaging = smbconf_reg_requires_messaging, 1093 .is_writeable = smbconf_reg_is_writeable, 1122 1094 .open_conf = smbconf_reg_open, 1123 1095 .close_conf = smbconf_reg_close, … … 1135 1107 .set_includes = smbconf_reg_set_includes, 1136 1108 .delete_includes = smbconf_reg_delete_includes, 1109 .transaction_start = smbconf_reg_transaction_start, 1110 .transaction_commit = smbconf_reg_transaction_commit, 1111 .transaction_cancel = smbconf_reg_transaction_cancel, 1137 1112 }; 1138 1113 -
branches/samba-3.3.x/source/lib/smbconf/smbconf_txt.c
r206 r223 139 139 smbconf_find_in_array(param_name, param_names, num_params, &idx)) 140 140 { 141 TALLOC_FREE(param_values[idx]);141 talloc_free(param_values[idx]); 142 142 param_values[idx] = talloc_strdup(cache, param_value); 143 143 if (param_values[idx] == NULL) { … … 161 161 static void smbconf_txt_flush_cache(struct smbconf_ctx *ctx) 162 162 { 163 TALLOC_FREE(pd(ctx)->cache); 163 talloc_free(pd(ctx)->cache); 164 pd(ctx)->cache = NULL; 164 165 } 165 166 … … 222 223 { 223 224 if (path == NULL) { 224 path = get_dyn_CONFIGFILE();225 return WERR_BADFILE; 225 226 } 226 227 ctx->path = talloc_strdup(ctx, path); … … 242 243 { 243 244 return ctx->ops->close_conf(ctx); 245 } 246 247 static bool smbconf_txt_requires_messaging(struct smbconf_ctx *ctx) 248 { 249 return false; 250 } 251 252 static bool smbconf_txt_is_writeable(struct smbconf_ctx *ctx) 253 { 254 /* no write support in this backend yet... */ 255 return false; 244 256 } 245 257 … … 349 361 350 362 done: 351 TALLOC_FREE(tmp_ctx);363 talloc_free(tmp_ctx); 352 364 return werr; 353 365 } … … 448 460 449 461 done: 450 TALLOC_FREE(tmp_ctx);462 talloc_free(tmp_ctx); 451 463 return werr; 452 464 } … … 583 595 584 596 done: 585 TALLOC_FREE(tmp_ctx);597 talloc_free(tmp_ctx); 586 598 return werr; 587 599 } … … 601 613 } 602 614 615 static WERROR smbconf_txt_transaction_start(struct smbconf_ctx *ctx) 616 { 617 return WERR_OK; 618 } 619 620 static WERROR smbconf_txt_transaction_commit(struct smbconf_ctx *ctx) 621 { 622 return WERR_OK; 623 } 624 625 static WERROR smbconf_txt_transaction_cancel(struct smbconf_ctx *ctx) 626 { 627 return WERR_OK; 628 } 603 629 604 630 static struct smbconf_ops smbconf_ops_txt = { 605 631 .init = smbconf_txt_init, 606 632 .shutdown = smbconf_txt_shutdown, 633 .requires_messaging = smbconf_txt_requires_messaging, 634 .is_writeable = smbconf_txt_is_writeable, 607 635 .open_conf = smbconf_txt_open, 608 636 .close_conf = smbconf_txt_close, … … 620 648 .set_includes = smbconf_txt_set_includes, 621 649 .delete_includes = smbconf_txt_delete_includes, 650 .transaction_start = smbconf_txt_transaction_start, 651 .transaction_commit = smbconf_txt_transaction_commit, 652 .transaction_cancel = smbconf_txt_transaction_cancel, 622 653 }; 623 654 -
branches/samba-3.3.x/source/lib/smbconf/smbconf_util.c
r206 r223 68 68 69 69 fail: 70 TALLOC_FREE(ctx);70 talloc_free(ctx); 71 71 return werr; 72 72 } … … 97 97 new_array[count] = talloc_strdup(new_array, string); 98 98 if (new_array[count] == NULL) { 99 TALLOC_FREE(new_array);99 talloc_free(new_array); 100 100 return WERR_NOMEM; 101 101 } -
branches/samba-3.3.x/source/lib/smbconf/testsuite.c
r206 r223 42 42 TALLOC_CTX *mem_ctx = talloc_stackframe(); 43 43 44 printf(" test: get_includes\n");44 printf("TEST: get_includes\n"); 45 45 werr = smbconf_get_global_includes(ctx, mem_ctx, 46 46 &num_includes, &includes); 47 47 if (!W_ERROR_IS_OK(werr)) { 48 printf(" failure: get_includes - %s\n", dos_errstr(werr));48 printf("FAIL: get_includes - %s\n", dos_errstr(werr)); 49 49 goto done; 50 50 } … … 54 54 print_strings("", num_includes, (const char **)includes); 55 55 56 printf(" success: get_includes\n");56 printf("OK: get_includes\n"); 57 57 ret = true; 58 58 59 59 done: 60 TALLOC_FREE(mem_ctx);60 talloc_free(mem_ctx); 61 61 return ret; 62 62 } … … 76 76 TALLOC_CTX *mem_ctx = talloc_stackframe(); 77 77 78 printf(" test: set_get_includes\n");78 printf("TEST: set_get_includes\n"); 79 79 80 80 werr = smbconf_set_global_includes(ctx, set_num_includes, set_includes); 81 81 if (!W_ERROR_IS_OK(werr)) { 82 printf(" failure: get_set_includes (setting includes) - %s\n",82 printf("FAIL: get_set_includes (setting includes) - %s\n", 83 83 dos_errstr(werr)); 84 84 goto done; … … 88 88 &get_includes); 89 89 if (!W_ERROR_IS_OK(werr)) { 90 printf(" failure: get_set_includes (getting includes) - %s\n",90 printf("FAIL: get_set_includes (getting includes) - %s\n", 91 91 dos_errstr(werr)); 92 92 goto done; … … 94 94 95 95 if (get_num_includes != set_num_includes) { 96 printf(" failure: get_set_includes - set %d includes, got %d\n",96 printf("FAIL: get_set_includes - set %d includes, got %d\n", 97 97 set_num_includes, get_num_includes); 98 98 goto done; … … 106 106 print_strings("* ", get_num_includes, 107 107 (const char **)get_includes); 108 printf(" failure: get_set_includes - data mismatch:\n");108 printf("FAIL: get_set_includes - data mismatch:\n"); 109 109 goto done; 110 110 } 111 111 } 112 112 113 printf(" success: set_includes\n");113 printf("OK: set_includes\n"); 114 114 ret = true; 115 115 116 116 done: 117 TALLOC_FREE(mem_ctx);117 talloc_free(mem_ctx); 118 118 return ret; 119 119 } … … 131 131 TALLOC_CTX *mem_ctx = talloc_stackframe(); 132 132 133 printf(" test: delete_includes\n");133 printf("TEST: delete_includes\n"); 134 134 135 135 werr = smbconf_set_global_includes(ctx, set_num_includes, set_includes); 136 136 if (!W_ERROR_IS_OK(werr)) { 137 printf(" failure: delete_includes (setting includes) - %s\n",137 printf("FAIL: delete_includes (setting includes) - %s\n", 138 138 dos_errstr(werr)); 139 139 goto done; … … 142 142 werr = smbconf_delete_global_includes(ctx); 143 143 if (!W_ERROR_IS_OK(werr)) { 144 printf(" failure: delete_includes (deleting includes) - %s\n",144 printf("FAIL: delete_includes (deleting includes) - %s\n", 145 145 dos_errstr(werr)); 146 146 goto done; … … 150 150 &get_includes); 151 151 if (!W_ERROR_IS_OK(werr)) { 152 printf(" failure: delete_includes (getting includes) - %s\n",152 printf("FAIL: delete_includes (getting includes) - %s\n", 153 153 dos_errstr(werr)); 154 154 goto done; … … 156 156 157 157 if (get_num_includes != 0) { 158 printf(" failure: delete_includes (not empty after delete)\n");158 printf("FAIL: delete_includes (not empty after delete)\n"); 159 159 goto done; 160 160 } … … 162 162 werr = smbconf_delete_global_includes(ctx); 163 163 if (!W_ERROR_IS_OK(werr)) { 164 printf(" failuer: delete_includes (delete empty includes) - "164 printf("FAIL: delete_includes (delete empty includes) - " 165 165 "%s\n", dos_errstr(werr)); 166 166 goto done; 167 167 } 168 168 169 printf(" success: delete_includes\n");169 printf("OK: delete_includes\n"); 170 170 ret = true; 171 171 … … 174 174 } 175 175 176 static bool create_conf_file(const char *filename) 177 { 178 FILE *f; 179 180 printf("TEST: creating file\n"); 181 f = sys_fopen(filename, "w"); 182 if (!f) { 183 printf("failure: failed to open %s for writing: %s\n", 184 filename, strerror(errno)); 185 return false; 186 } 187 188 fprintf(f, "[global]\n"); 189 fprintf(f, "\tserver string = smbconf testsuite\n"); 190 fprintf(f, "\tworkgroup = SAMBA\n"); 191 fprintf(f, "\tsecurity = user\n"); 192 193 fclose(f); 194 195 printf("OK: create file\n"); 196 return true; 197 } 198 176 199 static bool torture_smbconf_txt(void) 200 { 201 WERROR werr; 202 bool ret = true; 203 const char *filename = "/tmp/smb.conf.smbconf_testsuite"; 204 struct smbconf_ctx *conf_ctx = NULL; 205 TALLOC_CTX *mem_ctx = talloc_stackframe(); 206 207 printf("test: text backend\n"); 208 209 if (!create_conf_file(filename)) { 210 ret = false; 211 goto done; 212 } 213 214 printf("TEST: init\n"); 215 werr = smbconf_init_txt(mem_ctx, &conf_ctx, filename); 216 if (!W_ERROR_IS_OK(werr)) { 217 printf("FAIL: text backend\[ failed: %s\n", dos_errstr(werr)); 218 ret = false; 219 goto done; 220 } 221 printf("OK: init\n"); 222 223 ret &= test_get_includes(conf_ctx); 224 225 smbconf_shutdown(conf_ctx); 226 227 printf("TEST: unlink file\n"); 228 if (unlink(filename) != 0) { 229 printf("OK: unlink failed: %s\n", strerror(errno)); 230 ret = false; 231 goto done; 232 } 233 printf("OK: unlink file\n"); 234 235 done: 236 printf("%s: text backend\n", ret ? "success" : "failure"); 237 talloc_free(mem_ctx); 238 return ret; 239 } 240 241 static bool torture_smbconf_reg(void) 177 242 { 178 243 WERROR werr; … … 181 246 TALLOC_CTX *mem_ctx = talloc_stackframe(); 182 247 183 printf("test: textbackend\n");184 185 printf(" test: init\n");186 werr = smbconf_init_ txt(mem_ctx, &conf_ctx, NULL);187 if (!W_ERROR_IS_OK(werr)) { 188 printf(" failure: init failed: %s\n", dos_errstr(werr));248 printf("test: registry backend\n"); 249 250 printf("TEST: init\n"); 251 werr = smbconf_init_reg(mem_ctx, &conf_ctx, NULL); 252 if (!W_ERROR_IS_OK(werr)) { 253 printf("FAIL: init failed: %s\n", dos_errstr(werr)); 189 254 ret = false; 190 255 goto done; 191 256 } 192 printf("success: init\n"); 193 194 ret &= test_get_includes(conf_ctx); 195 196 smbconf_shutdown(conf_ctx); 197 198 printf("%s: text backend\n", ret ? "success" : "failure"); 199 200 done: 201 TALLOC_FREE(mem_ctx); 202 return ret; 203 } 204 205 static bool torture_smbconf_reg(void) 206 { 207 WERROR werr; 208 bool ret = true; 209 struct smbconf_ctx *conf_ctx = NULL; 210 TALLOC_CTX *mem_ctx = talloc_stackframe(); 211 212 printf("test: registry backend\n"); 213 214 printf("test: init\n"); 215 werr = smbconf_init_reg(mem_ctx, &conf_ctx, NULL); 216 if (!W_ERROR_IS_OK(werr)) { 217 printf("failure: init failed: %s\n", dos_errstr(werr)); 218 ret = false; 219 goto done; 220 } 221 printf("success: init\n"); 257 printf("OK: init\n"); 222 258 223 259 ret &= test_get_includes(conf_ctx); … … 227 263 smbconf_shutdown(conf_ctx); 228 264 265 done: 229 266 printf("%s: registry backend\n", ret ? "success" : "failure"); 230 231 done: 232 TALLOC_FREE(mem_ctx); 267 talloc_free(mem_ctx); 233 268 return ret; 234 269 } … … 279 314 280 315 done: 281 TALLOC_FREE(mem_ctx);316 talloc_free(mem_ctx); 282 317 return ret ? 0 : -1; 283 318 }
Note:
See TracChangeset
for help on using the changeset viewer.