Beispiel #1
0
/*FUNCTION*/
void HitHandler(void *t
  ){
  pThreadData ThisThread;
  pServerData ThisServer;
  pHttpdThread pHT;

  ThisThread = (pThreadData)t;
  pHT = ThisThread->pHT;

  ThisThread->AppThreadData = NULL;

#ifdef WIN32
  ThisThread->ClientIP[0] = ThisThread->addr.sin_addr.S_un.S_un_b.s_b1;
  ThisThread->ClientIP[1] = ThisThread->addr.sin_addr.S_un.S_un_b.s_b2;
  ThisThread->ClientIP[2] = ThisThread->addr.sin_addr.S_un.S_un_b.s_b3;
  ThisThread->ClientIP[3] = ThisThread->addr.sin_addr.S_un.S_un_b.s_b4;
#else
  memcpy(ThisThread->ClientIP,&(ThisThread->addr.sin_addr.s_addr),4);
#endif

  if( ! CheckAllowDeny(ThisThread) )FinishConnection(ThisThread);

  /* pointer to the server data that this thread belongs to */
  ThisServer = pHT->server + ThisThread->server_index;
  switch( ThisServer->type ){
    case SERVER_HTTP:
      HandleHttpHit(ThisThread);
    case SERVER_FTP:
      HandleFtpHit(ThisThread);
    }
  FinishConnection(ThisThread);
  }
Beispiel #2
0
/* This function should be called on list of socket file descriptors (sd) to determine
 * if any have opened successfully.  If so, it will return which one (index into
 * the array).  Otherwise it returns -1 if none have successfully opened.
 * This function will block for a maximum of 3 seconds.
 * As this function calls FinishConnection(), you shouldn't need to do anything special
 * after it returns success - the socket is set up and ready for use.
 */
static int CheckConnection(TCLinkCon *c, int *sd, int num_sd)
{
	fd_set wr_set, err_set;
	struct timeval tv;
	int max_sd = -1, i;

	tv.tv_sec = 3;        /* wait 3 seconds for soc->mething to happen */
	tv.tv_usec = 0;

	/* build the fd_sets used for select() */
	FD_ZERO(&wr_set);
	FD_ZERO(&err_set);
	for (i = 0; i < num_sd; i++)
	{
		if (sd[i] < 0) continue;
		FD_SET(sd[i], &wr_set);
		FD_SET(sd[i], &err_set);
		if (sd[i] > max_sd)
			max_sd = sd[i];
	}

	/* run the select and see what we have waiting for us */
	if (select(max_sd + 1, NULL, &wr_set, &err_set, &tv) < 1)
		return -1;     /* I hope this never happens */

	for (i = 0; i < num_sd; i++)
		if (sd[i] >= 0)
		{
			if (FD_ISSET(sd[i], &err_set))
			{
				/* error - close the socket and mark it defunct */
				close(sd[i]);
				sd[i] = -1;
			}
			else if (FD_ISSET(sd[i], &wr_set))
			{
				/* socket has opened! try to negotiate SSL */
				if (FinishConnection(c, sd[i])) {
					/* socket is ready to go, so return success */
					c->sd = sd[i];
					return i;
				}
				else {
					/* SSL handshake had errors, close the socket and mark it defunct */
					close(sd[i]);
					sd[i] = -1;
				}
			}
		}

	/* if we get here, nothing much interesting happened during those 3 seconds */
	return -1;
}
Beispiel #3
0
/*FUNCTION*/
void HandleFtpHit(pThreadData ThisThread
  ){
  pServerData ThisServer;
  fd_set readfds;
  struct timeval timeout;
  pHttpdThread pHT;
  char *Buffer;
  int cbBuffer,cbCharsRead,i;

  Buffer = ThisThread->buffer;
  cbBuffer = HIT_MAX_SIZE;

  /* pointer to the server data that this thread belongs to */
  pHT = ThisThread->pHT;
  ThisServer = pHT->server + ThisThread->server_index;

  send(ThisThread->msgsock,ThisServer->salute,strlen(ThisServer->salute),0);
  send(ThisThread->msgsock,"\r\n",2,0);

  while(1){
    FD_ZERO(&readfds);
    FD_SET(ThisThread->msgsock,&readfds);
    timeout.tv_sec=60;
    timeout.tv_usec=0;
    i = select(FD_SETSIZE,&readfds,NULL,NULL,&timeout);
    if( i == 0 )FinishConnection(ThisThread);
    cbCharsRead = recv(ThisThread->msgsock,Buffer,cbBuffer,0);
    /* some clients send such packets, but I could not figure out how */
    if( cbCharsRead == 0 )FinishConnection(ThisThread);
    if( cbCharsRead < 0 )FinishConnection(ThisThread);
    Buffer[cbCharsRead] = (char)0;
    /* note that FinishConnection function not only closes the socket but also terminates the this thread thus
       there us no need to get out of the loop and return from this function */
    if( ThisThread->pFunctions->FtpProc(ThisThread->pHT,ThisThread,Buffer) )FinishConnection(ThisThread);
    }
  }
