示例#1
0
static int send_auth_result(server_generic_client_t *client, int result)
{
        int ret;
        uint64_t nident;
        prelude_client_profile_t *cp;

        if ( ! client->msg ) {
                ret = prelude_msg_new(&client->msg, 1, sizeof(uint64_t), PRELUDE_MSG_AUTH, 0);
                if ( ret < 0 )
                        return -1;

                cp = prelude_client_get_profile(manager_client);
                nident = prelude_hton64(prelude_client_profile_get_analyzerid(cp));
                prelude_msg_set(client->msg, result, sizeof(nident), &nident);
        }

        ret = prelude_msg_write(client->msg, client->fd);

        if ( ret < 0 ) {
                if ( prelude_error_get_code(ret) == PRELUDE_ERROR_EAGAIN ) {
                        server_generic_notify_write_enable(client);
                        return 0;
                }

                prelude_msg_destroy(client->msg);
                return -1;
        }

        prelude_msg_destroy(client->msg);

        client->msg = NULL;

        return (client->state & SERVER_GENERIC_CLIENT_STATE_AUTHENTICATED) ? 1 : -1;
}
示例#2
0
static int do_close_fd(server_generic_client_t *client)
{
        int ret;
        void *fd_ptr;

        do {
                ret = prelude_io_close(client->fd);
                if ( ret == 0 )
                        break;

                else if ( ret < 0 && prelude_io_is_error_fatal(client->fd, ret) )
                        return 0;

                if ( prelude_error_get_code(ret) == PRELUDE_ERROR_EAGAIN ) {
                        fd_ptr = prelude_io_get_fdptr(client->fd);
                        if ( fd_ptr && gnutls_record_get_direction(fd_ptr) == 1 )
                                server_generic_notify_write_enable(client);

                        return -1;
                }

                server_generic_log_client(client, PRELUDE_LOG_WARN, "connection closure error: %s.\n", prelude_strerror(ret));

        } while ( ret < 0 );

        return ret;
}
示例#3
0
/* Return a pointer to a string containing a description of the error
   code in the error value ERR.  This function is not thread-safe.  */
const char *prelude_strerror(prelude_error_t err)
{
	int no;
  	prelude_error_code_t code = prelude_error_get_code(err);

        if ( prelude_error_is_verbose(err) )
                return _prelude_thread_get_error();
        
  	if ( code & PRELUDE_ERROR_SYSTEM_ERROR ) {
      		no = prelude_error_code_to_errno(code);
      		if ( no )
			return strerror(no);
      		else
			code = PRELUDE_ERROR_UNKNOWN_ERRNO;
    	}
        
  	return dgettext(PACKAGE, msgstr + msgidx[msgidxof((int)code)]);
}
示例#4
0
/* Return a pointer to a string containing the name of the symbol of
   the error code in the error value ERR.  Returns NULL if the error
   code is not known.  */
const char *prelude_strerror_sym(prelude_error_t err)
{
	int idx;
  	prelude_error_code_t code = prelude_error_get_code(err);

  	if ( code & PRELUDE_ERROR_SYSTEM_ERROR ) {
      		code &= ~PRELUDE_ERROR_SYSTEM_ERROR;
      
      		idx = errnos_msgidxof (code);
      		if ( idx >= 0 )
			return errnos_msgstr + errnos_msgidx[idx];
      		else
			return NULL;
    	}

  	if ( msgidxof(code) == msgidxof(PRELUDE_ERROR_CODE_DIM) )
    		return NULL;

	return msgstr + msgidx[msgidxof(code)];
}
示例#5
0
/**
 * prelude_read_multiline2:
 * @fd: File descriptor to read input from.
 * @line: Pointer to a line counter.
 * @out: Pointer to a #prelude_string_t object where the line should be stored.
 *
 * This function handles line reading separated by the '\' character.
 *
 * Returns: 0 on success, a negative value if an error occured.
 */
int prelude_read_multiline2(FILE *fd, unsigned int *line, prelude_string_t *out)
{
        int ret, r;
        char buf[8192];

        prelude_string_clear(out);

        do {
                ret = prelude_read_multiline(fd, line, buf, sizeof(buf));
                if ( ret < 0 && (r = prelude_error_get_code(ret)) != PRELUDE_ERROR_EINVAL ) {
                        if ( r == PRELUDE_ERROR_EOF && ! prelude_string_is_empty(out) )
                                ret = 0;

                        break;
                }

                r = prelude_string_cat(out, buf);
                if ( r < 0 )
                        return r;

        } while ( ret < 0 );

        return ret;
}