Exemple #1
0
Fichier : fm.c Projet : trazyn/dbfm
int fm_recording()
{
	char **resp = api_send_request(CMD_NEXT, SID, NULL);

	if(NULL == resp)
	{
		return -1;
	}

	if(!EQUAL(*resp, "ok"))
	{
		free_response(resp);

		return -1;
	}

	free_response(resp);

	return 0;
}
int
list_initiators(int argc, char **argv)
{
	iscsid_get_list_req_t lst;
	iscsid_response_t *rsp, *prsp;
	iscsid_get_list_rsp_t *list;
	iscsid_get_initiator_rsp_t *init;
	iscsid_sym_id_t req;
	unsigned i;

	memset(&req, 0x0, sizeof(req));
	check_extra_args(argc, argv);

	/* get the list of servers */
	lst.list_kind = INITIATOR_LIST;
	send_request(ISCSID_GET_LIST, sizeof(lst), &lst);
	rsp = get_response(TRUE);
	if (rsp->status) {
		status_error(rsp->status);
	}
	list = (iscsid_get_list_rsp_t *)(void *)rsp->parameter;

	/* display all servers */
	for (i = 0; i < list->num_entries; i++) {
		req.id = list->id[i];
		send_request(ISCSID_GET_INITIATOR_PORTAL, sizeof(req), &req);
		prsp = get_response(FALSE);
		if (prsp->status) {
			status_error(prsp->status);
		}
		init = (iscsid_get_initiator_rsp_t *)(void *)prsp->parameter;
		printf("%6d", init->portal_id.id);
		if (init->portal_id.name[0]) {
			printf("[%s]", init->portal_id.name);
		}
		printf(": %s\n", init->address);
		free_response(prsp);
	}
	free_response(rsp);
	return 0;
}
Exemple #3
0
NSS_STATUS
_nss_winbind_getpwuid_r(uid_t uid, struct passwd *result, char *buffer,
			size_t buflen, int *errnop)
{
	NSS_STATUS ret;
	static struct winbindd_response response;
	struct winbindd_request request;
	static int keep_response=0;

	/* If our static buffer needs to be expanded we are called again */
	if (!keep_response) {

		/* Call for the first time */

		ZERO_STRUCT(response);
		ZERO_STRUCT(request);

		request.data.uid = uid;

		ret = winbindd_request(WINBINDD_GETPWUID, &request, &response);

		if (ret == NSS_STATUS_SUCCESS) {
			ret = fill_pwent(result, &response.data.pw, 
					 &buffer, &buflen);

			if (ret == NSS_STATUS_TRYAGAIN) {
				keep_response = True;
				*errnop = errno = ERANGE;
				return ret;
			}
		}

	} else {

		/* We've been called again */

		ret = fill_pwent(result, &response.data.pw, &buffer, &buflen);

		if (ret == NSS_STATUS_TRYAGAIN) {
			keep_response = True;
			*errnop = errno = ERANGE;
			return ret;
		}

		keep_response = False;
		*errnop = errno = 0;
	}

	free_response(&response);
	return ret;
}
Exemple #4
0
NSS_STATUS
_nss_winbind_setpwent(void)
{
#ifdef DEBUG_NSS
	fprintf(stderr, "[%5d]: setpwent\n", getpid());
#endif

	if (num_pw_cache > 0) {
		ndx_pw_cache = num_pw_cache = 0;
		free_response(&getpwent_response);
	}

	return winbindd_request(WINBINDD_SETPWENT, NULL, NULL);
}
Exemple #5
0
NSS_STATUS
_nss_winbind_endgrent(void)
{
#ifdef DEBUG_NSS
	fprintf(stderr, "[%5d]: endgrent\n", getpid());
#endif

	if (num_gr_cache > 0) {
		ndx_gr_cache = num_gr_cache = 0;
		free_response(&getgrent_response);
	}

	return winbindd_request(WINBINDD_ENDGRENT, NULL, NULL);
}
int
list_isns_servers(int argc, char **argv)
{
	iscsid_get_list_req_t lst;
	iscsid_response_t *rsp, *prsp;
	iscsid_get_list_rsp_t *list;
	iscsid_get_isns_server_rsp_t *isns;
	iscsid_sym_id_t req;
	unsigned i;

	memset(&req, 0x0, sizeof(req));
	check_extra_args(argc, argv);

	/* get the list of servers */
	lst.list_kind = ISNS_LIST;
	send_request(ISCSID_GET_LIST, sizeof(lst), &lst);
	rsp = get_response(TRUE);
	if (rsp->status) {
		status_error(rsp->status);
	}
	list = (iscsid_get_list_rsp_t *)(void *)rsp->parameter;

	/* display all servers */
	for (i = 0; i < list->num_entries; i++) {
		req.id = list->id[i];
		send_request(ISCSID_GET_ISNS_SERVER, sizeof(req), &req);
		prsp = get_response(FALSE);
		if (prsp->status)
			status_error(prsp->status);

		isns = (iscsid_get_isns_server_rsp_t *)(void *)prsp->parameter;
		printf("%6d: %s\n", list->id[i], isns->address);
		free_response(prsp);
	}
	free_response(rsp);
	return 0;
}
/* take a username and return a string containing a comma-separated
   list of group id numbers to which the user belongs */