Beispiel #4
0
bool
XInterface::Connect()
{
	dprintf(D_FULLDEBUG, "XInterface::Connect\n");


	// First try as whatever user we entered as, with whatever
	// X credentials we were born with.

	dprintf(D_FULLDEBUG, "Trying to XOpenDisplay\n");
	if ((_display = XOpenDisplay(_display_name))) {
		FinishConnection();
		return true;
	}

	// Ok, that didn't work, try as condor
	set_condor_priv();

	dprintf(D_FULLDEBUG, "Trying to XOpenDisplay as condor\n");
	if ((_display = XOpenDisplay(_display_name))) {
		FinishConnection();
		return true;
	}

	// Time for the big guns, try as root
	set_root_priv();

	dprintf(D_FULLDEBUG, "Trying to XOpenDisplay as root\n");
	if ((_display = XOpenDisplay(_display_name))) {
		FinishConnection();
		return true;
	}

	set_condor_priv();

	
	// If we get here, let's try as each logged in user
	// If this X server is using MIT-MAGIC_COOKIE, set
	// XAUTHORITY to point within the user's home directory.

	ReadUtmp();

	int utmpIndex = 0;
	while (utmpIndex <= logged_on_users->getlast()) {

		const char *username = (*logged_on_users)[utmpIndex];

		dprintf(D_FULLDEBUG, "Trying to XOpenDisplay as user %s\n", username);
		bool switched = TryUser(username); // set_priv's and setenv's

		if (switched) {
			_display = XOpenDisplay(_display_name);		

			if (_display) {
				FinishConnection();
				return true;
			}

		}
		set_condor_priv();
		utmpIndex++;
	}

	dprintf(D_FULLDEBUG, "Exausted all possible attempts to "
		"connect to X server, will try again in 60 seconds.\n");
	daemonCore->Reset_Timer( _daemon_core_timer, 60 ,60 );
	dprintf(D_FULLDEBUG, "Reset timer: %d\n", _daemon_core_timer);

	g_connected = false;
	return false;
}
Beispiel #5
0
/*FUNCTION*/
void HandleHttpHit(pThreadData ThisThread
  ){
  pServerData ThisServer;
  int j,i,cbBuffer,cbCharsRead,cbCharsReadTotal;
  char *Buffer;
  char *s;
  void MyHttpExtensionProc(pThreadData);
  fd_set readfds;
  struct timeval timeout;
  pHttpdThread pHT;

  Buffer = ThisThread->buffer;
  cbBuffer = HIT_MAX_SIZE;

  /* pointer to the server data that this thread belongs to */
  pHT = ThisThread->pHT;
  ThisServer = pHT->server + ThisThread->server_index;
  
  cbCharsReadTotal = 0;
  while(1){
    FD_ZERO(&readfds);
    FD_SET(ThisThread->msgsock,&readfds);
    timeout.tv_sec=60;
    timeout.tv_usec=0;
    i = select(FD_SETSIZE,&readfds,NULL,NULL,&timeout);
    if( i == 0 )FinishConnection(ThisThread);
    cbCharsRead = recv(ThisThread->msgsock,Buffer,cbBuffer,0);
    /* some clients send such packets, but I could not figure out how */
    if( cbCharsRead == 0 )FinishConnection(ThisThread);
    if( cbCharsRead < 0 )FinishConnection(ThisThread);

    /* If this is the first chunk read then we are searching for the header terminating
       empty line from the first character. If this is not the first chunk then we start the
       search from the end of the previous chunk. */
    if( cbCharsReadTotal < 3 )j = 4 - cbCharsReadTotal; else j = 1;

    cbCharsReadTotal += cbCharsRead;

    /* if we have found the empty line following the header */
    for( ; j <= cbCharsRead ; j++ ){
      if( Buffer[j-1] == '\n' && Buffer[j-2] == '\r' &&
          Buffer[j-3] == '\n' && Buffer[j-4] == '\r' ){
        Buffer[j-4] = (char)0;
        ThisThread->pszData = Buffer+j;
        ThisThread->cbAvailable = cbCharsRead - j;
        goto HEADER_IS_READ;
        }
      }
    cbBuffer -= i;
    Buffer += i;
    if( cbBuffer <= 0 )FinishConnection(ThisThread);
    }
HEADER_IS_READ:;

  /* Here we have the total HTTP GET header. */
  s = ThisThread->pszMethod = ThisThread->buffer;
  while( *s && ! isspace(*s) )s++;
  if( *s )
    *s++ = (char)0;
  else FinishConnection(ThisThread);

  ThisThread->pszQueryString = s;
  while( *s && ! isspace(*s) )s++;
  if( *s )
    *s++ = (char)0;
  else FinishConnection(ThisThread);

  /* if there is anything after the URL until the new line then skip it */
  while( *s && *s != '\n' )s++;
  /* skip the CR/LF */
  while( *s == '\n' || *s == '\r' )s++;

  ThisThread->iHeaderLines = 0;
  /* now s points to the start of the first header line */
  while( *s ){

    ThisThread->HeaderKey[ThisThread->iHeaderLines] = s;
    while( *s && ! isspace(*s) && *s != ':' )s++;
    if( *s )*s++ = (char)0;
    while( isspace(*s) )s++;
    if( *s ){
      ThisThread->HeaderString[ThisThread->iHeaderLines] = s;
      while( *s && *s != '\n' && *s != '\r' )s++;
      if( *s )*s++ = (char)0;
      while( *s == '\n' || *s == '\r' )s++;
      ThisThread->iHeaderLines++;
      }
    }

  ThisThread->getparams[0] = (char)0;
  ThisThread->script[0] = (char)0;
  ThisThread->pThreadLocalData = NULL;

  ThisThread->pFunctions->HttpProc(ThisThread->pHT,ThisThread);

  FinishConnection(ThisThread);
  }