示例#1
0
extern	void
OpenDB_RedirectPort(
	DBG_Struct	*dbg)
{
	int		fh;
	DBG_Struct	*rdbg;

ENTER_FUNC;
	dbgprintf("dbg [%s]\n",dbg->name);
	if		(	(  fNoRedirect  )
			||	(  dbg->redirect  ==  NULL  ) ) {
		dbg->fpLog = NULL;
		dbg->redirectData = NULL;
	} else {
		rdbg = dbg->redirect;
		if		( ( rdbg->redirectPort  ==  NULL )
		 || (( fh = ConnectSocket(rdbg->redirectPort,SOCK_STREAM) )  <  0 ) ) {
			dbgmsg("loging server not ready");
			dbg->fpLog = NULL;
			dbg->redirectData = NULL;
			if ( !fNoCheck ){
				ChangeDBStatus_Redirect(dbg, DB_STATUS_REDFAILURE);
			}
		} else {
			dbg->fpLog = SocketToNet(fh);
			dbg->redirectData = NewLBS();
			if ( !RecvSTATUS_Redirect(dbg) ){
				CloseDB_RedirectPort(dbg);
			}
		}
	}
LEAVE_FUNC;
}
示例#2
0
void
SessionMain(
	ScreenData 	*scr)
{
	Port	*port;
	int		fd;
	NETFILE	*fp;

ENTER_FUNC;
	port = ParPort(TermPort,PORT_WFC);
	fd = ConnectSocket(port,SOCK_STREAM);
	DestroyPort(port);
	if ( fd > 0 ){
		fp = SocketToNet(fd);
		if (SendPanda(scr,fp)) {
			RecvPanda(scr,fp);
			CloseNet(fp);
		} else {
			scr->status = SCREEN_DATA_END;
		}
	} else {
		scr->status = SCREEN_DATA_END;
	}
LEAVE_FUNC;
}
示例#3
0
文件: message.c 项目: montsuqi/panda
extern void InitMessage(char *id, char *fn) {
  char *tempformat, *tempfn;
#ifdef USE_MSGD
  int fd;
  Port *port;
#endif

#ifdef USE_SYSLOG
  static char buff[SIZE_LOG];

  snprintf(buff, SIZE_LOG, "%s/%s", PACKAGE, id);
  openlog(buff, LOG_PID, syslog_facility);
#endif

  if (fn == NULL) {
    tempfn = getenv("LOG_FILE_NAME");
    if (tempfn != NULL) {
      fn = StrDup(tempfn);
    }
  }
  fpLog = NULL;
  Processid = StrDup(id);
  tempformat = getenv("LOG_DATA_FORMAT");
  if (tempformat != NULL) {
    Format = StrDup(tempformat);
  }
#ifdef USE_MSGD
  if (fn != NULL) {
    if (*fn == '@') {
      port = ParPort(fn + 1, PORT_MSGD);
      if ((fd = ConnectSocket(port, SOCK_STREAM)) >= 0) {
        fpLog = SocketToNet(fd);
        if (Format == NULL) {
          Format = "%F:%i:%f:%L:%B";
        }
      }
      DestroyPort(port);
    } else {
      if ((fd = open(fn, O_WRONLY | O_CREAT | O_TRUNC, 0600)) >= 0) {
        fpLog = FileToNet(fd);
      }
    }
  }
  if (fpLog == NULL) {
    if (Format == NULL) {
      Format = "%Y/%M/%D/%h:%m:%s %F:%f:%L:%B";
    }
    fpLog = FileToNet(STDOUT_FILENO);
  }
#else
  if ((fn == NULL) || ((fpLog = fopen(fn, "w+")) == NULL)) {
    fpLog = stdout;
  }
#endif
  if (Format == NULL) {
    Format = "%Y/%M/%D/%h:%m:%s %F:%f:%L:%B";
  }
  MessageFunction = __Message;
}
示例#4
0
extern	Bool
AuthUser(
	URL		*auth,
	char	*user,
	char	*pass,
	char	*other,
	char	*id)
{
	struct	timeval	tv;
	int		fh;
	NETFILE	*fp;
	Bool	rc;
	char	buff[SIZE_OTHER+1];

ENTER_FUNC;
	rc = FALSE;
	if		(  strcmp(auth->protocol,"trust")  ==  0  ) {
		rc = TRUE;
	} else {
		if		(user == NULL || pass == NULL) {
			return FALSE;
		}
		if		(  !stricmp(auth->protocol,"glauth")  ) {
			fh = ConnectIP_Socket(auth->port,SOCK_STREAM,auth->host);
			if	( fh > 0) {
				fp = SocketToNet(fh);
				SendString(fp,user);
				SendString(fp,pass);
				if		(  ( rc = RecvBool(fp) )  ) {
					/* for protocol interchangebility; 'other' is not using*/
					RecvnString(fp, sizeof(buff), buff);
				}
				CloseNet(fp);
			} else{
				Warning("can not connect glauth server");
				rc = FALSE;
			}
		} else if (!stricmp(auth->protocol,"api")) {
			rc = AuthAPI(user,pass,other,id);
		} else if (!stricmp(auth->protocol,"file")) {
			rc = AuthSingle(auth->file,user,pass,NULL);
		} else {
			rc = FALSE;
		}
	}

	if		(  id  !=  NULL  ) {
		if		(  rc  ) {
			gettimeofday(&tv, (struct timezone *) 0);
			strcpy(id,crypt(user,l64a(tv.tv_sec + getpid() + clock())));
		} else {
			*id = 0;
		}
	}
LEAVE_FUNC;
	return	(rc);
}
示例#5
0
static NETFILE *ConnectBlobAPI(char *socketfile) {
  NETFILE *fp;
  Port *port;
  int fd;

  fp = NULL;
  port = ParPort(socketfile, NULL);
  fd = ConnectSocket(port, SOCK_STREAM);
  DestroyPort(port);
  if (fd > 0) {
    fp = SocketToNet(fd);
  } else {
    Error("cannot connect blob api");
  }
  return fp;
}
示例#6
0
文件: msgd.c 项目: montsuqi/panda
static void LogThread(void *para) {
  int fhLog = (int)(long)para;
  NETFILE *fpLog;
  char buff[SIZE_BUFF + 1];
  Bool fOK;
  char *str;

  fpLog = SocketToNet(fhLog);
  do {
    if ((fOK = RecvStringDelim(fpLog, SIZE_BUFF, buff))) {
      str = StrDup(buff);
      EnQueue(FileQueue, str);
    }
    if (!CheckNetFile(fpLog))
      break;
  } while (fOK);
  CloseNet(fpLog);
}
示例#7
0
文件: net.c 项目: authorNari/panda
extern	NETFILE	*
OpenPort(
	char	*url,
	char	*defport)
{
	int		fd;
	Port	*port;
	NETFILE	*fp;

	port = ParPort(url,defport);
	if		(  ( fd = ConnectSocket(port,SOCK_STREAM) )  >  0  ) {
		fp = SocketToNet(fd);
	} else {
		fp = NULL;
	}
	DestroyPort(port);
	return	(fp);
}
示例#8
0
void
SessionExit(
	ScreenData 	*scr)
{
	Port	*port;
	int		fd;
	NETFILE	*fp;

ENTER_FUNC;
	port = ParPort(TermPort,PORT_WFC);
	fd = ConnectSocket(port,SOCK_STREAM);
	DestroyPort(port);
	if ( fd > 0 ){
		fp = SocketToNet(fd);
		SendTermServerEnd(fp,scr);
	} else {
		scr->status = SCREEN_DATA_NULL;
	}
LEAVE_FUNC;
}
示例#9
0
文件: sysdata.c 项目: montsuqi/panda
extern ValueStruct *SYSDATA_DBOPEN(DBG_Struct *dbg, DBCOMM_CTRL *ctrl) {
  int fh, rc;
  NETFILE *fp;

  fp = NULL;
  rc = MCP_BAD_OTHER;
  if (ThisEnv->sysdata != NULL && ThisEnv->sysdata->port != NULL &&
      (fh = ConnectSocket(ThisEnv->sysdata->port, SOCK_STREAM)) >= 0) {
    fp = SocketToNet(fh);
  }
  OpenDB_RedirectPort(dbg);
  dbg->conn = (void *)fp;
  if (fp != NULL) {
    dbg->dbstatus = DB_STATUS_CONNECT;
    rc = MCP_OK;
  }
  if (ctrl != NULL) {
    ctrl->rc = rc;
  }
  return (NULL);
}
示例#10
0
extern	int
ConnectTerm(
	int		_fhTerm)
{
	int				fhTerm;
	pthread_t		thr;
	pthread_attr_t	attr;
	TermNode		*term;

ENTER_FUNC;
	pthread_attr_init(&attr);
	pthread_attr_setstacksize(&attr,256*1024);
	if ((fhTerm = accept(_fhTerm,0,0)) < 0) {
		Error("accept(2) failure:%s",strerror(errno));
	}
	term = New(TermNode);
	term->que = NewQueue();
	term->fp = SocketToNet(fhTerm);
	pthread_create(&thr,&attr,(void *(*)(void *))TermThread,(void *)term);
	pthread_detach(thr);
LEAVE_FUNC;
	return	(fhTerm); 
}
示例#11
0
文件: glserver.c 项目: montsuqi/panda
static void ExecuteServer(void) {
  int pid;
  int fd;
  int soc_len;
  int soc[MAX_SOCKET];

  NETFILE *fpComm;
  Port *port;
#ifdef USE_SSL
  SSL_CTX *ctx;
  char *ssl_warning;
#endif
  port = ParPortName(PortNumber);
  soc_len = InitServerMultiPort(port, Back, soc);
#ifdef USE_SSL
  ctx = NULL;
  if (fSsl) {
    ctx = MakeSSL_CTX(KeyFile, CertFile, CA_File, CA_Path, Ciphers);
    if (ctx == NULL) {
      Warning(GetSSLErrorMessage());
      Error("CTX make error");
    }
    if (!fVerifyPeer) {
      SSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, NULL);
    }
    ssl_warning = GetSSLWarningMessage();
    if (strlen(ssl_warning) > 0) {
      Warning(ssl_warning);
    }
  }
#endif
  while (TRUE) {
    if ((fd = AcceptLoop(soc, soc_len)) < 0) {
      continue;
    }
    if ((pid = fork()) > 0) { /*	parent	*/
      close(fd);
    } else if (pid == 0) { /*	child	*/
#ifdef USE_SSL
      if (fSsl) {
        fpComm = MakeSSL_Net(ctx, fd);
        if (StartSSLServerSession(fpComm) != TRUE) {
          CloseNet(fpComm);
          Warning(GetSSLErrorMessage());
          exit(0);
        }
      } else {
        fpComm = SocketToNet(fd);
      }
#else
      fpComm = SocketToNet(fd);
#endif
      alarm(API_TIMEOUT_SEC);
      HTTP_Method(fpComm);
// FIXME avoid segv gl protocol timeout
#if 0
			CloseNet(fpComm);
#endif
      exit(0);
    }
  }
  DestroyPort(port);
}