static char *wb_aix_getgrset(char *user)
{
	struct winbindd_response response;
	struct winbindd_request request;
	NSS_STATUS ret;
	int i, idx;
	char *tmpbuf;
	int num_gids;
	gid_t *gid_list;
	char *r_user = user;

	if (*user == WB_AIX_ENCODED) {
		r_user = decode_user(r_user);
		if (!r_user) {
			errno = ENOENT;
			return NULL;
		}
	}

	logit("getgrset '%s'\n", r_user);

	STRCPY_RETNULL(request.data.username, r_user);

	if (*user == WB_AIX_ENCODED) {
		free(r_user);
	}

	ret = winbindd_request(WINBINDD_GETGROUPS, &request, &response);

	HANDLE_ERRORS(ret);

	num_gids = response.data.num_entries;
	gid_list = (gid_t *)response.extra_data;
		
	/* allocate a space large enough to contruct the string */
	tmpbuf = malloc(num_gids*12);
	if (!tmpbuf) {
		return NULL;
	}

	for (idx=i=0; i < num_gids-1; i++) {
		idx += sprintf(tmpbuf+idx, "%u,", gid_list[i]);	
	}
	idx += sprintf(tmpbuf+idx, "%u", gid_list[i]);	

	free_response(&response);

	return tmpbuf;
}
STATIC int
do_remove_target(int argc, char **argv, iscsid_list_kind_t kind)
{
	iscsid_list_id_t req;
	iscsid_search_list_req_t srch;
	iscsid_response_t *rsp;

	if (!cl_get_id('I', &req.id, argc, argv)) {
		if (!cl_get_string('n', (char *)srch.strval, argc, argv)) {
			arg_missing("Target ID or Name");
		}
		check_extra_args(argc, argv);

		srch.search_kind = FIND_TARGET_NAME;
		srch.list_kind = kind;

		send_request(ISCSID_SEARCH_LIST, sizeof(srch), &srch);
		rsp = get_response(FALSE);
		if (rsp->status) {
			status_error_slist(rsp->status);
		}
		GET_SYM_ID(req.id.id, rsp->parameter);
		free_response(rsp);
	} else {
		check_extra_args(argc, argv);
	}
	req.list_kind = kind;
	send_request(ISCSID_REMOVE_TARGET, sizeof(req), &req);
	rsp = get_response(TRUE);
	if (rsp->status) {
		status_error(rsp->status);
	}
	free_response(rsp);
	printf("OK\n");
	return 0;
}
Exemple #9
0
static void queue_response(struct response *rsp)
{
	struct client_info *ci = rsp->ci;

	if (ci->status == CLIENT_STATUS_DEAD) {
		free_response(rsp);
		return;
	}

	pthread_mutex_lock(&ci->tx_lock);
	list_add_tail(&rsp->w_list, &ci->rsp_list);
	if (ci->tx_on == 0)
		client_tx_on(ci);
	pthread_mutex_unlock(&ci->tx_lock);
}
int main()
{
	request_t request;
	response_t response;

	request.id = 555;
	request.request_nodelist = strdup("vm[1-3]");

	allocate(&request, &response);

	printf("response.id = %d\n", response.id);
	printf("response.allocate_nodelist = %s\n", response.allocate_nodelist);

	free_request(&request);
	free_response(&response);
	return 0;
}
Exemple #11
0
int read_reply(struct winbindd_response *response)
{
	int result1, result2 = 0;

	if (!response) {
		return -1;
	}
	
	/* Read fixed length response */
	
	if ((result1 = read_sock(response, sizeof(struct winbindd_response)))
	    == -1) {
		
		return -1;
	}
	
	/* We actually send the pointer value of the extra_data field from
	   the server.  This has no meaning in the client's address space
	   so we clear it out. */

	response->extra_data.data = NULL;

	/* Read variable length response */
	
	if (response->length > sizeof(struct winbindd_response)) {
		int extra_data_len = response->length - 
			sizeof(struct winbindd_response);
		
		/* Mallocate memory for extra data */
		
		if (!(response->extra_data.data = malloc(extra_data_len))) {
			return -1;
		}
		
		if ((result2 = read_sock(response->extra_data.data, extra_data_len))
		    == -1) {
			free_response(response);
			return -1;
		}
	}
	
	/* Return total amount of data read */
	
	return result1 + result2;
}
/*
  authenticate a user
 */
