| version 1.19, 2004/09/17 08:46:10 |
version 1.24, 2006/06/05 00:25:50 |
|
|
| /* $OpenXM: OpenXM/src/kxx/oxmain.c,v 1.18 2004/09/17 07:27:28 takayama Exp $ */ |
/* $OpenXM: OpenXM/src/kxx/oxmain.c,v 1.23 2006/02/25 09:11:10 takayama Exp $ */ |
| /* nullserver01 */ |
/* nullserver01 */ |
| #include <stdio.h> |
#include <stdio.h> |
| #include <fcntl.h> |
#include <fcntl.h> |
|
|
| #include <sys/types.h> |
#include <sys/types.h> |
| #include <sys/socket.h> |
#include <sys/socket.h> |
| #include <sys/time.h> |
#include <sys/time.h> |
| |
#include <sys/resource.h> |
| #include <netinet/in.h> |
#include <netinet/in.h> |
| #include <netdb.h> |
#include <netdb.h> |
| #include <signal.h> |
#include <signal.h> |
|
|
| int LocalMode = 1; |
int LocalMode = 1; |
| int NotifyPortnumber = 0; |
int NotifyPortnumber = 0; |
| int Do_not_use_control_stream_to_tell_no_server = 1; |
int Do_not_use_control_stream_to_tell_no_server = 1; |
| |
int IgnoreSIGINT = 1; |
| static void errorToStartEngine(void); |
static void errorToStartEngine(void); |
| static int findOxServer(char *server); |
static int findOxServer(char *server); |
| static void couldNotFind(char *s); |
static void couldNotFind(char *s); |
| /* gcc -v -c hoge.c */ |
/* gcc -v -c hoge.c */ |
| |
static void mywait(); |
| |
|
| void *sGC_malloc(int n) { |
void *sGC_malloc(int n) { |
| return (void *)malloc(n); |
return (void *)malloc(n); |
| Line 59 main(int argc, char *argv[]) { |
|
| Line 62 main(int argc, char *argv[]) { |
|
| char *passData = NULL; |
char *passData = NULL; |
| int result; |
int result; |
| int sleepingTime = 0; |
int sleepingTime = 0; |
| |
int authEncoding=0; |
| |
FILE *fp; |
| |
char *stmp; |
| extern int OxTerminateMode; |
extern int OxTerminateMode; |
| |
|
| signal(SIGHUP,SIG_IGN); /* ignore x of xterm */ |
signal(SIGHUP,SIG_IGN); /* ignore x of xterm */ |
| Line 118 main(int argc, char *argv[]) { |
|
| Line 124 main(int argc, char *argv[]) { |
|
| if (i<argc) { |
if (i<argc) { |
| sscanf(argv[i],"%d",&sleepingTime); |
sscanf(argv[i],"%d",&sleepingTime); |
| } |
} |
| |
}else if (strcmp(argv[i],"-authEncoding") == 0) { |
| |
i++; |
| |
if (strcmp(argv[i],"file") == 0) { |
| |
authEncoding = 1; |
| |
}else{ |
| |
fprintf(stderr,"Unknown -authEncoding %s.\n",argv[i]); |
| |
oxmainUsage(); exit(10); |
| |
} |
| |
}else if (strcmp(argv[i],"-ignoreSIGINT") == 0) { |
| |
i++; |
| |
if (i<argc) { |
| |
IgnoreSIGINT = argv[i]; |
| |
} |
| }else { |
}else { |
| fprintf(stderr,"Unknown option %s.\n",argv[i]); |
fprintf(stderr,"Unknown option %s.\n",argv[i]); |
| oxmainUsage(); exit(10); |
oxmainUsage(); exit(10); |
| Line 147 main(int argc, char *argv[]) { |
|
| Line 166 main(int argc, char *argv[]) { |
|
| } |
} |
| |
|
| /* Decrypt passControl and passData, here. Lookup cryptmethod. */ |
/* Decrypt passControl and passData, here. Lookup cryptmethod. */ |
| |
if (authEncoding == 1) { |
| |
stmp = (char *)sGC_malloc(strlen(getenv("HOME"))+strlen(passControl)+ |
| |
strlen(passData)+128); |
| |
sprintf(stmp,"%s/.openxm/tmp.opt/%s",(char *)getenv("HOME"),passControl); |
| |
fp = fopen(stmp,"r"); |
| |
if (fp == NULL) { fprintf(stderr,"passControl file %s is not found.\n",stmp); exit(1);} |
| |
fgets(stmp,127,fp); passControl = stmp; fclose(fp); |
| |
|
| |
stmp = (char *)sGC_malloc(strlen(getenv("HOME"))+strlen(passControl)+ |
| |
strlen(passData)+128); |
| |
sprintf(stmp,"%s/.openxm/tmp.opt/%s",(char *)getenv("HOME"),passData); |
| |
fp = fopen(stmp,"r"); |
| |
if (fp == NULL) { fprintf(stderr,"passData file %s is not found.\n",stmp); exit(1);} |
| |
fgets(stmp,127,fp); passData = stmp; fclose(fp); |
| |
} |
| |
|
| if (reverse) { |
if (reverse) { |
| /* The order is very important. */ |
/* The order is very important. */ |
| fdControl = socketConnectWithPass(sname,portControl,passControl); |
fdControl = socketConnectWithPass(sname,portControl,passControl); |
| Line 157 main(int argc, char *argv[]) { |
|
| Line 191 main(int argc, char *argv[]) { |
|
| result = 0; |
result = 0; |
| |
|
| |
|
| |
if ((fdControl < 0) || (fdStream < 0)) { |
| |
fprintf(stderr,"Waiting for 10 seconds to show an error.\n"); |
| |
sleep(10); |
| |
} |
| |
|
| if (portControl != -1) { |
if (portControl != -1) { |
| MyServerPid = fork(); |
MyServerPid = fork(); |
| if (MyServerPid > 0 ) parentServerMain(fdControl,fdStream); |
if (MyServerPid > 0 ) parentServerMain(fdControl,fdStream); |
| Line 249 main(int argc, char *argv[]) { |
|
| Line 288 main(int argc, char *argv[]) { |
|
| free(s); |
free(s); |
| } |
} |
| |
|
| |
if ((fdControl < 0) || (fdStream < 0)) { |
| |
fprintf(stderr,"Waiting for 10 seconds to show an error.\n"); |
| |
sleep(10); |
| |
} |
| |
|
| |
|
| result = 0; |
result = 0; |
| if (portControl != -1) { |
if (portControl != -1) { |
| MyServerPid = fork(); |
MyServerPid = fork(); |
| Line 269 static void errorToStartEngine(void) { |
|
| Line 314 static void errorToStartEngine(void) { |
|
| If you implement this, set Do_not_use_control_stream_to_tell_no_server to |
If you implement this, set Do_not_use_control_stream_to_tell_no_server to |
| zero. |
zero. |
| */ |
*/ |
| sleep(2); |
sleep(10); |
| exit(-1); |
exit(-1); |
| } |
} |
| |
|
|
|
| fprintf(stderr,"Usage: \n"); |
fprintf(stderr,"Usage: \n"); |
| fprintf(stderr," ox [-ox serverprogram -host name -data portnum -control portnum -monitor]\n"); |
fprintf(stderr," ox [-ox serverprogram -host name -data portnum -control portnum -monitor]\n"); |
| fprintf(stderr," [-insecure -portfile fname -reverse -passControl xxxyyyzzz -passData pppqqqrrr]"); |
fprintf(stderr," [-insecure -portfile fname -reverse -passControl xxxyyyzzz -passData pppqqqrrr]"); |
| fprintf(stderr," [-finish]"); |
fprintf(stderr," [-finish] [-wait seconds] [-authEncoding [file]]"); |
| |
fprintf(stderr," [-ignoreSIGINT [1|0]]"); |
| fprintf(stderr,"\n"); |
fprintf(stderr,"\n"); |
| fprintf(stderr,"-reverse: ox server connects to the client.\n"); |
fprintf(stderr,"-reverse: ox server connects to the client.\n"); |
| fprintf(stderr," The client must give a one time password to ox server to connect to the client with -pass* option.\n"); |
fprintf(stderr," The client must give a one time password to ox server to connect to the client with -pass* option.\n"); |
| Line 315 parentServerMain(int fdControl, int fdStream) { |
|
| Line 361 parentServerMain(int fdControl, int fdStream) { |
|
| extern OxTerminateMode; |
extern OxTerminateMode; |
| extern void myServerExit(); |
extern void myServerExit(); |
| |
|
| |
signal(SIGCHLD,mywait); |
| if (OxTerminateMode) { |
if (OxTerminateMode) { |
| /* |
/* |
| OxTerminateMode cannot be used if you run ox by xterm -exec ox ... |
OxTerminateMode cannot be used if you run ox by xterm -exec ox ... |
| Line 370 void myServerExit() { |
|
| Line 417 void myServerExit() { |
|
| |
|
| childServerMain(int fdControl, int fdStream) { |
childServerMain(int fdControl, int fdStream) { |
| int i; |
int i; |
| |
struct rlimit res; |
| close(fdControl); /* close(0); dup(fdStream); */ |
close(fdControl); /* close(0); dup(fdStream); */ |
| dup2(fdStream,3); |
dup2(fdStream,3); |
| dup2(fdStream,4); |
dup2(fdStream,4); |
| Line 409 childServerMain(int fdControl, int fdStream) { |
|
| Line 457 childServerMain(int fdControl, int fdStream) { |
|
| putenv(s); |
putenv(s); |
| } |
} |
| } |
} |
| |
getrlimit(RLIMIT_STACK,&res); |
| |
if (res.rlim_cur < 65536000) { |
| |
fprintf(stderr,"RLIMIT_STACK is increased to 65Mbytes by setrlimit.\n"); |
| |
res.rlim_cur = 65536000; |
| |
setrlimit(RLIMIT_STACK,&res); |
| |
} |
| |
|
| |
if (IgnoreSIGINT) signal(SIGINT, SIG_IGN); |
| |
|
| if (PacketMonitor) { |
if (PacketMonitor) { |
| if (execle(ServerName,ServerName,"-monitor",NULL,environ)) { |
if (execle(ServerName,ServerName,"-monitor",NULL,environ)) { |
| fprintf(stderr,"%s cannot be executed with -monitor.\n",ServerName); |
fprintf(stderr,"%s cannot be executed with -monitor.\n",ServerName); |
| Line 471 static void couldNotFind(char *s) { |
|
| Line 527 static void couldNotFind(char *s) { |
|
| } |
} |
| |
|
| |
|
| |
static void mywait() { |
| |
int status; |
| |
int pid; |
| |
int i,j; |
| |
/* signal(SIGCHLD,SIG_IGN); */ |
| |
pid = wait(&status); |
| |
fprintf(stderr,"Control: child process %d is exiting.\n",pid); |
| |
fprintf(stderr,"Control: Shutting down the control server.\n"); |
| |
sleep(2); |
| |
exit(0); |
| |
} |
| |
|
| |
|