예제 #1
0
파일: netlogon.c 프로젝트: jkstrick/samba
static NTSTATUS tcp_ldap_rootdse(void *data,
				 TALLOC_CTX *mem_ctx,
				 struct cldap_search *io)
{
	struct ldap_connection *conn = talloc_get_type(data,
						       struct ldap_connection);
	struct ldap_message *msg, *result;
	struct ldap_request *req;
	int i;
	NTSTATUS status;

	msg = new_ldap_message(mem_ctx);
	if (!msg) {
		return NT_STATUS_NO_MEMORY;
	}

	msg->type = LDAP_TAG_SearchRequest;
	msg->r.SearchRequest.basedn = "";
	msg->r.SearchRequest.scope = LDAP_SEARCH_SCOPE_BASE;
	msg->r.SearchRequest.deref = LDAP_DEREFERENCE_NEVER;
	msg->r.SearchRequest.timelimit = 0;
	msg->r.SearchRequest.sizelimit = 0;
	msg->r.SearchRequest.attributesonly = false;
	msg->r.SearchRequest.tree = ldb_parse_tree(msg, io->in.filter);
	msg->r.SearchRequest.num_attributes = str_list_length(io->in.attributes);
	msg->r.SearchRequest.attributes = io->in.attributes;

	req = ldap_request_send(conn, msg);
	if (req == NULL) {
		printf("Could not setup ldap search\n");
		return NT_STATUS_UNSUCCESSFUL;
	}

	ZERO_STRUCT(io->out);
	for (i = 0; i < 2; ++i) {
		status = ldap_result_n(req, i, &result);
		if (!NT_STATUS_IS_OK(status)) {
			return status;
		}
		switch (result->type) {
		case LDAP_TAG_SearchResultEntry:
			if (i != 0) {
				return NT_STATUS_LDAP(LDAP_PROTOCOL_ERROR);
			}
			io->out.response = &result->r.SearchResultEntry;
			break;
		case LDAP_TAG_SearchResultDone:
			io->out.result = &result->r.SearchResultDone;
			if (io->out.result->resultcode != LDAP_SUCCESS) {
				return NT_STATUS_LDAP(io->out.result->resultcode);
			}

			return NT_STATUS_OK;
		default:
			return NT_STATUS_LDAP(LDAP_PROTOCOL_ERROR);
		}
	}