static int wb_aix_authenticate(char *user, char *pass, 
			       int *reenter, char **message)
{
	struct winbindd_request request;
	struct winbindd_response response;
        NSS_STATUS result;
	char *r_user = user;

	logit("authenticate '%s' response='%s'\n", user, pass);

	*reenter = 0;
	*message = NULL;

	/* Send off request */
	ZERO_STRUCT(request);
	ZERO_STRUCT(response);

	if (*user == WB_AIX_ENCODED) {
		r_user = decode_user(r_user);
		if (!r_user) {
			return AUTH_NOTFOUND;
		}
	}

	STRCPY_RET(request.data.auth.user, r_user);
	STRCPY_RET(request.data.auth.pass, pass);

	if (*user == WB_AIX_ENCODED) {
		free(r_user);
	}

	result = winbindd_request(WINBINDD_PAM_AUTH, &request, &response);

	free_response(&response);

	logit("auth result %d for '%s'\n", result, user);

	if (result == NSS_STATUS_SUCCESS) {
		errno = 0;
		return AUTH_SUCCESS;
	}

	return AUTH_FAILURE;
}
/*
  change a user password
*/
static int wb_aix_chpass(char *user, char *oldpass, char *newpass, char **message)
{
	struct winbindd_request request;
	struct winbindd_response response;
        NSS_STATUS result;
	char *r_user = user;

	if (*user == WB_AIX_ENCODED) {
		r_user = decode_user(r_user);
		if (!r_user) {
			errno = ENOENT;
			return -1;
		}
	}

	logit("chpass '%s' old='%s' new='%s'\n", r_user, oldpass, newpass);

	*message = NULL;

	/* Send off request */
	ZERO_STRUCT(request);
	ZERO_STRUCT(response);

	STRCPY_RET(request.data.chauthtok.user, r_user);
	STRCPY_RET(request.data.chauthtok.oldpass, oldpass);
	STRCPY_RET(request.data.chauthtok.newpass, newpass);

	if (*user == WB_AIX_ENCODED) {
		free(r_user);
	}

	result = winbindd_request(WINBINDD_PAM_CHAUTHTOK, &request, &response);

	free_response(&response);

	if (result == NSS_STATUS_SUCCESS) {
		errno = 0;
		return 0;
	}

	errno = EINVAL;
	return -1;
}
_PUBLIC_ NSS_STATUS _nss_winbind_endgrent(void)
{
	NSS_STATUS ret;
#ifdef DEBUG_NSS
	fprintf(stderr, "[%5d]: endgrent\n", getpid());
#endif

	if (num_gr_cache > 0) {
		ndx_gr_cache = num_gr_cache = 0;
		free_response(&getgrent_response);
	}

	ret = winbindd_request(WINBINDD_ENDGRENT, NULL, NULL);
#ifdef DEBUG_NSS
	fprintf(stderr, "[%5d]: endgrent returns %s (%d)\n", getpid(),
		nss_err_str(ret), ret);
#endif
	return ret;
}
Exemple #15
0
NSS_STATUS
_nss_winbind_setpwent(void)
{
	NSS_STATUS ret;
#ifdef DEBUG_NSS
	fprintf(stderr, "[%5d]: setpwent\n", getpid());
#endif

	if (num_pw_cache > 0) {
		ndx_pw_cache = num_pw_cache = 0;
		free_response(&getpwent_response);
	}

	ret = winbindd_request_response(WINBINDD_SETPWENT, NULL, NULL);
#ifdef DEBUG_NSS
	fprintf(stderr, "[%5d]: setpwent returns %s (%d)\n", getpid(),
		nss_err_str(ret), ret);
#endif
	return ret;
}
int
logout(int argc, char **argv)
{
	iscsid_sym_id_t req;
	iscsid_response_t *rsp;

	if (!cl_get_id('I', &req, argc, argv)) {
		arg_missing("Session");
	}
	check_extra_args(argc, argv);

	send_request(ISCSID_LOGOUT, sizeof(req), &req);
	rsp = get_response(FALSE);
	if (rsp->status) {
		status_error(rsp->status);
	}
	free_response(rsp);

	printf("OK\n");
	return 0;
}
Exemple #17
0
static response *resolve_stream(const char *url)
{
    request *request = http_get(url);
    response *response = http_send(request);

    if (http_read_body(response) < 0 && response->status != 302) {
        fprintf(stderr, "request failed %s", url); 
        return NULL;
    }

    sds stream_url = sdsnew(http_header(response, "Location"));

    free_response(response);

    request = http_get(stream_url);
    response = http_send(request);
    
    sdsfree(stream_url);

    return response;
}
Exemple #18
0
/* return a list of group SIDs for a user SID */
NSS_STATUS
_nss_winbind_getusersids(const char *user_sid, char **group_sids,
			 int *num_groups,
			 char *buffer, size_t buf_size, int *errnop)
{
	NSS_STATUS ret;
	struct winbindd_request request;
	struct winbindd_response response;

#ifdef DEBUG_NSS
	fprintf(stderr, "[%5d]: getusersids %s\n", getpid(), user_sid);
#endif

	ZERO_STRUCT(request);
	ZERO_STRUCT(response);

	strncpy(request.data.sid, user_sid,sizeof(request.data.sid) - 1);
	request.data.sid[sizeof(request.data.sid) - 1] = '\0';

	ret = winbindd_request(WINBINDD_GETUSERSIDS, &request, &response);

	if (ret != NSS_STATUS_SUCCESS) {
		goto done;
	}

	if (buf_size < response.length - sizeof(response)) {
		ret = NSS_STATUS_TRYAGAIN;
		errno = *errnop = ERANGE;
		goto done;
	}

	*num_groups = response.data.num_entries;
	*group_sids = buffer;
	memcpy(buffer, response.extra_data, response.length - sizeof(response));
	errno = *errnop = 0;
	
 done:
	free_response(&response);
	return ret;
}
Exemple #19
0
Fichier : fm.c Projet : trazyn/dbfm
int fm_love(struct playlist *pl)
{
	char **resp = NULL;

	if(!LOVE)
	{
		ack = CMD_LOVE;

		resp = api_send_request(CMD_LOVE, SID, NULL);

		if(NULL == resp)
		{
			return -1;
		}

		reset(&current, "like", "1");

		free_response(resp);
	}

	return 0;
}
Exemple #20
0
Fichier : fm.c Projet : trazyn/dbfm
int fm_unlove()
{
	char **resp = NULL;

	if(LOVE)
	{
		ack = CMD_UNLOEV;

		resp = api_send_request(CMD_UNLOEV, SID, NULL);

		if(NULL == resp)
		{
			return -1;
		}

		reset(&current, "like", "0");

		free_response(resp);
	}

	return 0;
}
Exemple #21
0
/* map a user or group name to a SID string */
NSS_STATUS
_nss_winbind_nametosid(const char *name, char **sid, char *buffer,
		       size_t buflen, int *errnop)
{
	NSS_STATUS ret;
	struct winbindd_response response;
	struct winbindd_request request;

#ifdef DEBUG_NSS
	fprintf(stderr, "[%5d]: nametosid %s\n", getpid(), name);
#endif

	ZERO_STRUCT(response);
	ZERO_STRUCT(request);

	strncpy(request.data.name.name, name, 
		sizeof(request.data.name.name) - 1);
	request.data.name.name[sizeof(request.data.name.name) - 1] = '\0';

	ret = winbindd_request(WINBINDD_LOOKUPNAME, &request, &response);
	if (ret != NSS_STATUS_SUCCESS) {
		*errnop = errno = EINVAL;
		goto failed;
	}

	if (buflen < strlen(response.data.sid.sid)+1) {
		ret = NSS_STATUS_TRYAGAIN;
		*errnop = errno = ERANGE;
		goto failed;
	}

	*errnop = errno = 0;
	*sid = buffer;
	strcpy(*sid, response.data.sid.sid);

failed:
	free_response(&response);
	return ret;
}
int
remove_initiator(int argc, char **argv)
{
	iscsid_sym_id_t req;
	iscsid_response_t *rsp;

	memset(&req, 0x0, sizeof(req));
	if (!cl_get_id('I', &req, argc, argv)) {
		arg_missing("Initiator Portal ID");
	}
	check_extra_args(argc, argv);

	send_request(ISCSID_REMOVE_INITIATOR_PORTAL, sizeof(req), &req);
	rsp = get_response(FALSE);
	if (rsp->status) {
		status_error(rsp->status);
	}
	free_response(rsp);

	printf("OK\n");
	return 0;
}
Exemple #23
0
/* map a gid to a SID string */
NSS_STATUS
_nss_winbind_gidtosid(gid_t gid, char **sid, char *buffer,
		      size_t buflen, int *errnop)
{
	NSS_STATUS ret;
	struct winbindd_response response;
	struct winbindd_request request;

#ifdef DEBUG_NSS
	fprintf(stderr, "[%5u]: gidtosid %u\n", (unsigned int)getpid(), (unsigned int)gid);
#endif

	ZERO_STRUCT(response);
	ZERO_STRUCT(request);

	request.data.gid = gid;

	ret = winbindd_request(WINBINDD_GID_TO_SID, &request, &response);
	if (ret != NSS_STATUS_SUCCESS) {
		*errnop = errno = EINVAL;
		goto failed;
	}

	if (buflen < strlen(response.data.sid.sid)+1) {
		ret = NSS_STATUS_TRYAGAIN;
		*errnop = errno = ERANGE;
		goto failed;
	}

	*errnop = errno = 0;
	*sid = buffer;
	strcpy(*sid, response.data.sid.sid);

failed:
	free_response(&response);
	return ret;
}
int
remove_connection(int argc, char **argv)
{
	iscsid_remove_connection_req_t req;
	iscsid_response_t *rsp;

	if (!cl_get_id('I', &req.session_id, argc, argv)) {
		arg_missing("Session");
	}
	if (!cl_get_id('C', &req.connection_id, argc, argv)) {
		arg_missing("Connection");
	}
	check_extra_args(argc, argv);

	send_request(ISCSID_REMOVE_CONNECTION, sizeof(req), &req);
	rsp = get_response(FALSE);
	if (rsp->status) {
		status_error(rsp->status);
	}
	free_response(rsp);

	printf("OK\n");
	return 0;
}
Exemple #25
0
NSS_STATUS
_nss_winbind_getpwent_r(struct passwd *result, char *buffer, 
			size_t buflen, int *errnop)
{
	NSS_STATUS ret;
	struct winbindd_request request;
	static int called_again;

#ifdef DEBUG_NSS
	fprintf(stderr, "[%5d]: getpwent\n", getpid());
#endif

	/* Return an entry from the cache if we have one, or if we are
	   called again because we exceeded our static buffer.  */

	if ((ndx_pw_cache < num_pw_cache) || called_again) {
		goto return_result;
	}

	/* Else call winbindd to get a bunch of entries */
	
	if (num_pw_cache > 0) {
		free_response(&getpwent_response);
	}

	ZERO_STRUCT(request);
	ZERO_STRUCT(getpwent_response);

	request.data.num_entries = MAX_GETPWENT_USERS;

	ret = winbindd_request(WINBINDD_GETPWENT, &request, 
			       &getpwent_response);

	if (ret == NSS_STATUS_SUCCESS) {
		struct winbindd_pw *pw_cache;

		/* Fill cache */

		ndx_pw_cache = 0;
		num_pw_cache = getpwent_response.data.num_entries;

		/* Return a result */

	return_result:

		pw_cache = getpwent_response.extra_data;

		/* Check data is valid */

		if (pw_cache == NULL) {
			return NSS_STATUS_NOTFOUND;
		}

		ret = fill_pwent(result, &pw_cache[ndx_pw_cache],
				 &buffer, &buflen);
		
		/* Out of memory - try again */

		if (ret == NSS_STATUS_TRYAGAIN) {
			called_again = True;
			*errnop = errno = ERANGE;
			return ret;
		}

		*errnop = errno = 0;
		called_again = False;
		ndx_pw_cache++;

		/* If we've finished with this lot of results free cache */

		if (ndx_pw_cache == num_pw_cache) {
			ndx_pw_cache = num_pw_cache = 0;
			free_response(&getpwent_response);
		}
	}

	return ret;
}
Exemple #26
0
NTSTATUS contact_winbind_auth_crap(const char *username, 
				   const char *domain, 
				   const char *workstation,
				   const DATA_BLOB *challenge, 
				   const DATA_BLOB *lm_response, 
				   const DATA_BLOB *nt_response, 
				   uint32 flags, 
				   uint8 lm_key[8], 
				   uint8 user_session_key[16], 
				   char **error_string, 
				   char **unix_name) 
{
	NTSTATUS nt_status;
        NSS_STATUS result;
	struct winbindd_request request;
	struct winbindd_response response;

	if (!get_require_membership_sid()) {
		return NT_STATUS_INVALID_PARAMETER;
	}

	ZERO_STRUCT(request);
	ZERO_STRUCT(response);

	request.flags = flags;

	request.data.auth_crap.logon_parameters = MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT | MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT;

	if (require_membership_of_sid)
		fstrcpy(request.data.auth_crap.require_membership_of_sid, require_membership_of_sid);

        fstrcpy(request.data.auth_crap.user, username);
	fstrcpy(request.data.auth_crap.domain, domain);

	fstrcpy(request.data.auth_crap.workstation, 
		workstation);

	memcpy(request.data.auth_crap.chal, challenge->data, MIN(challenge->length, 8));

	if (lm_response && lm_response->length) {
		memcpy(request.data.auth_crap.lm_resp, 
		       lm_response->data, 
		       MIN(lm_response->length, sizeof(request.data.auth_crap.lm_resp)));
		request.data.auth_crap.lm_resp_len = lm_response->length;
	}

	if (nt_response && nt_response->length) {
		memcpy(request.data.auth_crap.nt_resp, 
		       nt_response->data, 
		       MIN(nt_response->length, sizeof(request.data.auth_crap.nt_resp)));
                request.data.auth_crap.nt_resp_len = nt_response->length;
	}
	
	result = winbindd_request_response(WINBINDD_PAM_AUTH_CRAP, &request, &response);

	/* Display response */

	if ((result != NSS_STATUS_SUCCESS) && (response.data.auth.nt_status == 0)) {
		nt_status = NT_STATUS_UNSUCCESSFUL;
		if (error_string)
			*error_string = smb_xstrdup("Reading winbind reply failed!");
		free_response(&response);
		return nt_status;
	}
	
	nt_status = (NT_STATUS(response.data.auth.nt_status));
	if (!NT_STATUS_IS_OK(nt_status)) {
		if (error_string) 
			*error_string = smb_xstrdup(response.data.auth.error_string);
		free_response(&response);
		return nt_status;
	}

	if ((flags & WBFLAG_PAM_LMKEY) && lm_key) {
		memcpy(lm_key, response.data.auth.first_8_lm_hash, 
		       sizeof(response.data.auth.first_8_lm_hash));
	}
	if ((flags & WBFLAG_PAM_USER_SESSION_KEY) && user_session_key) {
		memcpy(user_session_key, response.data.auth.user_session_key, 
			sizeof(response.data.auth.user_session_key));
	}

	if (flags & WBFLAG_PAM_UNIX_NAME) {
		*unix_name = SMB_STRDUP((char *)response.extra_data.data);
		if (!*unix_name) {
			free_response(&response);
			return NT_STATUS_NO_MEMORY;
		}
	}

	free_response(&response);
	return nt_status;
}
Exemple #27
0
/* map a sid string to a user or group name */
NSS_STATUS
_nss_winbind_sidtoname(const char *sid, char **name, char *buffer,
		       size_t buflen, int *errnop)
{
	NSS_STATUS ret;
	struct winbindd_response response;
	struct winbindd_request request;
	static char sep_char;
	unsigned needed;

#ifdef DEBUG_NSS
	fprintf(stderr, "[%5d]: sidtoname %s\n", getpid(), sid);
#endif

	ZERO_STRUCT(response);
	ZERO_STRUCT(request);

	/* we need to fetch the separator first time through */
	if (!sep_char) {
		ret = winbindd_request(WINBINDD_INFO, &request, &response);
		if (ret != NSS_STATUS_SUCCESS) {
			*errnop = errno = EINVAL;
			goto failed;
		}

		sep_char = response.data.info.winbind_separator;
		free_response(&response);
	}


	strncpy(request.data.sid, sid, 
		sizeof(request.data.sid) - 1);
	request.data.sid[sizeof(request.data.sid) - 1] = '\0';

	ret = winbindd_request(WINBINDD_LOOKUPSID, &request, &response);
	if (ret != NSS_STATUS_SUCCESS) {
		*errnop = errno = EINVAL;
		goto failed;
	}

	needed = 
		strlen(response.data.name.dom_name) +
		strlen(response.data.name.name) + 2;

	if (buflen < needed) {
		ret = NSS_STATUS_TRYAGAIN;
		*errnop = errno = ERANGE;
		goto failed;
	}

	snprintf(buffer, needed, "%s%c%s", 
		 response.data.name.dom_name,
		 sep_char,
		 response.data.name.name);

	*name = buffer;
	*errnop = errno = 0;

failed:
	free_response(&response);
	return ret;
}
Exemple #28
0
int read_dec_files (Tbl *decdef, int *dec_fac, Tbl **decimators)

