static gboolean
delete_event_callback (GtkWidget       *widget,
		       GdkEventAny     *event,
		       gpointer         data)
{
	void (*response_callback) (GtkDialog *dialog,
				   gint response_id);

	response_callback = data;

	response_callback (GTK_DIALOG (widget), GTK_RESPONSE_CLOSE);
	
	return TRUE;
}
static gsize
handle_response (MMSerialPort *port,
                 GByteArray *response,
                 GError *error,
                 GCallback callback,
                 gpointer callback_data)
{
    MMAtSerialPort *self = MM_AT_SERIAL_PORT (port);
    MMAtSerialResponseFn response_callback = (MMAtSerialResponseFn) callback;
    GString *string;

    /* Convert to a string and call the callback */
    string = g_string_sized_new (response->len + 1);
    g_string_append_len (string, (const char *) response->data, response->len);
    response_callback (self, string, error, callback_data);
    g_string_free (string, TRUE);

    return response->len;
}
Esempio n. 3
0
/* {{{ libssh2_userauth_keyboard_interactive
 * Authenticate using a challenge-response authentication
 */
LIBSSH2_API int libssh2_userauth_keyboard_interactive_ex(LIBSSH2_SESSION *session, const char *username, unsigned int username_len,
														 LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC((*response_callback)))
{
	unsigned char *s, *data; /* packet */
	unsigned long packet_len;

	packet_len = 1         /* byte      SSH_MSG_USERAUTH_REQUEST */
		+ 4 + username_len /* string    user name (ISO-10646 UTF-8, as defined in [RFC-3629]) */
		+ 4 + 14           /* string    service name (US-ASCII) */
		+ 4 + 20           /* string    "keyboard-interactive" (US-ASCII) */
		+ 4 + 0            /* string    language tag (as defined in [RFC-3066]) */
		+ 4 + 0            /* string    submethods (ISO-10646 UTF-8) */
		;

	if (!(data = s = LIBSSH2_ALLOC(session, packet_len))) {
		libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate memory for keyboard-interactive authentication", 0);
		return -1;
	}

	*s++ = SSH_MSG_USERAUTH_REQUEST;

	/* user name */
	libssh2_htonu32(s, username_len);										s += 4;
	memcpy(s, username, username_len);										s += username_len;

	/* service name */
	libssh2_htonu32(s, sizeof("ssh-connection") - 1);						s += 4;
	memcpy(s, "ssh-connection", sizeof("ssh-connection") - 1);				s += sizeof("ssh-connection") - 1;

	/* "keyboard-interactive" */
	libssh2_htonu32(s, sizeof("keyboard-interactive") - 1);					s += 4;
	memcpy(s, "keyboard-interactive", sizeof("keyboard-interactive") - 1);	s += sizeof("keyboard-interactive") - 1;

	/* language tag */
	libssh2_htonu32(s, 0);													s += 4;

	/* submethods */
	libssh2_htonu32(s, 0);													s += 4;

#ifdef LIBSSH2_DEBUG_USERAUTH
	_libssh2_debug(session, LIBSSH2_DBG_AUTH, "Attempting keyboard-interactive authentication");
#endif
	if (libssh2_packet_write(session, data, packet_len)) {
		libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, "Unable to send keyboard-interactive request", 0);
		LIBSSH2_FREE(session, data);
		return -1;
	}
	LIBSSH2_FREE(session, data);

	for (;;) {
		unsigned char reply_codes[4] = { SSH_MSG_USERAUTH_SUCCESS, SSH_MSG_USERAUTH_FAILURE, SSH_MSG_USERAUTH_INFO_REQUEST, 0 };
		unsigned int auth_name_len;
		char* auth_name = NULL;
		unsigned auth_instruction_len;
		char* auth_instruction = NULL;
		unsigned int language_tag_len;
		unsigned long data_len;
		unsigned int num_prompts = 0;
		unsigned int i;
		int auth_failure = 1;
		LIBSSH2_USERAUTH_KBDINT_PROMPT* prompts = NULL;
		LIBSSH2_USERAUTH_KBDINT_RESPONSE* responses = NULL;

		if (libssh2_packet_requirev(session, reply_codes, &data, &data_len)) {
			return -1;
		}

		if (data[0] == SSH_MSG_USERAUTH_SUCCESS) {
#ifdef LIBSSH2_DEBUG_USERAUTH
			_libssh2_debug(session, LIBSSH2_DBG_AUTH, "Keyboard-interactive authentication successful");
#endif
			LIBSSH2_FREE(session, data);
			session->state |= LIBSSH2_STATE_AUTHENTICATED;
			return 0;
		}

		if (data[0] == SSH_MSG_USERAUTH_FAILURE) {
			LIBSSH2_FREE(session, data);
			return -1;
		}

		/* server requested PAM-like conversation */

		s = data + 1;

		/* string    name (ISO-10646 UTF-8) */
		auth_name_len = libssh2_ntohu32(s);								s += 4;
		if (!(auth_name = LIBSSH2_ALLOC(session, auth_name_len))) {
			libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate memory for keyboard-interactive 'name' request field", 0);
			goto cleanup;
		}
		memcpy(auth_name, s, auth_name_len);							s += auth_name_len;

		/* string    instruction (ISO-10646 UTF-8) */
		auth_instruction_len = libssh2_ntohu32(s); s += 4;
		if (!(auth_instruction = LIBSSH2_ALLOC(session, auth_instruction_len))) {
			libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate memory for keyboard-interactive 'instruction' request field", 0);
			goto cleanup;
		}
		memcpy(auth_instruction, s, auth_instruction_len);				s += auth_instruction_len;

		/* string    language tag (as defined in [RFC-3066]) */
		language_tag_len = libssh2_ntohu32(s);							s += 4;
		/* ignoring this field as deprecated */							s += language_tag_len;

		/* int       num-prompts */
		num_prompts = libssh2_ntohu32(s);								s += 4;

		prompts = LIBSSH2_ALLOC(session, sizeof(LIBSSH2_USERAUTH_KBDINT_PROMPT) * num_prompts);
		if (!prompts) {
			libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate memory for keyboard-interactive prompts array", 0);
			goto cleanup;
		}
		memset(prompts, 0, sizeof(LIBSSH2_USERAUTH_KBDINT_PROMPT) * num_prompts);

		responses = LIBSSH2_ALLOC(session, sizeof(LIBSSH2_USERAUTH_KBDINT_RESPONSE) * num_prompts);
		if (!responses) {
			libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate memory for keyboard-interactive responses array", 0);
			goto cleanup;
		}
		memset(responses, 0, sizeof(LIBSSH2_USERAUTH_KBDINT_RESPONSE) * num_prompts);

		for(i = 0; i != num_prompts; ++i) {
			/* string    prompt[1] (ISO-10646 UTF-8) */
			prompts[i].length = libssh2_ntohu32(s);						s += 4;
			if (!(prompts[i].text = LIBSSH2_ALLOC(session, prompts[i].length))) {
				libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate memory for keyboard-interactive prompt message", 0);
				goto cleanup;
			}
			memcpy(prompts[i].text, s, prompts[i].length);				s += prompts[i].length;

			/* boolean   echo[1] */
			prompts[i].echo = *s++;
		}

		response_callback(auth_name, auth_name_len,  auth_instruction, auth_instruction_len, num_prompts, prompts, responses, &session->abstract);

#ifdef LIBSSH2_DEBUG_USERAUTH
		_libssh2_debug(session, LIBSSH2_DBG_AUTH, "Keyboard-interactive response callback function invoked");
#endif

		packet_len = 1 /* byte      SSH_MSG_USERAUTH_INFO_RESPONSE */
			+ 4        /* int       num-responses */
			;

		for (i = 0; i != num_prompts; ++i) {
			packet_len += 4 + responses[i].length; /* string    response[1] (ISO-10646 UTF-8) */
		}

		if (!(data = s = LIBSSH2_ALLOC(session, packet_len))) {
			libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate memory for keyboard-interactive response packet", 0);
			goto cleanup;
		}

		*s = SSH_MSG_USERAUTH_INFO_RESPONSE; s++;
		libssh2_htonu32(s, num_prompts);								s += 4;

		for (i = 0; i != num_prompts; ++i) {
			libssh2_htonu32(s, responses[i].length);					s += 4;
			memcpy(s, responses[i].text, responses[i].length);			s += responses[i].length;
		}

		if (libssh2_packet_write(session, data, packet_len)) {
			libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, "Unable to send userauth-keyboard-interactive request", 0);
			goto cleanup;
		}

		auth_failure = 0;

	cleanup:
		/* It's safe to clean all the data here, because unallocated pointers
		 * are filled by zeroes
		 */

		LIBSSH2_FREE(session, data);

		if (prompts) {
			for (i = 0; i != num_prompts; ++i) {
				LIBSSH2_FREE(session, prompts[i].text);
			}
		}

		if (responses) {
			for (i = 0; i != num_prompts; ++i) {
				LIBSSH2_FREE(session, responses[i].text);
			}
		}

		LIBSSH2_FREE(session, prompts);
		LIBSSH2_FREE(session, responses);

		if (auth_failure) {
			return -1;
		}
	}
}
Esempio n. 4
0
int template_page(char **postvars, char **getvars, int form_method) {
	int i=0;
	int write_flag=FALSE;
	char callback[100];
	dac_param_t	 dac_param = { "090",		/*THRESHOLD 0*/
				               "000",	    /*THRESHOLD 1*/
				               "000",       /*THRESHOLD 2*/
                               "000",		/*THRESHOLD 3*/
				               "000",	    /*THRESHOLD 4*/
                               "000",		/*THRESHOLD 5*/
				               "000",	    /*THRESHOLD 6*/
                               "000",		/*THRESHOLD 7*/
                               "100",		/*PREAMP*/
				               "005",	    /*IKRUM*/
				               "125",       /*SHAPER*/
                               "125",		/*DISC*/
				               "100",	    /*DISCLS*/
                               "100",		/*SHAPER_TEST*/
				               "061",	    /*DAC_DISCL*/
                               "100",		/*DAC_TEST*/
                               "067",		/*DAC_DISCH*/
				               "030",	    /*DELAY*/
				               "128",       /*TP_BUFFER_IN*/
                               "004",		/*TP_BUFFER_OUT*/
				               "255",	    /*RPZ*/
                               "141",		/*GND*/
				               "120",	    /*TP_REF*/
                               "177",		/*FBK*/
                               "187",		/*CAS*/
				               "260",	    /*TP_REFA*/
                               "263"		/*TP_REFB*/
	                         };
	
	if(read_dacfile(DAC_FILE,&dac_param) <0){
		printf("File %s not found\n",DAC_FILE);		
	}
	
	
	if(form_method == GET) {	
		for (i = 0; getvars[i]; i += 2) {
			    if (strncmp(getvars[i], "threshold_0",BUFFER)==0) {
					strncpy(dac_param.THRESHOLD_0, getvars[i+1],BUFFER);	
				}				
				else if (strncmp(getvars[i], "threshold_1",BUFFER)==0) {
					strncpy(dac_param.THRESHOLD_1, getvars[i+1],BUFFER);
				}
				else if (strncmp(getvars[i], "threshold_2",BUFFER)==0) {
					strncpy(dac_param.THRESHOLD_2, getvars[i+1],BUFFER);
				}
				else if (strncmp(getvars[i], "threshold_3",BUFFER)==0) {
					strncpy(dac_param.THRESHOLD_3, getvars[i+1],BUFFER);
				}
				else if (strncmp(getvars[i], "threshold_4",BUFFER)==0) {
					strncpy(dac_param.THRESHOLD_4, getvars[i+1],BUFFER);
				}
                else if (strncmp(getvars[i], "threshold_5",BUFFER)==0) {
					strncpy(dac_param.THRESHOLD_5, getvars[i+1],BUFFER);
				}
				else if (strncmp(getvars[i], "threshold_6",BUFFER)==0) {
					strncpy(dac_param.THRESHOLD_6, getvars[i+1],BUFFER);
				}
				else if (strncmp(getvars[i], "threshold_7",BUFFER)==0) {
					strncpy(dac_param.THRESHOLD_7, getvars[i+1],BUFFER);
				}
                else if (strncmp(getvars[i], "preamp",BUFFER)==0) {
					strncpy(dac_param.PREAMP, getvars[i+1],BUFFER);	
				}				
				else if (strncmp(getvars[i], "ikrum",BUFFER)==0) {
					strncpy(dac_param.IKRUM, getvars[i+1],BUFFER);
				}
				else if (strncmp(getvars[i], "shaper",BUFFER)==0) {
					strncpy(dac_param.SHAPER, getvars[i+1],BUFFER);
				}
				else if (strncmp(getvars[i], "disc",BUFFER)==0) {
					strncpy(dac_param.DISC, getvars[i+1],BUFFER);
				}
				else if (strncmp(getvars[i], "discls",BUFFER)==0) {
					strncpy(dac_param.DISCLS, getvars[i+1],BUFFER);
				}
                else if (strncmp(getvars[i], "shaper_test",BUFFER)==0) {
					strncpy(dac_param.SHAPER_TEST, getvars[i+1],BUFFER);
				}
				else if (strncmp(getvars[i], "dac_discl",BUFFER)==0) {
					strncpy(dac_param.DAC_DISCL, getvars[i+1],BUFFER);
				}
				else if (strncmp(getvars[i], "dac_test",BUFFER)==0) {
					strncpy(dac_param.DAC_TEST, getvars[i+1],BUFFER);
				}
                else if (strncmp(getvars[i], "dac_disch",BUFFER)==0) {
					strncpy(dac_param.DAC_DISCH, getvars[i+1],BUFFER);	
				}				
				else if (strncmp(getvars[i], "delay",BUFFER)==0) {
					strncpy(dac_param.DELAY, getvars[i+1],BUFFER);
				}
				else if (strncmp(getvars[i], "tp_bufferin",BUFFER)==0) {
					strncpy(dac_param.TP_BUFFER_IN, getvars[i+1],BUFFER);
				}
				else if (strncmp(getvars[i], "tp_bufferout",BUFFER)==0) {
					strncpy(dac_param.TP_BUFFER_OUT, getvars[i+1],BUFFER);
				}
				else if (strncmp(getvars[i], "rpz",BUFFER)==0) {
					strncpy(dac_param.RPZ, getvars[i+1],BUFFER);
				}
                else if (strncmp(getvars[i], "gnd",BUFFER)==0) {
					strncpy(dac_param.GND, getvars[i+1],BUFFER);
				}
				else if (strncmp(getvars[i], "tp_ref",BUFFER)==0) {
					strncpy(dac_param.TP_REF, getvars[i+1],BUFFER);
				}
				else if (strncmp(getvars[i], "fbk",BUFFER)==0) {
					strncpy(dac_param.FBK, getvars[i+1],BUFFER);
				}
                else if (strncmp(getvars[i], "cas",BUFFER)==0) {
					strncpy(dac_param.CAS, getvars[i+1],BUFFER);
				}
				else if (strncmp(getvars[i], "tp_refa",BUFFER)==0) {
					strncpy(dac_param.TP_REFA, getvars[i+1],BUFFER);
				}
				else if (strncmp(getvars[i], "tp_refb",BUFFER)==0) {
					strncpy(dac_param.TP_REFB, getvars[i+1],BUFFER);
				}

				else if (strncmp(getvars[i], "read",BUFFER)==0) {					
					if(response_callback(&callback)==0){
						printf("%s",callback);
					}
				
				}
				else if (strncmp(getvars[i], "write",BUFFER)==0) {
					write_flag=TRUE;					
				}
		}
		if(write_flag==TRUE){
			if(validate_dac_param(&dac_param)==0){
				write_dacfile(DAC_FILE,&dac_param);
			}	
		}
	}

	return 0;
}