Esempio n. 1
0
static inline void receive_and_reply(struct net_context *recv,
				     struct net_context *mcast_recv)
{
	struct net_buf *buf;

	buf = net_receive(recv, TICKS_UNLIMITED);
	if (buf) {
		prepare_reply("unicast ", buf);

		if (net_reply(recv, buf)) {
			ip_buf_unref(buf);
		}
		return;
	}

	buf = net_receive(mcast_recv, TICKS_UNLIMITED);
	if (buf) {
		prepare_reply("multicast ", buf);

		if (net_reply(mcast_recv, buf)) {
			ip_buf_unref(buf);
		}
		return;
	}
}
Esempio n. 2
0
void RXmTextGetSelectionPosition(message_t message)
{
  Widget w;
  Boolean result;
  XmTextPosition left,right;
  message_t reply=prepare_reply(message);

  toolkit_read_value(message,&w,XtRWidget);
  result=XmTextGetSelectionPosition(w,&left,&right);

  message_write_boolean(reply,result,boolean_tag);
  message_write_int(reply,left,int_tag);
  message_write_int(reply,right,int_tag);
  message_send(client_socket,reply);
  message_free(reply);
  must_confirm=False;
}
Esempio n. 3
0
void RXmTextPosToXY(message_t message)
{
  Widget w;
  XmTextPosition pos;
  Boolean result;
  Position x,y;
  message_t reply=prepare_reply(message);

  toolkit_read_value(message,&w,XtRWidget);
  toolkit_read_value(message,&pos,XtRInt);
  result=XmTextPosToXY(w,pos,&x,&y);

  message_write_boolean(reply,result,boolean_tag);
  message_write_int(reply,x,int_tag);
  message_write_int(reply,y,int_tag);
  message_send(client_socket,reply);
  message_free(reply);
  must_confirm=False;
}
Esempio n. 4
0
void thread_function(void *newsockfd_ptr){
	int fid_count;
	uint8_t* buffer;
	int n;
#ifdef DEBUG
	int i;
#endif
	int attach_flag;
	int newsockfd;
	uint8_t *Rbuffer;
	p9_obj_t *T_p9_obj;
	p9_obj_t *R_p9_obj;
        p9_obj_t *test_p9_obj;
	/* allocate the fid table */
	/* should be persistent through out the connection */
	fid_list **fid_table;
	fid_table = fid_table_init();
	/* end of fid_table allocation */
    assert(fid_table[0] == NULL);
    /* TODO: msize should be the minimum of 9000 and the one offered by the client */
    buffer = (uint8_t *)malloc(9000 * sizeof(char));
   	bzero(buffer, 256);
	T_p9_obj = (p9_obj_t *) malloc (sizeof(p9_obj_t));
	R_p9_obj = (p9_obj_t *) malloc(sizeof(p9_obj_t));
	test_p9_obj = (p9_obj_t *) malloc(sizeof(p9_obj_t));
	init_9p_obj(T_p9_obj);
	init_9p_obj(R_p9_obj);
	init_9p_obj(test_p9_obj);
	newsockfd = *(int *)newsockfd_ptr;
	fid_count = 0;
	attach_flag = 0;
	while(1){
	    	int size;
		int read_bytes;
		size = 0;
		n = read(newsockfd, buffer, 4);
		assert(n==4);
                size = buffer_bytes_to_int(buffer, 0, 4);
		assert(size!=0);
		read_bytes = 0;
		while(read_bytes < (size - 4)){
			n = read(newsockfd, buffer + 4 + read_bytes, size - 4 - read_bytes);
			read_bytes += n;
		}
		assert(read_bytes == (size - 4));
#ifdef DEBUG
		for(i = 0; i < size; i++){
			fprintf(stderr, "%d ", buffer[i]);
		}

		fprintf(stderr, "\n");
#endif

		/* decode the buffer and create the T object */
		decode(buffer, T_p9_obj);
		/* Print the T object in a friendly manner */
#ifdef DEBUG
		print_p9_obj(T_p9_obj);
#endif
		
		/* prepare the RMessage */
		prepare_reply(T_p9_obj, R_p9_obj, fid_table);
		/***************************/
		/* ENCODE, PRINT, AND SEND */
		/* encode the RMessage     */
		Rbuffer = encode(R_p9_obj);

		/* Check that the message buffer represents the R object */
#ifdef DEBUG
		decode(Rbuffer, test_p9_obj);
		assert(compare_9p_obj(R_p9_obj, test_p9_obj)==1);
		/* after checking. print and send */
		/* print the R P9 object in a friendly way */
		print_p9_obj(R_p9_obj);
#endif
		/* send the message buffer */
#ifdef DEBUG
		for(i = 0; i < R_p9_obj -> size; i++){
			fprintf(stderr, "%d ", Rbuffer[i]);
		}
		fprintf(stderr, "\n");
#endif
		if((n = write(newsockfd, Rbuffer, R_p9_obj -> size)) == -1){
			fprintf(stderr, "Error while writing to socket...\n");
			exit(1);
		}
		assert(n == R_p9_obj -> size);
		/***************************/
		if(T_p9_obj -> type == P9_TATTACH) attach_flag = 1;
		fid_count = get_fid_count(fid_table);
#ifdef DEBUG
		printf("fid_count_is %d\n", fid_count);
#endif
		destroy_p9_obj(T_p9_obj);
		destroy_p9_obj(R_p9_obj);
		destroy_p9_obj(test_p9_obj);
		free(Rbuffer);
#ifdef DEBUG
		printf("attach flag is %d\n", attach_flag);
#endif
		if((attach_flag == 1) && (fid_count ==0)){
#ifdef DEBUG
			printf("Connection is closing \n");
#endif
			break;
		}
	}
	fid_table_destroy(fid_table);
	free(buffer);
	free(T_p9_obj);
	free(R_p9_obj);
	free(test_p9_obj);
	close(newsockfd);
}
Esempio n. 5
0
int LOCAL_pam_handler(struct pam_auth_req *preq)
{
    struct LOCAL_request *lreq;
    static const char *attrs[] = {SYSDB_NAME,
                                  SYSDB_PWD,
                                  SYSDB_DISABLED,
                                  SYSDB_LAST_LOGIN,
                                  "lastPasswordChange",
                                  "accountExpires",
                                  SYSDB_FAILED_LOGIN_ATTEMPTS,
                                  "passwordHint",
                                  "passwordHistory",
                                  SYSDB_LAST_FAILED_LOGIN,
                                  NULL};
    struct ldb_result *res;
    const char *username = NULL;
    const char *pwdhash = NULL;
    char *new_hash = NULL;
    const char *password;
    struct pam_data *pd = preq->pd;
    int ret;

    DEBUG(4, ("LOCAL pam handler.\n"));

    lreq = talloc_zero(preq, struct LOCAL_request);
    if (!lreq) {
        return ENOMEM;
    }

    lreq->dbctx = preq->domain->sysdb;
    if (lreq->dbctx == NULL) {
        DEBUG(0, ("Fatal: Sysdb CTX not found for this domain!\n"));
        talloc_free(lreq);
        return ENOENT;
    }
    lreq->domain = preq->domain;
    lreq->ev = preq->cctx->ev;
    lreq->preq = preq;

    pd->pam_status = PAM_SUCCESS;

    ret = sysdb_get_user_attr(lreq, lreq->dbctx, preq->domain,
                              preq->pd->user, attrs, &res);
    if (ret != EOK) {
        DEBUG(1, ("sysdb_get_user_attr failed.\n"));
        talloc_free(lreq);
        return ret;
    }

    if (res->count < 1) {
        DEBUG(4, ("No user found with filter ["SYSDB_PWNAM_FILTER"]\n",
                  pd->user, pd->user));
        pd->pam_status = PAM_USER_UNKNOWN;
        goto done;
    } else if (res->count > 1) {
        DEBUG(4, ("More than one object found with filter ["SYSDB_PWNAM_FILTER"]\n",
                  pd->user, pd->user));
        lreq->error = EFAULT;
        goto done;
    }

    username = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_NAME, NULL);
    if (strcmp(username, pd->user) != 0) {
        DEBUG(1, ("Expected username [%s] get [%s].\n", pd->user, username));
        lreq->error = EINVAL;
        goto done;
    }

    lreq->res = res;

    switch (pd->cmd) {
        case SSS_PAM_AUTHENTICATE:
        case SSS_PAM_CHAUTHTOK:
        case SSS_PAM_CHAUTHTOK_PRELIM:
            if ((pd->cmd == SSS_PAM_CHAUTHTOK ||
                 pd->cmd == SSS_PAM_CHAUTHTOK_PRELIM) &&
                lreq->preq->cctx->priv == 1) {
/* TODO: maybe this is a candiate for an explicit audit message. */
                DEBUG(4, ("allowing root to reset a password.\n"));
                break;
            }
            ret = sss_authtok_get_password(pd->authtok, &password, NULL);
            NEQ_CHECK_OR_JUMP(ret, EOK, ("Failed to get password.\n"),
                               lreq->error, ret, done);

            pwdhash = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_PWD, NULL);
            NULL_CHECK_OR_JUMP(pwdhash, ("No password stored.\n"),
                               lreq->error, LDB_ERR_NO_SUCH_ATTRIBUTE, done);
            DEBUG(4, ("user: [%s], password hash: [%s]\n", username, pwdhash));

            ret = s3crypt_sha512(lreq, password, pwdhash, &new_hash);
            NEQ_CHECK_OR_JUMP(ret, EOK, ("nss_sha512_crypt failed.\n"),
                              lreq->error, ret, done);

            DEBUG(4, ("user: [%s], new hash: [%s]\n", username, new_hash));

            if (strcmp(new_hash, pwdhash) != 0) {
                DEBUG(1, ("Passwords do not match.\n"));
                do_failed_login(lreq);
                goto done;
            }

            break;
    }

    switch (pd->cmd) {
        case SSS_PAM_AUTHENTICATE:
            do_successful_login(lreq);
            break;
        case SSS_PAM_CHAUTHTOK:
            do_pam_chauthtok(lreq);
            break;
        case SSS_PAM_ACCT_MGMT:
            do_pam_acct_mgmt(lreq);
            break;
        case SSS_PAM_SETCRED:
            break;
        case SSS_PAM_OPEN_SESSION:
            break;
        case SSS_PAM_CLOSE_SESSION:
            break;
        case SSS_PAM_CHAUTHTOK_PRELIM:
            break;
        default:
            lreq->error = EINVAL;
            DEBUG(1, ("Unknown PAM task [%d].\n"));
    }

done:
    sss_authtok_set_empty(pd->newauthtok);
    sss_authtok_set_empty(pd->authtok);
    prepare_reply(lreq);
    return EOK;
}