Пример #1
0
/* Update the disclose database, adding when rm is zero, removing otherwise.
 * Documented in detail in poolback.h
 */
int update_disclose (struct pulleyback_tlspool *self, uint8_t **data, int rm) {
	dercursor lid;
	dercursor rid;
	lid.derlen = rid.derlen = 1030;  // Sane upper margin (errors beyond)
	lid.derptr = (uint8_t *) fetch_value (self, MXG_LOCALID , data);
	rid.derptr = (uint8_t *) fetch_value (self, MXG_REMOTEID, data);
	assert (lid.derptr != NULL);
	assert (rid.derptr != NULL);
	if (der_enter (&lid) || der_enter (&rid)) {
		// Perhaps length is too small, or DER formatting error
		return 0;
	}
	printf ("Updating disclose.db (%s): %.*s -> %.*s\n",
		rm ? "DEL" : "ADD",
		 (int)rid.derlen,
		 rid.derptr,
		 (int)lid.derlen,
		 lid.derptr
	);
	return update_db (self, &rid, &lid, -1, NULL, rm);
}
Пример #2
0
int main(int argc, char *argv[])
{
	exit_if_false(argc == 2,"exactly one input argument required");

	timer_start();

	//-------------------------------------------------------------------//
	
	// counters
	int i, n;

	// file paths
	char *input_file_path, *geometry_file_path, *case_file_path, *data_file_path, *data_numbered_file_path, *display_file_path, *display_numbered_file_path;
	exit_if_false(geometry_file_path = (char *)malloc(MAX_STRING_LENGTH * sizeof(char)),"allocating geometry file path");
	exit_if_false(case_file_path = (char *)malloc(MAX_STRING_LENGTH * sizeof(char)),"allocating case file path");
	exit_if_false(data_file_path = (char *)malloc(MAX_STRING_LENGTH * sizeof(char)),"allocating data file path");
	exit_if_false(data_numbered_file_path = (char *)malloc(MAX_STRING_LENGTH * sizeof(char)),"allocating data numbered file path");
	exit_if_false(display_file_path = (char *)malloc(MAX_STRING_LENGTH * sizeof(char)),"allocating display file path");
	exit_if_false(display_numbered_file_path = (char *)malloc(MAX_STRING_LENGTH * sizeof(char)),"allocating display numbered file path");

	// print string
	char *print;
	exit_if_false(print = (char *)malloc(MAX_STRING_LENGTH * sizeof(char)),"allocating the print string");

	// mesh structures
	int n_nodes, n_faces, n_elements, n_boundaries_old = 0, n_boundaries, n_terms;
	struct NODE *node;
	struct FACE *face;
	struct ELEMENT *element;
	struct BOUNDARY *boundary_old = NULL, *boundary;
	struct TERM *term;
	EXPRESSION *initial = NULL;
	
	// solution vectors
	int n_u_old = 0, n_u;
	double *u_old = NULL, *u;

	// files
	FILE *input_file, *case_file, *data_file, *geometry_file, *display_file;

	//-------------------------------------------------------------------//

	// opening the input file
	print_info("opening the input file %s",argv[1]);
	input_file_path = argv[1];
	input_file = fopen(input_file_path,"r");
	exit_if_false(input_file != NULL,"opening %s",input_file_path);

	// reading the case file path
	print_info("reading the case file path");
	exit_if_false(fetch_value(input_file,"case_file_path",'s',case_file_path) == FETCH_SUCCESS,"reading case_file_path from %s",input_file_path);
	print_continue(case_file_path);

	// reading the number of variables, variable names and orders
	print_info("reading the variables");
	int n_variables_old = 0, n_variables;
	exit_if_false(fetch_value(input_file,"number_of_variables",'i',&n_variables) == FETCH_SUCCESS,"reading number_of_variables from %s",input_file_path);
	int *variable_order_old = NULL, *variable_order = (int *)malloc(n_variables * sizeof(int));
	exit_if_false(variable_order != NULL,"allocating orders");
	exit_if_false(fetch_vector(input_file, "variable_order", 'i', n_variables, variable_order) == FETCH_SUCCESS,"reading variable_order from %s",input_file_path);
	char **variable_name = allocate_character_matrix(NULL,n_variables,MAX_STRING_LENGTH);
	exit_if_false(variable_name != NULL,"allocating variable names");
	warn_if_false(fetch_vector(input_file,"variable_name",'s',n_variables,variable_name) == FETCH_SUCCESS,"reading variable_name from %s",input_file_path);
	for(i = 0; i < n_variables; i ++) print_continue("%s order %i",variable_name[i],variable_order[i]);

	// reading the number of inner and outer iterations to perform
	print_info("reading the numbers of iterations");
	int outer_iteration = 0, inner_iteration;
	int n_outer_iterations, n_inner_iterations, data_n_outer_iterations, display_n_outer_iterations;
	exit_if_false(fetch_value(input_file,"number_of_inner_iterations",'i',&n_inner_iterations) == FETCH_SUCCESS,"reading number_of_inner_iterations from %s",input_file_path);
	exit_if_false(fetch_value(input_file,"number_of_outer_iterations",'i',&n_outer_iterations) == FETCH_SUCCESS,"reading number_of_outer_iterations from %s",input_file_path);
	print_continue("%i outer of %i inner iterations to be done",n_outer_iterations,n_inner_iterations);

	// read existing case and data
	case_file = fopen(case_file_path,"r");
	if(case_file != NULL)
	{
		print_info("reading existing case file %s",case_file_path);
		read_case(case_file, &n_variables_old, &variable_order_old, &n_nodes, &node, &n_faces, &face, &n_elements, &element, &n_boundaries_old, &boundary_old);
		fclose(case_file);
		n = 0; for(i = 0; i < n_variables; i ++) n += n_elements*ORDER_TO_N_BASIS(variable_order[i]);

		if(fetch_value(input_file,"initial_data_file_path",'s',data_file_path) == FETCH_SUCCESS)
		{
			print_info("reading existing data file %s",data_file_path);
			exit_if_false(data_file = fopen(data_file_path,"r"),"opening %s",data_file_path);
			read_data(data_file, &n_u_old, &u_old, &outer_iteration);
			fclose(data_file);
			exit_if_false(n_u_old == n,"case and initial data does not match");
		}
	}

	// construct new case
	else
	{
		print_info("reading the geometry file path");
		exit_if_false(fetch_value(input_file,"geometry_file_path",'s',geometry_file_path) == FETCH_SUCCESS,"reading geometry_file_path from %s",input_file_path);
		print_continue(geometry_file_path);

		print_info("reading the geometry file %s",geometry_file_path);
		exit_if_false(geometry_file = fopen(geometry_file_path,"r"),"opening %s",geometry_file_path);
		read_geometry(geometry_file, &n_nodes, &node, &n_faces, &face, &n_elements, &element);
		fclose(geometry_file);
		print_continue("%i nodes, %i faces and %i elements",n_nodes,n_faces,n_elements);

		print_info("generating additional connectivity and geometry");
		process_geometry(n_nodes, node, n_faces, face, n_elements, element);
	}

	// read the data file path and output frequency
	print_info("reading the data file path and output frequency");
	exit_if_false(fetch_value(input_file,"data_file_path",'s',data_file_path) == FETCH_SUCCESS,"reading data_file_path from %s",input_file_path);
	if(fetch_value(input_file,"data_number_of_outer_iterations",'i',&data_n_outer_iterations) != FETCH_SUCCESS)
		data_n_outer_iterations = n_outer_iterations + outer_iteration;
	print_continue("data to be written to %s every %i outer iterations",data_file_path,data_n_outer_iterations);

	// read boundaries
	print_info("reading boundaries");
	boundaries_input(input_file, n_faces, face, &n_boundaries, &boundary);
	print_continue("%i boundaries",n_boundaries);

	// read terms
	print_info("reading PDE terms");
	terms_input(input_file, &n_terms, &term);
	print_continue("%i terms",n_terms);

	// update unknown indices and values
	print_info("updating the numbering of the degrees of freedom");
	update_element_unknowns(n_variables_old, n_variables, variable_order_old, variable_order, n_elements, element, n_u_old, &n_u, u_old, &u);
	print_continue("%i degrees of freedom",n_u);

	// update face boundaries
	print_info("updating the face boundary associations");
	update_face_boundaries(n_variables, n_faces, face, n_boundaries, boundary);

	// update integration
	print_info("updating integration");
	i = update_face_integration(n_variables_old, n_variables, variable_order_old, variable_order, n_faces, face);
	if(i) print_continue("updated %i face quadratures",i);
	i = update_element_integration(n_variables_old, n_variables, variable_order_old, variable_order, n_elements, element);
	if(i) print_continue("updated %i element quadratures",i);

	// update numerics
	print_info("updating numerics");
	i = update_face_numerics(n_variables_old, n_variables, variable_order_old, variable_order, n_faces, face, n_boundaries_old, boundary_old);
	if(i) print_continue("updated %i face interpolations",i);
	i = update_element_numerics(n_variables_old, n_variables, variable_order_old, variable_order, n_elements, element);
	if(i) print_continue("updated %i element interpolations",i);

	// write case file
	print_info("writing case file %s",case_file_path);
	exit_if_false(case_file = fopen(case_file_path,"w"),"opening %s",case_file_path);
	write_case(case_file, n_variables, variable_order, n_nodes, node, n_faces, face, n_elements, element, n_boundaries, boundary);
	fclose(case_file);

	// read the display file path and output frequency
	print_info("reading the display file path and output frequency");
	if(
			fetch_value(input_file,"display_file_path",'s',display_file_path) == FETCH_SUCCESS &&
			fetch_value(input_file,"display_number_of_outer_iterations",'i',&display_n_outer_iterations) == FETCH_SUCCESS
	  )
		print_continue("display to be written to %s every %i outer iterations",display_file_path,display_n_outer_iterations);
	else
	{
		display_n_outer_iterations = 0;
		warn_if_false(0,"display files will not be written");
	}

	// initialise
	if(initial_input(input_file, n_variables, &initial))
	{
		print_info("initialising the degrees of freedom");
		initialise_values(n_variables, variable_order, n_elements, element, initial, u);
	}

	//-------------------------------------------------------------------//
	
	// allocate and initialise the system
	print_info("allocating and initialising the system");
	SPARSE system = NULL;
	initialise_system(n_variables, variable_order, n_elements, element, n_u, &system);
	double *residual, *max_residual, *du, *max_du;
	exit_if_false(residual = (double *)malloc(n_u * sizeof(double)),"allocating the residuals");
	exit_if_false(max_residual = (double *)malloc(n_variables * sizeof(double)),"allocating the maximum residuals");
	exit_if_false(du = (double *)malloc(n_u * sizeof(double)),"allocating du");
	exit_if_false(max_du = (double *)malloc(n_variables * sizeof(double)),"allocating the maximum changes");
	exit_if_false(u_old = (double *)realloc(u_old, n_u * sizeof(double)),"re-allocating u_old");

	timer_reset();

	// iterate
	print_info("iterating");
	n_outer_iterations += outer_iteration;
	for(; outer_iteration < n_outer_iterations; outer_iteration ++)
	{
		print_output("iteration %i", outer_iteration);

		for(i = 0; i < n_u; i ++) u_old[i] = u[i];

		for(inner_iteration = 0; inner_iteration < n_inner_iterations; inner_iteration ++)
		{
			calculate_system(n_variables, variable_order, n_faces, face, n_elements, element, n_terms, term, n_u, u_old, u, system, residual);

			exit_if_false(sparse_solve(system, du, residual) == SPARSE_SUCCESS,"solving system");
			for(i = 0; i < n_u; i ++) u[i] -= du[i];

			calculate_maximum_changes_and_residuals(n_variables, variable_order, n_elements, element, du, max_du, residual, max_residual);
			for(i = 0; i < n_variables; i ++) sprintf(&print[26*i],"%.6e|%.6e ",max_du[i],max_residual[i]);
			print_continue("%s",print);
		}

		slope_limit(n_variables, variable_order, n_nodes, node, n_elements, element, n_boundaries, boundary, u);

		if(data_n_outer_iterations && outer_iteration % data_n_outer_iterations == 0)
		{
			generate_numbered_file_path(data_numbered_file_path, data_file_path, outer_iteration);
			print_info("writing data to %s",data_numbered_file_path);
			exit_if_false(data_file = fopen(data_numbered_file_path,"w"),"opening %s",data_numbered_file_path);
			write_data(data_file, n_u, u, outer_iteration);
			fclose(data_file);
		}

		if(display_n_outer_iterations && outer_iteration % display_n_outer_iterations == 0)
		{
			generate_numbered_file_path(display_numbered_file_path, display_file_path, outer_iteration);
			print_info("writing display to %s",data_numbered_file_path);
			exit_if_false(display_file = fopen(display_numbered_file_path,"w"),"opening %s",display_numbered_file_path);
			write_display(display_file, n_variables, variable_name, variable_order, n_elements, element, n_u, u);
			fclose(display_file);
		}

		timer_print();
	}

	//-------------------------------------------------------------------//
	
	print_info("freeing all memory");

	fclose(input_file);

	free(geometry_file_path);
	free(case_file_path);
	free(data_file_path);
	free(data_numbered_file_path);
	free(display_file_path);
	free(display_numbered_file_path);

	free(print);

	destroy_nodes(n_nodes,node);
	destroy_faces(n_faces,face,n_variables);
	destroy_elements(n_elements,element,n_variables);
	destroy_boundaries(n_boundaries_old,boundary_old);
	destroy_boundaries(n_boundaries,boundary);
	destroy_terms(n_terms,term);
	destroy_initial(n_variables,initial);

	free(variable_order_old);
	free(variable_order);
	destroy_matrix((void *)variable_name);

	free(u_old);
	free(u);

	sparse_destroy(system);
	free(residual);
	free(max_residual);
	free(du);
	free(max_du);

	return 0;
}
Пример #3
0
static
DWORD
TestDsrRoleGetPrimaryDomainInformation(
    PTEST         pTest,
    PCWSTR        pwszHostname,
    PCWSTR        pwszBindingString,
    PCREDENTIALS  pCreds,
    PPARAMETER    pOptions,
    DWORD         dwOptcount
    )
{
    const DWORD dwDefLevel = (WORD)(-1);

    BOOLEAN bRet = TRUE;
    WINERROR err = ERROR_SUCCESS;
    enum param_err perr = perr_success;
    DSR_BINDING hDsr = NULL;
    DWORD dwSelectedLevels[] = {0};
    DWORD dwAvailableLevels[] = { DS_ROLE_BASIC_INFORMATION,
                                  DS_ROLE_UPGRADE_STATUS,
                                  DS_ROLE_OP_STATUS };
    PDWORD pdwLevels = NULL;
    DWORD dwNumLevels = 0;
    DWORD dwLevel = 0;
    DWORD i = 0;
    PDSR_ROLE_INFO pInfo = NULL;

    perr = fetch_value(pOptions, dwOptcount, "level", pt_uint32, &dwLevel,
                       &dwDefLevel);
    if (!perr_is_ok(perr)) perr_fail(perr);

    PARAM_INFO("level", pt_uint32, &dwLevel);

    TESTINFO(pTest, pwszHostname);

    if (dwLevel == (WORD)(-1))
    {
        pdwLevels   = dwAvailableLevels;
        dwNumLevels = sizeof(dwAvailableLevels)/sizeof(dwAvailableLevels[0]);
    }
    else
    {
        dwSelectedLevels[0] = dwLevel;
        pdwLevels   = dwSelectedLevels;
        dwNumLevels = sizeof(dwSelectedLevels)/sizeof(dwSelectedLevels[0]);
    }

    bRet &= CreateRpcBinding(OUT_PPVOID(&hDsr),
                             RPC_DSSETUP_BINDING,
                             pwszHostname,
                             pwszBindingString,
                             pCreds);
    if (!bRet)
    {
        goto error;
    }

    for (i = 0; i < dwNumLevels; i++)
    {
        dwLevel = pdwLevels[i];

        INPUT_ARG_UINT(dwLevel);

        CALL_NETAPI(err, DsrRoleGetPrimaryDomainInformation(
                                    hDsr,
                                    dwLevel,
                                    &pInfo));
        BAIL_ON_WIN_ERROR(err);

        switch (dwLevel)
        {
        case DS_ROLE_BASIC_INFORMATION:
            ASSERT_TEST((pInfo->Basic.dwRole >= DS_ROLE_STANDALONE_WORKSTATION &&
                         pInfo->Basic.dwRole <= DS_ROLE_PRIMARY_DC));
            ASSERT_TEST(pInfo->Basic.pwszDomain != NULL);
            ASSERT_TEST(pInfo->Basic.pwszDnsDomain != NULL);
            ASSERT_TEST(pInfo->Basic.pwszForest != NULL);
            break;

        case DS_ROLE_UPGRADE_STATUS:
            ASSERT_TEST((pInfo->Upgrade.swUpgradeStatus == DS_ROLE_NOT_UPGRADING ||
                         pInfo->Upgrade.swUpgradeStatus == DS_ROLE_UPGRADING));
            ASSERT_TEST((pInfo->Upgrade.dwPrevious >= DS_ROLE_PREVIOUS_UNKNOWN &&
                         pInfo->Upgrade.dwPrevious <= DS_ROLE_PREVIOUS_BACKUP));
            break;

        case DS_ROLE_OP_STATUS:
            ASSERT_TEST(pInfo->OpStatus.swStatus <= DS_ROLE_NEEDS_REBOOT);
            break;
        }

        if (pInfo)
        {
            DsrFreeMemory(pInfo);
            pInfo = NULL;
        }
    }

    DsrFreeBinding(&hDsr);

error:
    if (pInfo)
    {
        DsrFreeMemory(pInfo);
    }

    if (err != ERROR_SUCCESS)
    {
        bRet = FALSE;
    }

    return bRet;
}
Пример #4
0
/* Update the trust database, adding when rm is zero, removing otherwise.
 * Documented in detail in poolback.h
 */
