Esempio n. 1
0
static AuthData *
create_auth_data (CockpitAuth *self,
                  const gchar *name,
                  const gchar *application,
                  const gchar *type,
                  const gchar *remote_peer,
                  const gchar *logname,
                  GBytes *input)
{
  guint pipe_timeout;
  guint idle_timeout;
  guint wanted_fd;
  AuthData *ad = NULL;

  /* How long to wait for the auth process to send some data */
  pipe_timeout = timeout_option ("timeout", type, cockpit_ws_auth_process_timeout);
  /* How long to wait for a response from the client to a auth prompt */
  idle_timeout = timeout_option ("response-timeout", type,
                                 cockpit_ws_auth_response_timeout);
  /* The wanted authfd for this command, default is 3 */
  wanted_fd = cockpit_conf_guint (type, "authFD", 3, 1024, 3);

  ad = g_new0 (AuthData, 1);
  ad->refs = 1;
  ad->id = cockpit_auth_nonce (self);
  ad->pending_result = NULL;
  ad->response_data = NULL;
  ad->tag = NULL;
  ad->remote_peer = g_strdup (remote_peer);
  ad->auth_type = g_strdup (type);
  ad->authorization = g_bytes_ref (input);
  ad->application = g_strdup (application);

  ad->auth_process = g_object_new (COCKPIT_TYPE_AUTH_PROCESS,
                                   "pipe-timeout", pipe_timeout,
                                   "idle-timeout", idle_timeout,
                                   "id", ad->id,
                                   "logname", logname,
                                   "name", name,
                                   "wanted-auth-fd", wanted_fd,
                                   NULL);
  return ad;
}
Esempio n. 2
0
void rwqAction(int sockID, struct sockaddr_in sockInfo, struct PARAMS *params)
{
	unsigned short int bnum = 1;
	unsigned short int sz  = 0;

	tftp_ack_hdr ack;
	tftp_rwq_hdr rwq;
	tftp_data_hdr data;
	char buffer[MAX_BUFFER];
	
	bzero(&data, sizeof(tftp_data_hdr));
	bzero(&rwq, sizeof(tftp_rwq_hdr));

	rwq_deserialize(&rwq, buffer);

	if(mode_transfer(rwq.mode, "octet", params) == -1)
	{
		sendError(sockID, sockInfo, RFC1350_OP_ERROR, RFC1350_ERR_NOTDEF, "Set transfer mode to octet");
		return;
	}

	FILE *pFile = NULL;
	if((pFile = open_file(rwq.filename, "rb", params)) == NULL)
	{
		return;
	}

	if(timeout_option(&rwq, params) == 1)
	{
		sendACKOpt(sockID, sockInfo, "timeout", params->rexmt);
	}

	int t_out = 0;
	int intents = 5;
	
	do
	{
		bzero(buffer, MAX_BUFFER);
		bzero(&data, sizeof(tftp_data_hdr));

		data.opcode = RFC1350_OP_DATA;
		data.num_block = bnum++;

		sz = fread(data.data, 1, RFC1350_BLOCKSIZE, pFile);
		sz = data_serialize(&data, buffer, sz);		
	
		bzero(&ack, sizeof(tftp_ack_hdr));
		intents = 5;
		
		do
		{
			sendInfo(sockID, sockInfo, buffer, sz);			
			if((t_out = select_func(sockID, params->rexmt)) == 1)
			{
				get_ack(&ack, sockID, sockInfo, params);
				ack_serialize(&ack, buffer);
			}
		}while(t_out == 0 && --intents);
	}while((sz - SHORT_SIZE * 2) == RFC1350_BLOCKSIZE && t_out != -1);

	if(intents == 0)
	{
		printf("Transfer timed out\n");
	}

	fclose(pFile);
}