{
    int i, j, n;
    Response *rsp;
    char string[512];
    FILE *file;

    FIR_decimation *decptr;
    Response *resp;

    resp = (Response *) new_response ();

    if(*decimators == NULL) *decimators = newtbl(0);
    if (resp == NULL) {
        elog_die(0, "read_dec_files: Malloc error on decimation response structure.\n");
        return (0);
    }
    for (i=0,(*dec_fac)=1; i<maxtbl(decdef); i++) {
        int ok;
        char *decfile;
        decfile = gettbl(decdef,i);
        if(!strcmp(decfile,"none") )
        {
            *dec_fac = 1.0;
            decptr = (FIR_decimation *) malloc(sizeof(FIR_decimation));
            if(decptr == NULL)
            {
                elog_notify(0,"Cannot malloc decimation structure for stage %d\n",
                            i);
                return(0);
            }
            decptr->decfac = 1.0;
            decptr->ncoefs = 0;
            decptr->coefs=NULL;
            pushtbl(*decimators,decptr);
            return(2);
        }

        file = fopen(decfile, "r");
        if (file == NULL) {
            elog_notify(0, "read_dec_files: Unable to open response stage file '%s'.\n",
                        decfile);
            return (0);
        }
        if (read_response (file, &rsp)) {
            elog_clear_register(1);
            elog_notify(0, "read_dec_files: read_response() error on stage file '%s'.\n",
                        decfile);
            return (0);
        }
        fclose (file);
        get_response_nstages (rsp, &n);
        for (j=0,ok=0; j<n; j++) {
            int dec_factor, nnum, nden;
            double srate;

            get_response_stage_type (rsp, j, string);
            if (strcmp(string, "fir")) continue;
            get_response_stage_fir_ncoefs (rsp, j, &srate, &dec_factor, &nnum, &nden);
            if (nden > 1) {
                elog_notify(0, "read_dec_files: Dont know how to do IIR filters (%s).\n",
                            decfile);
                return (0);
            }
            if (nnum < 1) {
                elog_notify(0, "read_dec_files: No numerator terms (%s).\n",
                            decfile);
                return (0);
            }
            ok=1;
            (*dec_fac) *= dec_factor;
        }
        if (!ok) {
            elog_notify(0, "read_dec_files: no fir stage on file '%s'.\n",
                        decfile);
            return (0);
        }
        for (j=0; j<n; j++) {
            Response_group *gpi;

            get_response_stage_type (rsp, j, string);
            if (strcmp(string, "fir")) continue;
            gpi = rsp->groups + j;
            if (copy_response_group (gpi, (resp), -1) < 0) {
                elog_notify(0, "read_dec_files: copy_response_group() error.\n");
                return (0);
            }
        }
        free_response (rsp);
    }
    get_response_nstages ((resp), &n);

    for (i=0; i<n; i++) {
        Response_group *gpi;
        int dec_factor, nnum, nden;
        double srate;
        double *coefsi, *coefs_err;
        double *coefdi, *coefd_err;

        decptr = (FIR_decimation *) malloc(sizeof(FIR_decimation));
        if(decptr == NULL)
        {
            elog_notify(0,"Cannot malloc decimation structure for stage %d\n",
                        i);
            return(0);
        }

        gpi = (resp)->groups + i;
        get_response_stage_fir_ncoefs ((resp), i, &srate, &dec_factor, &nnum, &nden);
        get_response_stage_fir_coefs ((resp), i, &nnum, &coefsi, &coefs_err,
                                      &nden, &coefdi, &coefd_err);
        for (j=0; j<nnum/2; j++) if (coefsi[j] != coefsi[nnum-j-1]) break;
        if (j < nnum/2) {
            elog_notify(0, "read_dec_files: Can only do symetrical FIR filters.\n");
            return (0);
        }

        decptr->ncoefs = nnum;
        decptr->decfac = dec_factor;
        decptr->coefs = calloc(nnum,sizeof(float));
        if((decptr->coefs) == NULL)
            elog_die(0,"read_dec_files:  can't alloc filter coef array of length %d\n",nnum);
        for(j=0; j<nnum; j++) decptr->coefs[j] = coefsi[j];
        pushtbl(*decimators,decptr);
    }
    return (1);
}
Exemple #29
0
static NSS_STATUS
winbind_getgrent(enum winbindd_cmd cmd,
		 struct group *result,
		 char *buffer, size_t buflen, int *errnop)
{
	NSS_STATUS ret;
	static struct winbindd_request request;
	static int called_again;
	

#ifdef DEBUG_NSS
	fprintf(stderr, "[%5d]: getgrent\n", getpid());
#endif

	/* Return an entry from the cache if we have one, or if we are
	   called again because we exceeded our static buffer.  */

	if ((ndx_gr_cache < num_gr_cache) || called_again) {
		goto return_result;
	}

	/* Else call winbindd to get a bunch of entries */
	
	if (num_gr_cache > 0) {
		free_response(&getgrent_response);
	}

	ZERO_STRUCT(request);
	ZERO_STRUCT(getgrent_response);

	request.data.num_entries = MAX_GETGRENT_USERS;

	ret = winbindd_request(cmd, &request, 
			       &getgrent_response);

	if (ret == NSS_STATUS_SUCCESS) {
		struct winbindd_gr *gr_cache;
		int mem_ofs;

		/* Fill cache */

		ndx_gr_cache = 0;
		num_gr_cache = getgrent_response.data.num_entries;

		/* Return a result */

	return_result:

		gr_cache = getgrent_response.extra_data;

		/* Check data is valid */

		if (gr_cache == NULL) {
			return NSS_STATUS_NOTFOUND;
		}

		/* Fill group membership.  The offset into the extra data
		   for the group membership is the reported offset plus the
		   size of all the winbindd_gr records returned. */

		mem_ofs = gr_cache[ndx_gr_cache].gr_mem_ofs +
			num_gr_cache * sizeof(struct winbindd_gr);

		ret = fill_grent(result, &gr_cache[ndx_gr_cache],
				 ((char *)getgrent_response.extra_data)+mem_ofs,
				 &buffer, &buflen);
		
		/* Out of memory - try again */

		if (ret == NSS_STATUS_TRYAGAIN) {
			called_again = True;
			*errnop = errno = ERANGE;
			return ret;
		}

		*errnop = 0;
		called_again = False;
		ndx_gr_cache++;

		/* If we've finished with this lot of results free cache */

		if (ndx_gr_cache == num_gr_cache) {
			ndx_gr_cache = num_gr_cache = 0;
			free_response(&getgrent_response);
		}
	}

	return ret;
}
Exemple #30
0
NSS_STATUS
_nss_winbind_getgrnam_r(const char *name,
			struct group *result, char *buffer,
			size_t buflen, int *errnop)
{
	NSS_STATUS ret;
	static struct winbindd_response response;
	struct winbindd_request request;
	static int keep_response;
	
#ifdef DEBUG_NSS
	fprintf(stderr, "[%5d]: getgrnam %s\n", getpid(), name);
#endif

	/* If our static buffer needs to be expanded we are called again */
	
	if (!keep_response) {

		/* Call for the first time */

		ZERO_STRUCT(request);
		ZERO_STRUCT(response);

		strncpy(request.data.groupname, name, 
			sizeof(request.data.groupname));
		request.data.groupname
			[sizeof(request.data.groupname) - 1] = '\0';

		ret = winbindd_request(WINBINDD_GETGRNAM, &request, &response);

		if (ret == NSS_STATUS_SUCCESS) {
			ret = fill_grent(result, &response.data.gr, 
					 response.extra_data,
					 &buffer, &buflen);

			if (ret == NSS_STATUS_TRYAGAIN) {
				keep_response = True;
				*errnop = errno = ERANGE;
				return ret;
			}
		}

	} else {
		
		/* We've been called again */
		
		ret = fill_grent(result, &response.data.gr, 
				 response.extra_data, &buffer, &buflen);
		
		if (ret == NSS_STATUS_TRYAGAIN) {
			keep_response = True;
			*errnop = errno = ERANGE;
			return ret;
		}

		keep_response = False;
		*errnop = 0;
	}

	free_response(&response);
	return ret;
}