int update_trust (struct pulleyback_tlspool *self, der_t *data, int rm) {
	dercursor crd;
	dercursor vex;
	uint32_t flags = 0;
	//
	// Collect DER data for validation expression and optional credential
	vex.derlen = 1030;  // sane upper margin ~1kB
	crd.derlen = 8200;  // sane upper margin ~8kB
	crd.derptr = (uint8_t *) fetch_value (self, MXG_CRED,    data);
	vex.derptr = (uint8_t *) fetch_value (self, MXG_VALEXP,  data);
	assert (vex.derptr != NULL);
	//
	// Enter the DER data to obtain contents and length
	if (der_enter (&vex)) {
		return 0;
	}
	if (crd.derptr == NULL) {
		crd.derlen = 0;
	} else {
		if (der_enter (&crd)) {
			return 0;
		}
	}
	//
	// Collect the flags
	if (check_flag (self, data, MXG_CLIENT, MXG_ROLE)) {
		flags |= TAD_ROLE_CLIENT;
	}
	if (check_flag (self, data, MXG_SERVER, MXG_ROLE)) {
		flags |= TAD_ROLE_SERVER;
	}
	if (check_flag (self, data, MXG_PEER, MXG_ROLE)) {
		flags |= TAD_ROLE_CLIENT | TAD_ROLE_SERVER;
	}
	if (check_flag (self, data, MXG_X509, MXG_CREDTYPE)) {
		flags |= TAD_TYPE_X509;
	} else if (check_flag (self, data, MXG_PGP, MXG_CREDTYPE)) {
		flags |= TAD_TYPE_PGP;
	}
	//TODO// MXG_SRP  -> LID_TYPE_SRP
	//TODO// MXG_KRB5 -> LID_TYPE_KRB5
	   else {
		return 0;
	}
	//TODO// if (check_flag (self, data, MXG_NOTROOT, MXG_NONE)) {
	//TODO// 	flags |= TAD_NOTROOT;
	//TODO// }
	//
	// Collect the value for this entry
	dercursor value;
	value.derlen = 4 + vex.derlen + 1 + crd.derlen;
	uint8_t entry [value.derlen];
	value.derptr = entry;
	* (uint32_t *) entry = htonl (flags);
	memcpy (entry + 4, vex.derptr, vex.derlen);
	entry [4 + vex.derlen] = '\0';
	if (crd.derlen > 0) {
		memcpy (entry + 4 + vex.derlen + 1, crd.derptr, crd.derlen);
	}
	//
	//TODO// Determine the key for this entry
	uint8_t keybytes_TODO [] = { 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff };
	dercursor key;
	key.derptr = keybytes_TODO;
	key.derlen = sizeof (keybytes_TODO);
	//
	// Submit the information to the database
	static const uint8_t flag4 [] = { 0x00, 0x00, 0x00, 0xff };
	return update_db (self, &key, &value, 4, flag4, rm);
}
Пример #5
0
/* Update the localid database, adding when rm is zero, removing otherwise.
 * Documented in detail in poolback.h
 */
