NTSTATUS torture_local_init(void) { int i; struct torture_suite *suite = torture_suite_create( talloc_autofree_context(), "LOCAL"); torture_suite_add_simple_test(suite, "TALLOC", torture_local_talloc); torture_suite_add_simple_test(suite, "REPLACE", torture_local_replace); torture_suite_add_simple_test(suite, "CRYPTO-SHA1", torture_local_crypto_sha1); torture_suite_add_simple_test(suite, "CRYPTO-MD4", torture_local_crypto_md4); torture_suite_add_simple_test(suite, "CRYPTO-MD5", torture_local_crypto_md5); torture_suite_add_simple_test(suite, "CRYPTO-HMACMD5", torture_local_crypto_hmacmd5); torture_suite_add_simple_test(suite, "CRYPTO-HMACSHA1", torture_local_crypto_hmacsha1); for (i = 0; suite_generators[i]; i++) torture_suite_add_suite(suite, suite_generators[i](talloc_autofree_context())); suite->description = talloc_strdup(suite, "Local, Samba-specific tests"); torture_register_suite(suite); return NT_STATUS_OK; }
NTSTATUS torture_local_init(void) { int i; struct torture_suite *suite = torture_suite_create( talloc_autofree_context(), "local"); torture_suite_add_simple_test(suite, "talloc", torture_local_talloc); torture_suite_add_simple_test(suite, "replace", torture_local_replace); torture_suite_add_simple_test(suite, "crypto.md4", torture_local_crypto_md4); torture_suite_add_simple_test(suite, "crypto.md5", torture_local_crypto_md5); torture_suite_add_simple_test(suite, "crypto.hmacmd5", torture_local_crypto_hmacmd5); for (i = 0; suite_generators[i]; i++) torture_suite_add_suite(suite, suite_generators[i](talloc_autofree_context())); suite->description = talloc_strdup(suite, "Local, Samba-specific tests"); torture_register_suite(suite); return NT_STATUS_OK; }
/** * Add an element to the schema (attribute or class) from an LDB message */ WERROR dsdb_schema_set_el_from_ldb_msg(struct ldb_context *ldb, struct dsdb_schema *schema, struct ldb_message *msg) { static struct ldb_parse_tree *attr_tree, *class_tree; if (!attr_tree) { attr_tree = ldb_parse_tree(talloc_autofree_context(), "(objectClass=attributeSchema)"); if (!attr_tree) { return WERR_NOMEM; } } if (!class_tree) { class_tree = ldb_parse_tree(talloc_autofree_context(), "(objectClass=classSchema)"); if (!class_tree) { return WERR_NOMEM; } } if (ldb_match_msg(ldb, msg, attr_tree, NULL, LDB_SCOPE_BASE)) { return dsdb_attribute_from_ldb(ldb, schema, msg); } else if (ldb_match_msg(ldb, msg, class_tree, NULL, LDB_SCOPE_BASE)) { return dsdb_class_from_ldb(schema, msg); } /* Don't fail on things not classes or attributes */ return WERR_OK; }
static bool test_autofree(void) { void *p; printf("test: autofree [\nTALLOC AUTOFREE CONTEXT\n]\n"); p = talloc_autofree_context(); talloc_free(p); p = talloc_autofree_context(); talloc_free(p); printf("success: autofree\n"); return true; }
/** * Return the path to a directory where temporary files should be * created. */ const char *get_temp_directory() { static const char *temp_directory = NULL; char *tmp; if (temp_directory != NULL) return temp_directory; temp_directory = getenv("PROOT_TMP_DIR"); if (temp_directory == NULL) { temp_directory = P_tmpdir; return temp_directory; } tmp = realpath(temp_directory, NULL); if (tmp == NULL) { note(NULL, WARNING, SYSTEM, "can't canonicalize %s, using %s instead of PROOT_TMP_DIR", temp_directory, P_tmpdir); temp_directory = P_tmpdir; return temp_directory; } temp_directory = talloc_strdup(talloc_autofree_context(), tmp); if (temp_directory == NULL) temp_directory = tmp; else free(tmp); return temp_directory; }
/* a useful helper function for printing idl structures to a string */ _PUBLIC_ char *ndr_print_struct_string(TALLOC_CTX *mem_ctx, ndr_print_fn_t fn, const char *name, void *ptr) { struct ndr_print *ndr; char *ret = NULL; ndr = talloc_zero(mem_ctx, struct ndr_print); if (!ndr) return NULL; ndr->private_data = talloc_strdup(ndr, ""); if (!ndr->private_data) { goto failed; } ndr->print = ndr_print_string_helper; ndr->depth = 1; ndr->flags = 0; /* this is a s4 hack until we build up the courage to pass * this all the way down */ #if _SAMBA_BUILD_ == 4 ndr->iconv_convenience = smb_iconv_convenience_init(talloc_autofree_context(), "ASCII", "UTF-8", true); #endif fn(ndr, name, ptr); ret = talloc_steal(mem_ctx, (char *)ndr->private_data); failed: talloc_free(ndr); return ret; }
struct passwd *getpwnam_alloc(TALLOC_CTX *mem_ctx, const char *name) { struct passwd *pw, *for_cache; pw = (struct passwd *)memcache_lookup_talloc( NULL, GETPWNAM_CACHE, data_blob_string_const(name)); if (pw != NULL) { return tcopy_passwd(mem_ctx, pw); } pw = sys_getpwnam(name); if (pw == NULL) { return NULL; } for_cache = tcopy_passwd(talloc_autofree_context(), pw); if (for_cache == NULL) { return NULL; } memcache_add_talloc(NULL, GETPWNAM_CACHE, data_blob_string_const(name), &for_cache); return tcopy_passwd(mem_ctx, pw); }
/** \details Initialize ldb_context to samdb, creates one for all emsmdbp contexts \param lp_ctx pointer to the loadparm context */ static struct ldb_context *samdb_init(struct loadparm_context *lp_ctx) { TALLOC_CTX *mem_ctx; struct tevent_context *ev; const char *samdb_url; if (samdb_ctx) return samdb_ctx; mem_ctx = talloc_autofree_context(); ev = tevent_context_init(mem_ctx); if (!ev) { OC_PANIC(false, ("Fail to initialize tevent_context\n")); return NULL; } tevent_loop_allow_nesting(ev); /* Retrieve samdb url (local or external) */ samdb_url = lpcfg_parm_string(lp_ctx, NULL, "dcerpc_mapiproxy", "samdb_url"); if (!samdb_url) { samdb_ctx = samdb_connect(mem_ctx, ev, lp_ctx, system_session(lp_ctx), 0); } else { samdb_ctx = samdb_connect_url(mem_ctx, ev, lp_ctx, system_session(lp_ctx), LDB_FLG_RECONNECT, samdb_url); } return samdb_ctx; }
/*************************************************************************** authenticate when we are running as a CGI ***************************************************************************/ static void cgi_web_auth(void) { const char *user = getenv("REMOTE_USER"); struct passwd *pwd; const char *head = "Content-Type: text/html\r\n\r\n<HTML><BODY><H1>SWAT installation Error</H1>\n"; const char *tail = "</BODY></HTML>\r\n"; if (!user) { printf("%sREMOTE_USER not set. Not authenticated by web server.<br>%s\n", head, tail); exit(0); } pwd = getpwnam_alloc(talloc_autofree_context(), user); if (!pwd) { printf("%sCannot find user %s<br>%s\n", head, user, tail); exit(0); } setuid(0); setuid(pwd->pw_uid); if (geteuid() != pwd->pw_uid || getuid() != pwd->pw_uid) { printf("%sFailed to become user %s - uid=%d/%d<br>%s\n", head, user, (int)geteuid(), (int)getuid(), tail); exit(0); } TALLOC_FREE(pwd); }
NTSTATUS torture_krb5_init(void) { struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "krb5"); struct torture_suite *kdc_suite = torture_suite_create(suite, "kdc"); suite->description = talloc_strdup(suite, "Kerberos tests"); kdc_suite->description = talloc_strdup(kdc_suite, "Kerberos KDC tests"); torture_suite_add_simple_test(kdc_suite, "as-req-cmdline", torture_krb5_as_req_cmdline); torture_suite_add_simple_test(kdc_suite, "as-req-pac-request", torture_krb5_as_req_pac_request); torture_suite_add_simple_test(kdc_suite, "as-req-break-pw", torture_krb5_as_req_break_pw); torture_suite_add_simple_test(kdc_suite, "as-req-clock-skew", torture_krb5_as_req_clock_skew); torture_suite_add_suite(kdc_suite, torture_krb5_canon(kdc_suite)); torture_suite_add_suite(suite, kdc_suite); torture_register_suite(suite); return NT_STATUS_OK; }
static Suite *openchangedb_create_suite(SFun setup, SFun teardown) { char *suite_name = talloc_asprintf(talloc_autofree_context(), "Openchangedb Logger backend"); Suite *s = suite_create(suite_name); TCase *tc = tcase_create("Openchangedb Logger interface"); tcase_add_checked_fixture(tc, setup, teardown); tcase_add_test(tc, test_call_get_SpecialFolderID); tcase_add_test(tc, test_call_get_SystemFolderID); tcase_add_test(tc, test_call_get_PublicFolderID); tcase_add_test(tc, test_call_get_distinguishedName); tcase_add_test(tc, test_call_get_MailboxGuid); tcase_add_test(tc, test_call_get_MailboxReplica); tcase_add_test(tc, test_call_get_PublicFolderReplica); tcase_add_test(tc, test_call_get_mapistoreURI); tcase_add_test(tc, test_call_set_mapistoreURI); tcase_add_test(tc, test_call_get_parent_fid); tcase_add_test(tc, test_call_get_fid); tcase_add_test(tc, test_call_get_MAPIStoreURIs); tcase_add_test(tc, test_call_get_ReceiveFolder); tcase_add_test(tc, test_call_replica_mapping_guid_to_replid); tcase_add_test(tc, test_call_replica_mapping_replid_to_guid); suite_add_tcase(s, tc); return s; }
struct torture_suite *torture_wbclient(void) { struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "wbclient"); torture_suite_add_simple_test(suite, "wbcPing", test_wbc_ping); torture_suite_add_simple_test(suite, "wbcPingDc", test_wbc_pingdc); torture_suite_add_simple_test(suite, "wbcLibraryDetails", test_wbc_library_details); torture_suite_add_simple_test(suite, "wbcInterfaceDetails", test_wbc_interface_details); torture_suite_add_simple_test(suite, "wbcSidTypeString", test_wbc_sidtypestring); torture_suite_add_simple_test(suite, "wbcSidToString", test_wbc_sidtostring); torture_suite_add_simple_test(suite, "wbcGuidToString", test_wbc_guidtostring); torture_suite_add_simple_test(suite, "wbcDomainInfo", test_wbc_domain_info); torture_suite_add_simple_test(suite, "wbcListUsers", test_wbc_users); torture_suite_add_simple_test(suite, "wbcListGroups", test_wbc_groups); torture_suite_add_simple_test(suite, "wbcListTrusts", test_wbc_trusts); torture_suite_add_simple_test(suite, "wbcLookupDomainController", test_wbc_lookupdc); torture_suite_add_simple_test(suite, "wbcLookupDomainControllerEx", test_wbc_lookupdcex); torture_suite_add_simple_test(suite, "wbcResolveWinsByName", test_wbc_resolve_winsbyname); torture_suite_add_simple_test(suite, "wbcResolveWinsByIP", test_wbc_resolve_winsbyip); torture_suite_add_simple_test(suite, "wbcLookupRids", test_wbc_lookup_rids); torture_suite_add_simple_test(suite, "wbcGetSidAliases", test_wbc_get_sidaliases); torture_suite_add_simple_test(suite, "wbcAuthenticateUser", test_wbc_authenticate_user); torture_suite_add_simple_test(suite, "wbcLogonUser", test_wbc_logon_user); torture_suite_add_simple_test(suite, "wbcChangeUserPassword", test_wbc_change_password); torture_suite_add_simple_test(suite, "wbcGetGroups", test_wbc_getgroups); return suite; }
NTSTATUS torture_smb2_init(void) { struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "SMB2"); torture_suite_add_simple_test(suite, "CONNECT", torture_smb2_connect); torture_suite_add_simple_test(suite, "SCAN", torture_smb2_scan); torture_suite_add_simple_test(suite, "SCANGETINFO", torture_smb2_getinfo_scan); torture_suite_add_simple_test(suite, "SCANSETINFO", torture_smb2_setinfo_scan); torture_suite_add_simple_test(suite, "SCANFIND", torture_smb2_find_scan); torture_suite_add_simple_test(suite, "GETINFO", torture_smb2_getinfo); torture_suite_add_simple_test(suite, "SETINFO", torture_smb2_setinfo); torture_suite_add_simple_test(suite, "FIND", torture_smb2_find); torture_suite_add_suite(suite, torture_smb2_lock_init()); torture_suite_add_suite(suite, torture_smb2_read_init()); torture_suite_add_suite(suite, torture_smb2_create_init()); torture_suite_add_simple_test(suite, "NOTIFY", torture_smb2_notify); torture_suite_add_suite(suite, torture_smb2_durable_open_init()); torture_suite_add_1smb2_test(suite, "OPLOCK-BATCH1", torture_smb2_oplock_batch1); torture_suite_add_suite(suite, torture_smb2_lease_init()); suite->description = talloc_strdup(suite, "SMB2-specific tests"); torture_register_suite(suite); return NT_STATUS_OK; }
static bool parse_target(struct loadparm_context *lp_ctx, const char *target) { char *host = NULL, *share = NULL; struct dcerpc_binding *binding_struct; NTSTATUS status; /* see if its a RPC transport specifier */ if (!smbcli_parse_unc(target, NULL, &host, &share)) { status = dcerpc_parse_binding(talloc_autofree_context(), target, &binding_struct); if (NT_STATUS_IS_ERR(status)) { d_printf("Invalid option: %s is not a valid torture target (share or binding string)\n\n", target); return false; } lp_set_cmdline(lp_ctx, "torture:host", binding_struct->host); if (lp_parm_string(lp_ctx, NULL, "torture", "share") == NULL) lp_set_cmdline(lp_ctx, "torture:share", "IPC$"); lp_set_cmdline(lp_ctx, "torture:binding", target); } else { lp_set_cmdline(lp_ctx, "torture:host", host); lp_set_cmdline(lp_ctx, "torture:share", share); lp_set_cmdline(lp_ctx, "torture:binding", host); } return true; }
void dsdb_make_schema_global(struct ldb_context *ldb, struct dsdb_schema *schema) { if (!schema) { return; } if (global_schema) { talloc_unlink(talloc_autofree_context(), global_schema); } /* we want the schema to be around permanently */ talloc_reparent(ldb, talloc_autofree_context(), schema); global_schema = schema; /* This calls the talloc_reference() of the global schema back onto the ldb */ dsdb_set_global_schema(ldb); }
void glsl_type::init_talloc_type_ctx(void) { if (glsl_type::mem_ctx == NULL) { glsl_type::mem_ctx = talloc_autofree_context(); assert(glsl_type::mem_ctx != NULL); } }
static bool test_autofree(void) { #if _SAMBA_BUILD_ < 4 /* autofree test would kill smbtorture */ void *p; printf("test: autofree\n# TALLOC AUTOFREE CONTEXT\n"); p = talloc_autofree_context(); talloc_free(p); p = talloc_autofree_context(); talloc_free(p); printf("success: autofree\n"); #endif return true; }
NTSTATUS torture_raw_init(void) { struct torture_suite *suite = torture_suite_create( talloc_autofree_context(), "raw"); /* RAW smb tests */ torture_suite_add_simple_test(suite, "bench-oplock", torture_bench_oplock); torture_suite_add_simple_test(suite, "ping-pong", torture_ping_pong); torture_suite_add_simple_test(suite, "bench-lock", torture_bench_lock); torture_suite_add_simple_test(suite, "bench-open", torture_bench_open); torture_suite_add_simple_test(suite, "bench-lookup", torture_bench_lookup); torture_suite_add_simple_test(suite, "bench-tcon", torture_bench_treeconnect); torture_suite_add_simple_test(suite, "offline", torture_test_offline); torture_suite_add_1smb_test(suite, "qfsinfo", torture_raw_qfsinfo); torture_suite_add_1smb_test(suite, "qfileinfo", torture_raw_qfileinfo); torture_suite_add_1smb_test(suite, "qfileinfo.ipc", torture_raw_qfileinfo_pipe); torture_suite_add_suite(suite, torture_raw_sfileinfo(suite)); torture_suite_add_suite(suite, torture_raw_search(suite)); torture_suite_add_1smb_test(suite, "close", torture_raw_close); torture_suite_add_suite(suite, torture_raw_open(suite)); torture_suite_add_1smb_test(suite, "mkdir", torture_raw_mkdir); torture_suite_add_suite(suite, torture_raw_oplock(suite)); torture_suite_add_1smb_test(suite, "hold-oplock", torture_hold_oplock); torture_suite_add_2smb_test(suite, "notify", torture_raw_notify); torture_suite_add_1smb_test(suite, "mux", torture_raw_mux); torture_suite_add_1smb_test(suite, "ioctl", torture_raw_ioctl); torture_suite_add_1smb_test(suite, "chkpath", torture_raw_chkpath); torture_suite_add_suite(suite, torture_raw_unlink(suite)); torture_suite_add_suite(suite, torture_raw_read(suite)); torture_suite_add_suite(suite, torture_raw_write(suite)); torture_suite_add_suite(suite, torture_raw_lock(suite)); torture_suite_add_1smb_test(suite, "context", torture_raw_context); torture_suite_add_suite(suite, torture_raw_rename(suite)); torture_suite_add_1smb_test(suite, "seek", torture_raw_seek); torture_suite_add_1smb_test(suite, "eas", torture_raw_eas); torture_suite_add_suite(suite, torture_raw_streams(suite)); torture_suite_add_suite(suite, torture_raw_acls(suite)); torture_suite_add_1smb_test(suite, "composite", torture_raw_composite); torture_suite_add_simple_test(suite, "samba3hide", torture_samba3_hide); torture_suite_add_simple_test(suite, "samba3closeerr", torture_samba3_closeerr); torture_suite_add_simple_test(suite, "samba3rootdirfid", torture_samba3_rootdirfid); torture_suite_add_simple_test(suite, "samba3checkfsp", torture_samba3_checkfsp); torture_suite_add_simple_test(suite, "samba3oplocklogoff", torture_samba3_oplock_logoff); torture_suite_add_simple_test(suite, "samba3badpath", torture_samba3_badpath); torture_suite_add_simple_test(suite, "samba3caseinsensitive", torture_samba3_caseinsensitive); torture_suite_add_simple_test(suite, "samba3posixtimedlock", torture_samba3_posixtimedlock); torture_suite_add_simple_test(suite, "scan-eamax", torture_max_eas); suite->description = talloc_strdup(suite, "Tests for the raw SMB interface"); torture_register_suite(suite); return NT_STATUS_OK; }
void dsdb_make_schema_global(struct ldb_context *ldb) { struct dsdb_schema *schema = dsdb_get_schema(ldb); if (!schema) { return; } if (global_schema) { talloc_unlink(talloc_autofree_context(), global_schema); } /* we want the schema to be around permanently */ talloc_reparent(talloc_parent(schema), talloc_autofree_context(), schema); global_schema = schema; dsdb_set_global_schema(ldb); }
struct event_context *smbd_event_context(void) { if (!smbd_event_ctx) { smbd_event_ctx = event_context_init(talloc_autofree_context()); } if (!smbd_event_ctx) { smb_panic("Could not init smbd event context"); } return smbd_event_ctx; }
/* test name registration to a server */ struct torture_suite *torture_nbt_register(void) { struct torture_suite *suite; suite = torture_suite_create(talloc_autofree_context(), "REGISTER"); torture_suite_add_simple_test(suite, "register_own", nbt_register_own); torture_suite_add_simple_test(suite, "refresh_own", nbt_refresh_own); return suite; }
/* basic testing of SMB2 ioctls */ struct torture_suite *torture_smb2_ioctl_init(void) { struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "ioctl"); torture_suite_add_1smb2_test(suite, "shadow_copy", test_ioctl_get_shadow_copy); suite->description = talloc_strdup(suite, "SMB2-IOCTL tests"); return suite; }
} END_TEST // ^ unit tests --------------------------------------------------------------- // v suite definition --------------------------------------------------------- static void tc_IDSET_parse_setup(void) { mem_ctx = talloc_new(talloc_autofree_context()); }
} END_TEST // ^ Unit test ---------------------------------------------------------------- // v Suite definition --------------------------------------------------------- static void logon_table_setup(void) { g_mem_ctx = talloc_new(talloc_autofree_context()); }
/* register a lease backend */ _PUBLIC_ NTSTATUS sys_lease_register(const struct sys_lease_ops *backend) { struct sys_lease_ops *b; b = talloc_realloc(talloc_autofree_context(), backends, struct sys_lease_ops, num_backends+1); NT_STATUS_HAVE_NO_MEMORY(b); backends = b; backends[num_backends] = *backend; num_backends++; return NT_STATUS_OK; }
NTSTATUS torture_bind_dns_init(void) { struct torture_suite *suite; TALLOC_CTX *mem_ctx = talloc_autofree_context(); /* register DNS related test cases */ suite = dlz_bind9_suite(mem_ctx); if (!suite) return NT_STATUS_NO_MEMORY; torture_register_suite(suite); return NT_STATUS_OK; }
struct memcache *smbd_memcache(void) { if (!smbd_memcache_ctx) { smbd_memcache_ctx = memcache_init(talloc_autofree_context(), lp_max_stat_cache_size()*1024); } if (!smbd_memcache_ctx) { smb_panic("Could not init smbd memcache"); } return smbd_memcache_ctx; }
NTSTATUS com_register_running_class(struct GUID *clsid, const char *progid, struct IUnknown *p) { struct com_class *l = talloc_zero(running_classes?running_classes:talloc_autofree_context(), struct com_class); l->clsid = *clsid; l->progid = talloc_strdup(l, progid); l->class_object = p; DLIST_ADD(running_classes, l); return NT_STATUS_OK; }
NTSTATUS torture_winbind_init(void) { struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "WINBIND"); torture_suite_add_suite(suite, torture_winbind_struct_init()); suite->description = talloc_strdup(suite, "WINBIND tests"); torture_register_suite(suite); return NT_STATUS_OK; }
/** * DNS torture module initialization */ NTSTATUS torture_internal_dns_init(void) { struct torture_suite *suite; TALLOC_CTX *mem_ctx = talloc_autofree_context(); /* register internal DNS torture test cases */ suite = internal_dns_suite(mem_ctx); if (!suite) return NT_STATUS_NO_MEMORY; torture_register_suite(suite); return NT_STATUS_OK; }