static void APISession( TermNode *term) { SessionData *data; APIData *api; char ld[SIZE_NAME+1]; char window[SIZE_NAME+1]; char user[SIZE_USER+1]; char host[SIZE_HOST+1]; data = NULL; RecvnString(term->fp, sizeof(ld), ld); ON_IO_ERROR(term->fp,badio); RecvnString(term->fp, sizeof(window), window); ON_IO_ERROR(term->fp,badio); RecvnString(term->fp, sizeof(user), user); ON_IO_ERROR(term->fp,badio); RecvnString(term->fp, sizeof(host), host); ON_IO_ERROR(term->fp,badio); data = InitAPISession(user,ld,window,host); if (data != NULL) { data->term = term; data->retry = 0; api = data->apidata; RecvLBS(term->fp, api->rec); data = Process(data); api = data->apidata; SendPacketClass(term->fp, api->status); ON_IO_ERROR(term->fp,badio2); if (api->status == WFC_API_OK) { SendLBS(term->fp, api->rec); ON_IO_ERROR(term->fp,badio2); } CloseNet(term->fp); badio2: FreeSessionData(data); } else { SendPacketClass(term->fp,WFC_API_NOT_FOUND); ON_IO_ERROR(term->fp,badio2); CloseNet(term->fp); } badio: ; }
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; }
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); }
extern ValueStruct *SYSDATA_DBDISCONNECT(DBG_Struct *dbg, DBCOMM_CTRL *ctrl) { if (dbg->dbstatus == DB_STATUS_CONNECT) { SendPacketClass(NBCONN(dbg), SYSDATA_END); CloseNet(NBCONN(dbg)); CloseDB_RedirectPort(dbg); dbg->dbstatus = DB_STATUS_DISCONNECT; if (ctrl != NULL) { ctrl->rc = MCP_OK; } } return (NULL); }
extern void RecvnString(NETFILE *fp, size_t size, char *str) { size_t lsize; lsize = RecvLength(fp); if (size >= lsize) { size = lsize; Recv(fp, str, size); str[size] = 0; } else { CloseNet(fp); Message("error size mismatch !"); } }
void SessionLink( ScreenData *scr) { NETFILE *fp; ENTER_FUNC; fp = OpenPanda(scr); if (fp != NULL) { scr->status = SCREEN_DATA_CONNECT; RecvPanda(scr,fp); CloseNet(fp); } else { scr->status = SCREEN_DATA_NULL; } LEAVE_FUNC; }
static void TermSession( TermNode *term) { SessionData *data; char buff[SIZE_TERM+1]; RecvnString(term->fp,SIZE_TERM,buff); data = CheckSession(term->fp,buff); if (data != NULL) { data = ReadTerminal(term->fp,data); data->term = term; data->retry = 0; TermMain(term,data); } CloseNet(term->fp); }
static void MainProc(char *comm) { NETFILE *fp; if ((fp = OpenPort(ControlPort, 0)) != NULL) { if (Auth(fp)) { if (stricmp(comm, "stop") == 0) { SendPacketClass(fp, WFCCONTROL_STOP); } else { printf("command error\n"); } } else { printf("auth fail\n"); } CloseNet(fp); } else { fprintf(stderr, "invalid control port\n"); } }
extern void CloseDB_RedirectPort( DBG_Struct *dbg) { ENTER_FUNC; if ( dbg->redirect == NULL ) return; if ( dbg->fpLog != NULL ) { SendPacketClass(dbg->fpLog,RED_END); CloseNet(dbg->fpLog); dbg->fpLog = NULL; } if ( dbg->redirectData != NULL ) { FreeLBS(dbg->redirectData); dbg->redirectData = NULL; } LEAVE_FUNC; }
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); }
static void DisconnectBlobAPI(NETFILE *fp) { if (fp != NULL && CheckNetFile(fp)) { CloseNet(fp); } }
static void TermInit( TermNode *term) { SessionData *data; LD_Node *ld; int i; uuid_t u; ENTER_FUNC; data = NewSessionData(); data->term = term; data->fInProcess = TRUE; uuid_generate(u); uuid_unparse(u,data->hdr->uuid); if ((ld = g_hash_table_lookup(APS_Hash,ThisEnv->InitialLD)) == NULL) { Error("cannot find initial ld:%s.check directory",ThisEnv->InitialLD); } RecvnString(term->fp,SIZE_NAME,data->hdr->user);ON_IO_ERROR(term->fp,badio); RecvnString(term->fp,SIZE_HOST,data->host); ON_IO_ERROR(term->fp,badio); RecvnString(term->fp,SIZE_NAME,data->agent);ON_IO_ERROR(term->fp,badio); MessageLogPrintf("[%s:%s] session start",data->hdr->user,data->hdr->uuid); dbgprintf("uuid = [%s]",data->hdr->uuid); dbgprintf("user = [%s]",data->hdr->user); dbgprintf("host = [%s]",data->host); dbgprintf("agent = [%s]",data->agent); if (SesNum != 0 && GetSessionNum() >= SesNum) { Warning("Discard new session(%s);max session number(%d)",term,SesNum); SendPacketClass(term->fp,WFC_NOT); CloseNet(term->fp); return; } SendPacketClass(term->fp,WFC_OK); ON_IO_ERROR(term->fp,badio); SendString(term->fp,data->hdr->uuid); ON_IO_ERROR(term->fp,badio); data->ld = ld; data->linkdata = NewLinkData(); data->cWindow = ld->info->cWindow; data->scrdata = (LargeByteString **)xmalloc(sizeof(void*)*data->cWindow); for (i = 0 ; i < data->cWindow ; i ++) { if (data->ld->info->windows[i] != NULL) { dbgprintf("[%s]",data->ld->info->windows[i]->name); data->scrdata[i] = GetScreenData(data,data->ld->info->windows[i]->name); } else { data->scrdata[i] = NULL; } } data->hdr->puttype = SCREEN_NULL; RegisterSession(data); TermMain(term,data); CloseNet(term->fp); badio: LEAVE_FUNC; return; }
static int _StartBatch(MessageHandler *handler, char *name, char *param) { int pid; int pDBR[2], pDBW[2]; char line[SIZE_BUFF], **cmd; int rc; int pAPR[2], pAPW[2]; if (handler->loadpath == NULL) { handler->loadpath = ExecPath; } signal(SIGPIPE, SignalHandler); if (LibPath == NULL) { ExecPath = getenv("APS_EXEC_PATH"); } else { ExecPath = LibPath; } if (pipe(pAPR) != 0) { perror("pipe"); exit(1); } if (pipe(pAPW) != 0) { perror("pipe"); exit(1); } if (pipe(pDBR) != 0) { perror("pipe"); exit(1); } if (pipe(pDBW) != 0) { perror("pipe"); exit(1); } ExpandStart(line, handler->start, handler->loadpath, name, param); cmd = ParCommandLine(line); if (setjmp(SubError) == 0) { if ((pid = fork()) == 0) { dup2(pAPW[0], STDIN_FILENO); dup2(pAPR[1], STDOUT_FILENO); close(pAPW[0]); close(pAPW[1]); close(pAPR[0]); close(pAPR[1]); dup2(pDBW[0], DBIN_FILENO); dup2(pDBR[1], DBOUT_FILENO); close(pDBW[0]); close(pDBW[1]); close(pDBR[0]); close(pDBR[1]); execv(cmd[0], cmd); } else { close(pAPR[1]); close(pAPW[0]); fpDBR = FileToNet(pDBR[0]); close(pDBR[1]); fpDBW = FileToNet(pDBW[1]); close(pDBW[0]); StartDB(handler); } (void)wait(&pid); CancelDB(); CloseNet(fpDBW); CloseNet(fpDBR); rc = TRUE; } else { rc = FALSE; } return (rc); }
static Bool _ExecuteProcess(MessageHandler *handler, ProcessNode *node) { char *module; int pid; int pAPR[2], pAPW[2], pDBR[2], pDBW[2]; Bool rc; NETFILE *fpAPR, *fpAPW; char line[SIZE_BUFF], **cmd; if (handler->loadpath == NULL) { handler->loadpath = ExecPath; } signal(SIGPIPE, SignalHandler); module = ValueStringPointer(GetItemLongName(node->mcprec->value, "dc.module")); ExpandStart(line, handler->start, handler->loadpath, module, ""); cmd = ParCommandLine(line); if (pipe(pAPR) != 0) { perror("pipe"); exit(1); } if (pipe(pAPW) != 0) { perror("pipe"); exit(1); } if (pipe(pDBR) != 0) { perror("pipe"); exit(1); } if (pipe(pDBW) != 0) { perror("pipe"); exit(1); } if (setjmp(SubError) == 0) { if ((pid = fork()) == 0) { dup2(pAPW[0], STDIN_FILENO); dup2(pAPR[1], STDOUT_FILENO); close(pAPW[0]); close(pAPW[1]); close(pAPR[0]); close(pAPR[1]); dup2(pDBW[0], DBIN_FILENO); dup2(pDBR[1], DBOUT_FILENO); close(pDBW[0]); close(pDBW[1]); close(pDBR[0]); close(pDBR[1]); execv(cmd[0], cmd); } else { fpAPR = FileToNet(pAPR[0]); close(pAPR[1]); fpAPW = FileToNet(pAPW[1]); close(pAPW[0]); fpDBR = FileToNet(pDBR[0]); close(pDBR[1]); fpDBW = FileToNet(pDBW[1]); close(pDBW[0]); StartDB(handler); PutApplication(handler, fpAPW, node); GetApplication(handler, fpAPR, node); (void)wait(&pid); CancelDB(); signal(SIGPIPE, SIG_DFL); CloseNet(fpAPW); CloseNet(fpAPR); CloseNet(fpDBW); CloseNet(fpDBR); } rc = TRUE; } else { rc = FALSE; } return (rc); }
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); }