int update_localid (struct pulleyback_tlspool *self, der_t *data, int rm) {
	dercursor lid;
	dercursor crd;
	dercursor p11;
	dercursor vex;
	uint32_t flags = 0;
	//
	// Collect DER data for localid and PKCS #11 URI
	lid.derlen =
	p11.derlen =
	vex.derlen = 1030;  // sane upper margin ~1kB
	crd.derlen = 8200;  // sane upper margin ~8kB
	lid.derptr = (uint8_t *) fetch_value (self, MXG_LOCALID, data);
	crd.derptr = (uint8_t *) fetch_value (self, MXG_CRED,    data);
	p11.derptr = (uint8_t *) fetch_value (self, MXG_PKCS11,  data);
	vex.derptr = (uint8_t *) fetch_value (self, MXG_VALEXP,  data);
	assert (lid.derptr != NULL);
	//
	// Enter the DER data to obtain contents and length
	if (crd.derptr == NULL) {
		crd.derlen = 0;
	} else {
		if (der_enter (&crd)) {
			return 0;
		}
	}
	if (der_enter (&lid)) {
		return 0;
	}
	if ((p11.derptr != NULL) && der_enter (&p11)) {
		return 0;
	}
	if ((vex.derptr != NULL) && der_enter (&vex)) {
		return 0;
	}
	//
	// Collect the flags
	if (p11.derptr == NULL) {
		flags |= LID_NO_PKCS11;
	}
	if (check_flag (self, data, MXG_CLIENT, MXG_ROLE)) {
		flags |= LID_ROLE_CLIENT;
	}
	if (check_flag (self, data, MXG_SERVER, MXG_ROLE)) {
		flags |= LID_ROLE_SERVER;
	}
	if (check_flag (self, data, MXG_PEER, MXG_ROLE)) {
		flags |= LID_ROLE_CLIENT | LID_ROLE_SERVER;
	}
	if (check_flag (self, data, MXG_X509, MXG_CREDTYPE)) {
		flags |= LID_TYPE_X509;
	} else if (check_flag (self, data, MXG_PGP, MXG_CREDTYPE)) {
		flags |= LID_TYPE_PGP;
	} else if (vex.derptr != NULL) {
		// Valexp is a case in localid, as an entry LID_TYPE_VALEXP
		flags |= LID_TYPE_VALEXP;
		flags &= ~LID_NO_PKCS11;
	}
	//TODO// MXG_SRP  -> LID_TYPE_SRP
	//TODO// MXG_KRB5 -> LID_TYPE_KRB5
	   else {
		return 0;
	}
	if (check_flag (self, data, MXG_CHAINED, MXG_NONE)) {
		flags |= LID_CHAINED;
	}
	//
	// Handle PKCS #11 URI and/or validation expression
	if (p11.derptr == NULL) {
		// Put the validation expression in the PKCS #11 URI hole
		p11 = vex;
	} else {
		assert (vex.derptr == NULL);
	}
	if (p11.derptr == NULL) {
		p11.derlen = 0;
	}
	//
	// Collect the value for this entry
	dercursor value;
	value.derlen = 4 + p11.derlen + ((p11.derptr != NULL)?1:0) + crd.derlen;
	uint8_t entry [value.derlen];
	value.derptr = entry;
	* (uint32_t *) entry = htonl (flags);
	if (p11.derptr != NULL) {
		memcpy (entry + 4, p11.derptr, p11.derlen);
		entry [4 + p11.derlen] = '\0';
	}
	if (crd.derptr != NULL) {
		memcpy (entry + 4 + p11.derlen + 1, crd.derptr, crd.derlen);
	}
	//
	// Submit the information to the database
	static const uint8_t flag4 [] = { 0x00, 0x00, 0x00, 0xff };
	return update_db (self, &lid, &value, 4, flag4, rm);
}
Пример #6
0
static
DWORD
TestNetlogonEnumDomainTrusts(
    PTEST         pTest,
    PCWSTR        pwszHostname,
    PCWSTR        pwszBindingString,
    PCREDENTIALS  pCreds,
    PPARAMETER    pOptions,
    DWORD         dwOptcount
)
{
    const DWORD dwDefTrustFlags = NETR_TRUST_FLAG_IN_FOREST |
                                  NETR_TRUST_FLAG_OUTBOUND |
                                  NETR_TRUST_FLAG_TREEROOT |
                                  NETR_TRUST_FLAG_PRIMARY |
                                  NETR_TRUST_FLAG_NATIVE |
                                  NETR_TRUST_FLAG_INBOUND;

    BOOLEAN bRet = TRUE;
    NTSTATUS ntStatus = STATUS_SUCCESS;
    WINERROR err = ERROR_SUCCESS;
    NETR_BINDING hNetr = NULL;
    enum param_err perr = perr_success;
    DWORD dwTrustFlags = 0;
    DWORD dwCount = 0;
    NetrDomainTrust *pTrusts = NULL;
    DWORD iTrust = 0;

    TESTINFO(pTest, pwszHostname);

    perr = fetch_value(pOptions, dwOptcount, "trustflags", pt_uint32, &dwTrustFlags,
                       &dwDefTrustFlags);
    if (!perr_is_ok(perr)) perr_fail(perr);

    PARAM_INFO("trustflags", pt_uint32, &dwTrustFlags);

    bRet &= CreateRpcBinding(OUT_PPVOID(&hNetr),
                             RPC_NETLOGON_BINDING,
                             pwszHostname,
                             pwszBindingString,
                             pCreds);

    CALL_NETAPI(err, DsrEnumerateDomainTrusts(hNetr, pwszHostname, dwTrustFlags,
                &pTrusts, &dwCount));
    BAIL_ON_WIN_ERROR(err);

    bRet  &= TestValidateDomainTrusts(pTrusts, dwCount);

    for (iTrust = 0; iTrust < dwCount; iTrust++)
    {
        OUTPUT_ARG_WSTR(pTrusts[iTrust].netbios_name);
        OUTPUT_ARG_WSTR(pTrusts[iTrust].dns_name);
        OUTPUT_ARG_UINT(pTrusts[iTrust].trust_flags);
    }

error:
    if (pTrusts)
    {
        NetrFreeMemory(pTrusts);
    }

    NetrFreeBinding(&hNetr);

    if (ntStatus != STATUS_SUCCESS ||
            err != ERROR_SUCCESS)
    {
        bRet = FALSE;
    }

    return bRet;
}
Пример #7
0
static
DWORD
TestNetlogonEnumTrustedDomains(
    PTEST         pTest,
    PCWSTR        pwszHostname,
    PCWSTR        pwszBindingString,
    PCREDENTIALS  pCreds,
    PPARAMETER    pOptions,
    DWORD         dwOptcount
)
{
    PCSTR pszDefServer = "TEST";

    BOOLEAN bRet = TRUE;
    NTSTATUS ntStatus = STATUS_SUCCESS;
    NETR_BINDING hNetr = NULL;
    enum param_err perr = perr_success;
    PWSTR pwszServer = NULL;
    DWORD dwCount = 0;
    NetrDomainTrust *pTrusts = NULL;
    DWORD iTrust = 0;

    TESTINFO(pTest, pwszHostname);

    perr = fetch_value(pOptions, dwOptcount, "server", pt_w16string, &pwszServer,
                       &pszDefServer);
    if (!perr_is_ok(perr)) perr_fail(perr);

    PARAM_INFO("server", pt_w16string, pwszServer);

    bRet &= CreateRpcBinding(OUT_PPVOID(&hNetr),
                             RPC_NETLOGON_BINDING,
                             pwszHostname,
                             pwszBindingString,
                             pCreds);

    CALL_MSRPC(ntStatus, NetrEnumerateTrustedDomainsEx(hNetr, pwszServer,
               &pTrusts, &dwCount));
    BAIL_ON_NT_STATUS(ntStatus);

    bRet  &= TestValidateDomainTrusts(pTrusts, dwCount);

    for (iTrust = 0; iTrust < dwCount; iTrust++)
    {
        OUTPUT_ARG_WSTR(pTrusts[iTrust].netbios_name);
        OUTPUT_ARG_WSTR(pTrusts[iTrust].dns_name);
        OUTPUT_ARG_UINT(pTrusts[iTrust].trust_flags);
    }

error:
    if (pTrusts)
    {
        NetrFreeMemory(pTrusts);
    }

    NetrFreeBinding(&hNetr);

    LW_SAFE_FREE_MEMORY(pwszServer);

    if (ntStatus != STATUS_SUCCESS)
    {
        bRet = FALSE;
    }

    return bRet;
}
Пример #8
0
static
DWORD
TestNetlogonSamLogonInteractiveEx(
    PTEST         pTest,
    PCWSTR        pwszHostname,
    PCWSTR        pwszBindingString,
    PCREDENTIALS  pCreds,
    PPARAMETER    pOptions,
    DWORD         dwOptcount
)
{
    PCSTR pszDefComputer = "TestWks4";
    PCSTR pszDefMachpass = "******";
    const DWORD dwDefLogonLevel = 0;
    const DWORD dwDefValidationLevel = 2;

    BOOLEAN bRet = TRUE;
    DWORD dwError = ERROR_SUCCESS;
    NETR_BINDING hNetr = NULL;
    NETR_BINDING hSchn = NULL;
    enum param_err perr = perr_success;
    NetrCredentials NetlogonCreds = {0};
    NetrValidationInfo **ppSamLogonInfo = NULL;
    PSTR pszComputer = NULL;
    PSTR pszMachpass = NULL;
    PWSTR pwszComputer = NULL;
    PWSTR pwszMachAcct = NULL;
    PWSTR pwszMachpass = NULL;
    PWSTR pwszServer = NULL;
    PWSTR pwszDomain = NULL;
    PWSTR pwszDnsDomain = NULL;
    PWSTR pwszUsername = NULL;
    PWSTR pwszPassword = NULL;
    DWORD dwLogonLevel = 0;
    DWORD dwValidationLevel = 0;
    DWORD pDefaultLogonLevels[] = { 1, 3, 4};
    DWORD numLogonLevels = (sizeof(pDefaultLogonLevels)
                            /sizeof(pDefaultLogonLevels[0]));
    PDWORD pLogonLevels = NULL;
    DWORD pDefaultValidationLevels[] = { 2, 3, 6 };
    DWORD numValidationLevels = (sizeof(pDefaultValidationLevels)
                                 /sizeof(pDefaultValidationLevels[0]));
    PDWORD pValidationLevels = NULL;
    DWORD iLogonLevel = 0;
    DWORD iValidationLevel = 0;

    TESTINFO(pTest, pwszHostname);

    perr = fetch_value(pOptions, dwOptcount, "computer", pt_w16string, &pwszComputer,
                       &pszDefComputer);
    if (!perr_is_ok(perr)) perr_fail(perr);

    perr = fetch_value(pOptions, dwOptcount, "machpass", pt_w16string, &pwszMachpass,
                       &pszDefMachpass);
    if (!perr_is_ok(perr)) perr_fail(perr);

    perr = fetch_value(pOptions, dwOptcount, "server", pt_w16string, &pwszServer,
                       NULL);
    if (perr_is_err(perr)) perr_fail(perr);

    perr = fetch_value(pOptions, dwOptcount, "domain", pt_w16string, &pwszDomain,
                       NULL);
    if (perr_is_err(perr)) perr_fail(perr);

    perr = fetch_value(pOptions, dwOptcount, "dnsdomain", pt_w16string, &pwszDnsDomain,
                       NULL);
    if (perr_is_err(perr)) perr_fail(perr);

    perr = fetch_value(pOptions, dwOptcount, "username", pt_w16string, &pwszUsername,
                       NULL);
    if (!perr_is_ok(perr)) perr_fail(perr);

    perr = fetch_value(pOptions, dwOptcount, "password", pt_w16string, &pwszPassword,
                       NULL);
    if (!perr_is_ok(perr)) perr_fail(perr);

    perr = fetch_value(pOptions, dwOptcount, "logon_level", pt_uint32, &dwLogonLevel,
                       &dwDefLogonLevel);
    if (!perr_is_ok(perr)) perr_fail(perr);

    perr = fetch_value(pOptions, dwOptcount, "validation_level", pt_uint32,
                       &dwValidationLevel, &dwDefValidationLevel);
    if (!perr_is_ok(perr)) perr_fail(perr);

    dwError = LwWc16sToMbs(pwszComputer, &pszComputer);
    BAIL_ON_WIN_ERROR(dwError);

    dwError = LwWc16sToMbs(pwszMachpass, &pszMachpass);
    BAIL_ON_WIN_ERROR(dwError);

    if (strcmp(pszComputer, pszDefComputer) == 0 &&
            strcmp(pszMachpass, pszDefMachpass) == 0)
    {
        LW_SAFE_FREE_MEMORY(pwszComputer);
        LW_SAFE_FREE_MEMORY(pwszMachpass);

        dwError = GetMachinePassword(
                      &pwszDnsDomain,
                      &pwszDomain,
                      &pwszMachAcct,
                      &pwszMachpass,
                      &pwszComputer);
        BAIL_ON_WIN_ERROR(dwError);
    }

    PARAM_INFO("computer", pt_w16string, pwszComputer);
    PARAM_INFO("machpass", pt_w16string, pwszMachpass);
    PARAM_INFO("server", pt_w16string, pwszServer);
    PARAM_INFO("domain", pt_w16string, pwszDomain);
    PARAM_INFO("dnsdomain", pt_w16string, pwszDnsDomain);
    PARAM_INFO("username", pt_w16string, pwszUsername);
    PARAM_INFO("password", pt_w16string, pwszPassword);
    PARAM_INFO("logon_level", pt_int32, &dwLogonLevel);
    PARAM_INFO("validation_level", pt_int32, &dwValidationLevel);

    bRet &= CreateRpcBinding(OUT_PPVOID(&hNetr),
                             RPC_NETLOGON_BINDING,
                             pwszHostname,
                             pwszBindingString,
                             pCreds);

    bRet &= CallOpenSchannel(hNetr,
                             pwszMachAcct,
                             pwszHostname,
                             pwszServer,
                             pwszDomain,
                             pwszDnsDomain,
                             pwszComputer,
                             pwszMachpass,
                             &NetlogonCreds,
                             &hSchn);

    if (hSchn == NULL)
    {
        bRet = FALSE;
        goto done;
    }

    if (dwLogonLevel)
    {
        pLogonLevels = &dwLogonLevel;
        numLogonLevels = 1;
    }
    else
    {
        pLogonLevels = pDefaultLogonLevels;
    }

    if (dwValidationLevel)
    {
        pValidationLevels = &dwValidationLevel;
        numValidationLevels = 1;
    }
    else
    {
        pValidationLevels = pDefaultValidationLevels;
    }

    for (iLogonLevel = 0; iLogonLevel < numLogonLevels; iLogonLevel++)
    {
        bRet &= CallNetrSamLogonInteractiveEx(
                    hSchn,
                    &NetlogonCreds,
                    pwszServer,
                    pwszDomain,
                    pwszComputer,
                    pwszUsername,
                    pwszPassword,
                    pLogonLevels[iLogonLevel],
                    pValidationLevels,
                    numValidationLevels,
                    &ppSamLogonInfo);

        if (bRet)
        {
            bRet &= TestValidateSamLogonInfo(&ppSamLogonInfo, 1);

            for (iValidationLevel = 0;
                    ppSamLogonInfo && iValidationLevel <= 6;
                    iValidationLevel++)
            {
                if (ppSamLogonInfo[iValidationLevel])
                {
                    NetrFreeMemory(ppSamLogonInfo[iValidationLevel]);
                    ppSamLogonInfo[iValidationLevel] = NULL;
                }
            }
        }
    }

    bRet &= CallCloseSchannel(hSchn);

done:
error:
    for (iValidationLevel = 0;
            ppSamLogonInfo && iValidationLevel <= 6;
            iValidationLevel++)
    {
        if (ppSamLogonInfo[iValidationLevel])
        {
            NetrFreeMemory(ppSamLogonInfo[iValidationLevel]);
            ppSamLogonInfo[iValidationLevel] = NULL;
        }
    }

    NetrFreeBinding(&hNetr);

    LW_SAFE_FREE_MEMORY(pwszMachAcct);
    LW_SECURE_FREE_WSTRING(pwszMachpass);
    LW_SAFE_FREE_MEMORY(pwszComputer);
    LW_SAFE_FREE_MEMORY(pwszServer);
    LW_SAFE_FREE_MEMORY(pwszDomain);
    LW_SAFE_FREE_MEMORY(pwszUsername);
    LW_SAFE_FREE_MEMORY(pwszPassword);
    LW_SAFE_FREE_MEMORY(pszComputer);
    LW_SAFE_FREE_MEMORY(pszMachpass);

    return (int)bRet;
}
Пример #9
0
static
DWORD
TestNetlogonGetDcName(
    PTEST         pTest,
    PCWSTR        pwszHostname,
    PCWSTR        pwszBindingString,
    PCREDENTIALS  pCreds,
    PPARAMETER    pOptions,
    DWORD         dwOptcount
)
{
    const DWORD dwDefGetDcFlags = DS_FORCE_REDISCOVERY;
    const PSTR pszDefDomainName = "DOMAIN";

    BOOLEAN bRet = TRUE;
    NTSTATUS ntStatus = STATUS_SUCCESS;
    WINERROR err = ERROR_SUCCESS;
    NETR_BINDING hNetr = NULL;
    enum param_err perr = perr_success;
    DWORD dwGetDcFlags = 0;
    PWSTR pwszDomainName = NULL;
    DsrDcNameInfo *pInfo = NULL;

    TESTINFO(pTest, pwszHostname);

    perr = fetch_value(pOptions, dwOptcount, "getdcflags", pt_uint32, &dwGetDcFlags,
                       &dwDefGetDcFlags);
    if (!perr_is_ok(perr)) perr_fail(perr);

    perr = fetch_value(pOptions, dwOptcount, "domainname", pt_w16string, &pwszDomainName,
                       &pszDefDomainName);
    if (!perr_is_ok(perr)) perr_fail(perr);

    PARAM_INFO("getdcflags", pt_uint32, &dwGetDcFlags);
    PARAM_INFO("domainname", pt_w16string, pwszDomainName);

    bRet &= CreateRpcBinding(OUT_PPVOID(&hNetr),
                             RPC_NETLOGON_BINDING,
                             pwszHostname,
                             pwszBindingString,
                             pCreds);

    CALL_NETAPI(err, DsrGetDcName(hNetr, pwszHostname, pwszDomainName,
                                  NULL, NULL, dwGetDcFlags, &pInfo));
    BAIL_ON_WIN_ERROR(err);

error:
    if (pInfo)
    {
        NetrFreeMemory(pInfo);
    }

    NetrFreeBinding(&hNetr);

    if (ntStatus != STATUS_SUCCESS ||
            err != ERROR_SUCCESS)
    {
        bRet = FALSE;
    }

    return bRet;
}
Пример #10
0
static long process(aoRecord *prec)
{
	struct aodset	*pdset = (struct aodset *)(prec->dset);
	long		 status=0;
	unsigned char    pact=prec->pact;
	double		value;

	if ((pdset==NULL) || (pdset->write_ao==NULL)) {
		prec->pact=TRUE;
		recGblRecordError(S_dev_missingSup,(void *)prec,"write_ao");
		return(S_dev_missingSup);
	}

	/* fetch value and convert*/
	if (prec->pact == FALSE) {
                if ((prec->dol.type != CONSTANT)
                && (prec->omsl == menuOmslclosed_loop)) {
                    status = fetch_value(prec, &value);
                }
                else {
                    value = prec->val;
                }
		if(!status) convert(prec, value);
		prec->udf = isnan(prec->val);
	}

	/* check for alarms */
	checkAlarms(prec);

	if (prec->nsev < INVALID_ALARM )
		status=writeValue(prec); /* write the new value */
	else {
    		switch (prec->ivoa) {
		    case (menuIvoaContinue_normally) :
			status=writeValue(prec); /* write the new value */
		        break;
		    case (menuIvoaDon_t_drive_outputs) :
			break;
		    case (menuIvoaSet_output_to_IVOV) :
	                if(prec->pact == FALSE){
			 	prec->val=prec->ivov;
			 	value=prec->ivov;
				convert(prec,value);
                        }
			status=writeValue(prec); /* write the new value */
		        break;
		    default :
			status=-1;
		        recGblRecordError(S_db_badField,(void *)prec,
		                "ao:process Illegal IVOA field");
		}
	}

	/* check if device support set pact */
	if ( !pact && prec->pact ) return(0);
	prec->pact = TRUE;

	recGblGetTimeStamp(prec);

	/* check event list */
	monitor(prec);

	/* process the forward scan link record */
        recGblFwdLink(prec);

	prec->init=FALSE;
	prec->pact=FALSE;
	return(status);
}