	return NT_STATUS_OK;
}
예제 #2
0
/*
  send a name query reply
*/
void nbtd_name_query_reply(struct nbt_name_socket *nbtsock, 
			   struct nbt_name_packet *request_packet, 
			   struct socket_address *src,
			   struct nbt_name *name, uint32_t ttl,
			   uint16_t nb_flags, const char **addresses)
{
	struct nbt_name_packet *packet;
	size_t num_addresses = str_list_length(addresses);
	struct nbtd_interface *iface = talloc_get_type(nbtsock->incoming.private, 
						       struct nbtd_interface);
	struct nbtd_server *nbtsrv = iface->nbtsrv;
	int i;

	if (num_addresses == 0) {
		DEBUG(3,("No addresses in name query reply - failing\n"));
		return;
	}

	packet = talloc_zero(nbtsock, struct nbt_name_packet);
	if (packet == NULL) return;

	packet->name_trn_id = request_packet->name_trn_id;
	packet->ancount = 1;
	packet->operation = 
		NBT_FLAG_REPLY | 
		NBT_OPCODE_QUERY | 
		NBT_FLAG_AUTHORITIVE |
		NBT_FLAG_RECURSION_DESIRED |
		NBT_FLAG_RECURSION_AVAIL;

	packet->answers = talloc_array(packet, struct nbt_res_rec, 1);
	if (packet->answers == NULL) goto failed;

	packet->answers[0].name     = *name;
	packet->answers[0].rr_type  = NBT_QTYPE_NETBIOS;
	packet->answers[0].rr_class = NBT_QCLASS_IP;
	packet->answers[0].ttl      = ttl;
	packet->answers[0].rdata.netbios.length = num_addresses*6;
	packet->answers[0].rdata.netbios.addresses = 
		talloc_array(packet->answers, struct nbt_rdata_address, num_addresses);
	if (packet->answers[0].rdata.netbios.addresses == NULL) goto failed;

	for (i=0;i<num_addresses;i++) {
		struct nbt_rdata_address *addr = 
			&packet->answers[0].rdata.netbios.addresses[i];
		addr->nb_flags = nb_flags;
		addr->ipaddr = talloc_strdup(packet->answers, addresses[i]);
		if (addr->ipaddr == NULL) goto failed;
	}

	DEBUG(7,("Sending name query reply for %s at %s to %s:%d\n", 
		 nbt_name_string(packet, name), addresses[0], src->addr, src->port));
	
	nbtsrv->stats.total_sent++;
	nbt_name_reply_send(nbtsock, src, packet);

failed:
	talloc_free(packet);
}
예제 #3
0
void table_add_row_from_strlist (Table* t, StrList* list)
{
        wchar_t** row = (wchar_t**)malloc(str_list_length(list)
                                          * sizeof(wchar_t**));
        int i = 0;

        while (list)
        {
                row[i] = (wchar_t*)list->str;

                list = list->next;
                ++i;
        }

        table_add_row (t, row);
}
예제 #4
0
파일: ui.c 프로젝트: bcl/parted
void
command_line_prompt_words (const char* prompt, const char* def,
                           const StrList* possibilities, int multi_word)
{
        char*    line;
        char*    real_prompt;
        char*    _def = (char*) def;
        int      _def_needs_free = 0;

        if (!def && str_list_length (possibilities) == 1) {
                _def = str_list_convert_node (possibilities);
                _def_needs_free = 1;
        }

        if (opt_script_mode) {
                if (_def) {
                        command_line_push_line (_def, 0);
                        if (_def_needs_free)
                                free (_def);
                }
                return;
        }

        do {
                real_prompt = _construct_prompt (prompt, _def, possibilities);
                line = _readline (real_prompt, possibilities);
                free (real_prompt);
                if (!line) {
                        /* readline returns NULL to indicate EOF.
                           Treat that like an interrupt.  */
                        got_ctrl_c = 1;
                        break;
                }

                if (!strlen (line)) {
                        if (_def)
                                command_line_push_line (_def, 0);
                } else {
                        command_line_push_line (line, multi_word);
                }
                free (line);
        } while (!command_line_get_word_count () && !_def);

        if (_def_needs_free)
                free (_def);
}
예제 #5
0
void table_add_row_from_strlist (Table* t, StrList* list)
{
        wchar_t** row = xmalloc (str_list_length(list) * sizeof(*row));
        int i = 0;

        while (list)
        {
                row[i] = wcsdup (list->str);
                if (row[i] == NULL)
                        xalloc_die ();


                list = list->next;
                ++i;
        }

        table_add_row (t, row);
}
예제 #6
0
파일: ui.c 프로젝트: bcl/parted
static char*
_construct_prompt (const char* head, const char* def,
                   const StrList* possibilities)
{
        char*    prompt = strdup (head);

        if (def && possibilities)
                PED_ASSERT (str_list_match_any (possibilities, def));

        if (possibilities && str_list_length (possibilities) < 8) {
                const StrList*    walk;

                if (strlen (prompt))
                        prompt = realloc_and_cat (prompt, "  ");

                for (walk = possibilities; walk; walk = walk->next) {
                        if (walk != possibilities)
                                prompt = realloc_and_cat (prompt, "/");

                        if (def && str_list_match_node (walk, def) == 2) {
                                prompt = realloc_and_cat (prompt, "[");
                                prompt = realloc_and_cat (prompt, def);
                                prompt = realloc_and_cat (prompt, "]");
                        } else {
                                char*    text = str_list_convert_node (walk);
                                prompt = realloc_and_cat (prompt, text);
                                free (text);
                        }
                }
                prompt = realloc_and_cat (prompt, "? ");
        } else if (def) {
                if (strlen (prompt))
                        prompt = realloc_and_cat (prompt, "  ");
                prompt = realloc_and_cat (prompt, "[");
                prompt = realloc_and_cat (prompt, def);
                prompt = realloc_and_cat (prompt, "]? ");
        } else {
                if (strlen (prompt))
                        prompt = realloc_and_cat (prompt, " ");
        }

        return prompt;
}
예제 #7
0
파일: pyparam.c 프로젝트: Arkhont/samba
static PyObject *py_lp_ctx_get_helper(struct loadparm_context *lp_ctx, const char *service_name, const char *param_name)
{
	struct parm_struct *parm = NULL;
	void *parm_ptr = NULL;
	int i;

	if (service_name != NULL && strwicmp(service_name, GLOBAL_NAME) && 
		strwicmp(service_name, GLOBAL_NAME2)) {
		struct loadparm_service *service;
		/* its a share parameter */
		service = lpcfg_service(lp_ctx, service_name);
		if (service == NULL) {
			return NULL;
		}
		if (strchr(param_name, ':')) {
			/* its a parametric option on a share */
			const char *type = talloc_strndup(lp_ctx, param_name,
											  strcspn(param_name, ":"));
			const char *option = strchr(param_name, ':') + 1;
			const char *value;
			if (type == NULL || option == NULL) {
			return NULL;
			}
			value = lpcfg_get_parametric(lp_ctx, service, type, option);
			if (value == NULL) {
			return NULL;
			}
			return PyString_FromString(value);
		}

		parm = lpcfg_parm_struct(param_name);
		if (parm == NULL || parm->p_class == P_GLOBAL) {
			return NULL;
		}
		parm_ptr = lpcfg_parm_ptr(lp_ctx, service, parm);
    } else if (strchr(param_name, ':')) {
		/* its a global parametric option */
		const char *type = talloc_strndup(lp_ctx,
				  param_name, strcspn(param_name, ":"));
		const char *option = strchr(param_name, ':') + 1;
		const char *value;
		if (type == NULL || option == NULL) {
			return NULL;
		}
		value = lpcfg_get_parametric(lp_ctx, NULL, type, option);
		if (value == NULL)
			return NULL;
		return PyString_FromString(value);
	} else {
		/* its a global parameter */
		parm = lpcfg_parm_struct(param_name);
		if (parm == NULL) {
			return NULL;
		}
		parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, parm);
	}

	if (parm == NULL || parm_ptr == NULL) {
		return NULL;
    }

    /* construct and return the right type of python object */
    switch (parm->type) {
    case P_STRING:
    case P_USTRING:
	return PyString_FromString(*(char **)parm_ptr);
    case P_BOOL:
	return PyBool_FromLong(*(bool *)parm_ptr);
    case P_INTEGER:
    case P_OCTAL:
    case P_BYTES:
	return PyLong_FromLong(*(int *)parm_ptr);
    case P_ENUM:
	for (i=0; parm->enum_list[i].name; i++) {
	    if (*(int *)parm_ptr == parm->enum_list[i].value) {
		return PyString_FromString(parm->enum_list[i].name);
	    }
	}
	return NULL;
    case P_CMDLIST:
    case P_LIST: 
	{
	    int j;
	    const char **strlist = *(const char ***)parm_ptr;
	    PyObject *pylist;
		
		if(strlist == NULL) {
			return PyList_New(0);
		}
		
		pylist = PyList_New(str_list_length(strlist));
	    for (j = 0; strlist[j]; j++) 
		PyList_SetItem(pylist, j, 
			       PyString_FromString(strlist[j]));
	    return pylist;
	}

	break;
    }
    return NULL;

}
예제 #8
0
파일: basic.c 프로젝트: DavidMulder/samba
static bool test_referrals(struct torture_context *tctx, TALLOC_CTX *mem_ctx,
	const char *url, const char *basedn, const char **partitions)
{
	struct ldb_context *ldb;
	struct ldb_result *res;
	const char * const *attrs = { NULL };
	struct ldb_dn *dn1, *dn2;
	int ret;
	int i, j, k;
	char *tempstr;
	bool found, l_found;

	printf("Testing referrals\n");

	if (partitions[0] == NULL) {
		printf("Partitions list empty!\n");
		return false;
	}

	if (strcmp(partitions[0], basedn) != 0) {
		printf("The first (root) partition DN should be the base DN!\n");
		return false;
	}

	ldb = ldb_wrap_connect(mem_ctx, tctx->ev, tctx->lp_ctx, url,
			       NULL, popt_get_cmdline_credentials(), 0);

	/* "partitions[i]" are the partitions for which we search the parents */
	for (i = 1; partitions[i] != NULL; i++) {
		dn1 = ldb_dn_new(mem_ctx, ldb, partitions[i]);
		if (dn1 == NULL) {
			printf("Out of memory\n");
			talloc_free(ldb);
			return false;
		}

		/* search using base scope */
		/* "partitions[j]" are the parent candidates */
		for (j = str_list_length(partitions) - 1; j >= 0; --j) {
			dn2 = ldb_dn_new(mem_ctx, ldb, partitions[j]);
			if (dn2 == NULL) {
				printf("Out of memory\n");
				talloc_free(ldb);
				return false;
			}

			ret = ldb_search(ldb, mem_ctx, &res, dn2,
					 LDB_SCOPE_BASE, attrs,
					 "(foo=bar)");
			if (ret != LDB_SUCCESS) {
				printf("%s", ldb_errstring(ldb));
				talloc_free(ldb);
				return false;
			}

			if (res->refs != NULL) {
				printf("There shouldn't be generated any referrals in the base scope!\n");
				talloc_free(ldb);
				return false;
			}

			talloc_free(res);
			talloc_free(dn2);
		}

		/* search using onelevel scope */
		found = false;
		/* "partitions[j]" are the parent candidates */
		for (j = str_list_length(partitions) - 1; j >= 0; --j) {
			dn2 = ldb_dn_new(mem_ctx, ldb, partitions[j]);
			if (dn2 == NULL) {
				printf("Out of memory\n");
				talloc_free(ldb);
				return false;
			}

			ret = ldb_search(ldb, mem_ctx, &res, dn2,
					 LDB_SCOPE_ONELEVEL, attrs,
					 "(foo=bar)");
			if (ret != LDB_SUCCESS) {
				printf("%s", ldb_errstring(ldb));
				talloc_free(ldb);
				return false;
			}

			tempstr = talloc_asprintf(mem_ctx, "/%s??base",
						  partitions[i]);
			if (tempstr == NULL) {
				printf("Out of memory\n");
				talloc_free(ldb);
				return false;
			}

			/* Try to find or find not a matching referral */
			l_found = false;
			for (k = 0; (!l_found) && (res->refs != NULL)
			    && (res->refs[k] != NULL); k++) {
				if (strstr(res->refs[k], tempstr) != NULL) {
					l_found = true;
				}
			}

			talloc_free(tempstr);

			if ((!found) && (ldb_dn_compare_base(dn2, dn1) == 0)
			    && (ldb_dn_compare(dn2, dn1) != 0)) {
				/* This is a referral candidate */
				if (!l_found) {
					printf("A required referral hasn't been found on onelevel scope (%s -> %s)!\n", partitions[j], partitions[i]);
					talloc_free(ldb);
					return false;
				}
				found = true;
			} else {
				/* This isn't a referral candidate */
				if (l_found) {
					printf("A unrequired referral has been found on onelevel scope (%s -> %s)!\n", partitions[j], partitions[i]);
					talloc_free(ldb);
					return false;
				}
			}

			talloc_free(res);
			talloc_free(dn2);
		}

		/* search using subtree scope */
		found = false;
		/* "partitions[j]" are the parent candidates */
		for (j = str_list_length(partitions) - 1; j >= 0; --j) {
			dn2 = ldb_dn_new(mem_ctx, ldb, partitions[j]);
			if (dn2 == NULL) {
				printf("Out of memory\n");
				talloc_free(ldb);
				return false;
			}

			ret = ldb_search(ldb, mem_ctx, &res, dn2,
					 LDB_SCOPE_SUBTREE, attrs,
					 "(foo=bar)");
			if (ret != LDB_SUCCESS) {
				printf("%s", ldb_errstring(ldb));
				talloc_free(ldb);
				return false;
			}

			tempstr = talloc_asprintf(mem_ctx, "/%s",
						  partitions[i]);
			if (tempstr == NULL) {
				printf("Out of memory\n");
				talloc_free(ldb);
				return false;
			}

			/* Try to find or find not a matching referral */
			l_found = false;
			for (k = 0; (!l_found) && (res->refs != NULL)
			    && (res->refs[k] != NULL); k++) {
				if (strstr(res->refs[k], tempstr) != NULL) {
					l_found = true;
				}
			}

			talloc_free(tempstr);

			if ((!found) && (ldb_dn_compare_base(dn2, dn1) == 0)
			    && (ldb_dn_compare(dn2, dn1) != 0)) {
				/* This is a referral candidate */
				if (!l_found) {
					printf("A required referral hasn't been found on subtree scope (%s -> %s)!\n", partitions[j], partitions[i]);
					talloc_free(ldb);
					return false;
				}
				found = true;
			} else {
				/* This isn't a referral candidate */
				if (l_found) {
					printf("A unrequired referral has been found on subtree scope (%s -> %s)!\n", partitions[j], partitions[i]);
					talloc_free(ldb);
					return false;
				}
			}

			talloc_free(res);
			talloc_free(dn2);
		}

		talloc_free(dn1);
	}

	talloc_free(ldb);

	return true;
}
예제 #9
0
파일: nbench.c 프로젝트: gojdic/samba
/* run a test that simulates an approximate netbench client load */
static bool run_netbench(struct torture_context *tctx, struct smbcli_state *cli, int client)
{
	int torture_nprocs = torture_setting_int(tctx, "nprocs", 4);
	int i;
	char line[1024];
	char *cname;
	FILE *f;
	bool correct = true;
	double target_rate = torture_setting_double(tctx, "targetrate", 0);	
	int n;

	if (target_rate != 0 && client == 0) {
		printf("Targetting %.4f MByte/sec\n", target_rate);
	}

	nb_setup(cli, client);

	if (torture_nprocs == 1) {
		if (!read_only) {
			NB_RETRY(torture_setup_dir(cli, "\\clients"));
		}
	}

	asprintf(&cname, "client%d", client+1);

	f = fopen(loadfile, "r");

	if (!f) {
		perror(loadfile);
		return false;
	}

again:
	nbio_time_reset();

	while (fgets(line, sizeof(line)-1, f)) {
		NTSTATUS status;
		const char **params0, **params;

		nbench_line_count++;

		line[strlen(line)-1] = 0;

		all_string_sub(line,"client1", cname, sizeof(line));
		
		params = params0 = str_list_make_shell(NULL, line, " ");
		i = str_list_length(params);

		if (i > 0 && isdigit(params[0][0])) {
			double targett = strtod(params[0], NULL);
			if (target_rate != 0) {
				nbio_target_rate(target_rate);
			} else {
				nbio_time_delay(targett);
			}
			params++;
			i--;
		} else if (target_rate != 0) {
			nbio_target_rate(target_rate);
		}

		if (i < 2 || params[0][0] == '#') continue;

		if (!strncmp(params[0],"SMB", 3)) {
			printf("ERROR: You are using a dbench 1 load file\n");
			nb_exit(1);
		}

		if (strncmp(params[i-1], "NT_STATUS_", 10) != 0 &&
		    strncmp(params[i-1], "0x", 2) != 0) {
			printf("Badly formed status at line %d\n", nbench_line_count);
			talloc_free(params);
			continue;
		}

		/* accept numeric or string status codes */
		if (strncmp(params[i-1], "0x", 2) == 0) {
			status = NT_STATUS(strtoul(params[i-1], NULL, 16));
		} else {
			status = nt_status_string_to_code(params[i-1]);
		}

		DEBUG(9,("run_netbench(%d): %s %s\n", client, params[0], params[1]));

		if (!strcmp(params[0],"NTCreateX")) {
			NB_RETRY(nb_createx(params[1], ival(params[2]), ival(params[3]), 
					    ival(params[4]), status));
		} else if (!strcmp(params[0],"Close")) {
			NB_RETRY(nb_close(ival(params[1]), status));
		} else if (!read_only && !strcmp(params[0],"Rename")) {
			NB_RETRY(nb_rename(params[1], params[2], status, n>0));
		} else if (!read_only && !strcmp(params[0],"Unlink")) {
			NB_RETRY(nb_unlink(params[1], ival(params[2]), status, n>0));
		} else if (!read_only && !strcmp(params[0],"Deltree")) {
			NB_RETRY(nb_deltree(params[1], n>0));
		} else if (!read_only && !strcmp(params[0],"Rmdir")) {
			NB_RETRY(nb_rmdir(params[1], status, n>0));
		} else if (!read_only && !strcmp(params[0],"Mkdir")) {
			NB_RETRY(nb_mkdir(params[1], status, n>0));
		} else if (!strcmp(params[0],"QUERY_PATH_INFORMATION")) {
			NB_RETRY(nb_qpathinfo(params[1], ival(params[2]), status));
		} else if (!strcmp(params[0],"QUERY_FILE_INFORMATION")) {
			NB_RETRY(nb_qfileinfo(ival(params[1]), ival(params[2]), status));
		} else if (!strcmp(params[0],"QUERY_FS_INFORMATION")) {
			NB_RETRY(nb_qfsinfo(ival(params[1]), status));
		} else if (!read_only && !strcmp(params[0],"SET_FILE_INFORMATION")) {
			NB_RETRY(nb_sfileinfo(ival(params[1]), ival(params[2]), status));
		} else if (!strcmp(params[0],"FIND_FIRST")) {
			NB_RETRY(nb_findfirst(params[1], ival(params[2]), 
					      ival(params[3]), ival(params[4]), status));
		} else if (!read_only && !strcmp(params[0],"WriteX")) {
			NB_RETRY(nb_writex(ival(params[1]), 
					   ival(params[2]), ival(params[3]), ival(params[4]),
					   status));
		} else if (!read_only && !strcmp(params[0],"Write")) {
			NB_RETRY(nb_write(ival(params[1]), 
					  ival(params[2]), ival(params[3]), ival(params[4]),
					  status));
		} else if (!strcmp(params[0],"LockX")) {
			NB_RETRY(nb_lockx(ival(params[1]), 
					  ival(params[2]), ival(params[3]), status));
		} else if (!strcmp(params[0],"UnlockX")) {
			NB_RETRY(nb_unlockx(ival(params[1]), 
					    ival(params[2]), ival(params[3]), status));
		} else if (!strcmp(params[0],"ReadX")) {
			NB_RETRY(nb_readx(ival(params[1]), 
					  ival(params[2]), ival(params[3]), ival(params[4]),
					  status));
		} else if (!strcmp(params[0],"Flush")) {
			NB_RETRY(nb_flush(ival(params[1]), status));
		} else if (!strcmp(params[0],"Sleep")) {
			nb_sleep(ival(params[1]), status);
		} else {
			printf("[%d] Unknown operation %s\n", nbench_line_count, params[0]);
		}

		if (n > nb_max_retries) {
			printf("Maximum reconnect retries reached for op '%s'\n", params[0]);
			nb_exit(1);
		}

		talloc_free(params0);
		
		if (nb_tick()) goto done;
	}

	rewind(f);
	goto again;

done:
	fclose(f);

	if (!read_only && torture_nprocs == 1) {
		smbcli_deltree(cli->tree, "\\clients");
	}
	if (!torture_close_connection(cli)) {
		correct = false;
	}
	
	return correct;
}
예제 #10
0
파일: ui.c 프로젝트: bcl/parted
int
command_line_get_word_count ()
{
        return str_list_length (command_line);
}