int main(int argc, char *argv[]) { struct starter_config *cfg = NULL; struct starter_conn *new_conn = NULL; err_t perr = NULL; FILE *file = NULL; char *cPath = "./test.cfg"; //Connection *conn = [[[ConnectionsDB sharedInstance] connDB] objectAtIndex:[selConn indexOfSelectedItem]]; //file pathname /* NSString *origFileName = [conn connName]; NSString *fileName = [origFileName stringByAppendingFormat:@".conf"]; NSString *origPath = @"~/Library/Application Support/Openswan"; NSString *filePath = [origPath stringByAppendingPathComponent:fileName]; NSString *path = [filePath stringByStandardizingPath]; char cPath[100]; [path getCString:cPath maxLength:100 encoding:NSMacOSRomanStringEncoding]; */ cfg = (struct starter_config *) malloc(sizeof(struct starter_config)); if (!cfg) printf("can't allocate memory"); memset(cfg, 0, sizeof(struct starter_config)); ipsecconf_default_values(cfg); //NSString to char* //char cConnName[20]; //[[conn connName] getCString:cConnName maxLength:20 encoding:NSMacOSRomanStringEncoding]; new_conn = alloc_add_conn(cfg, "test", &perr); if(new_conn == NULL) printf("%s", perr); cfg->setup.options_set[KBF_NATTRAVERSAL] = 1; cfg->setup.options[KBF_NATTRAVERSAL] = 0; cfg->setup.strings_set[KSF_PROTOSTACK] = 1; cfg->setup.strings[KSF_PROTOSTACK] = strdup("netkey"); new_conn->connalias = strdup("anotheralias"); new_conn->left.rsakey2 = (unsigned char *)"0s23489234ba28934243"; new_conn->left.rsakey1 = (unsigned char *)"0sabcdabcdabcd"; new_conn->desired_state = STARTUP_START; new_conn->options_set[KBF_AUTO] = 1; new_conn->options[KBF_AUTO] = STARTUP_START; new_conn->left.cert = "/my/cert/file"; file = fopen(cPath,"w"); confwrite(cfg, file); fclose(file); return 0; }
int main(int argc, char *argv[]) { int opt = 0; struct starter_config *cfg = NULL; err_t err = NULL; char *confdir = NULL; char *configfile = NULL; struct starter_conn *conn = NULL; progname = argv[0]; tool_init_log(); starter_use_log(verbose, 1, verbose ? 0 : 1); cfg = (struct starter_config *)malloc(sizeof(struct starter_config)); if (!cfg) { fprintf(stderr, "can't allocate mem in %s\n", progname); exit(10); } memset(cfg, 0, sizeof(*cfg)); /** * Set default values */ ipsecconf_default_values(cfg); conn = alloc_add_conn(cfg, "mytestconn", &err); conn->connalias = xstrdup("anotheralias"); conn->options[KBF_DPDDELAY] = 60; conn->options_set[KBF_DPDDELAY] = 1; conn->policy = POLICY_ENCRYPT | POLICY_PFS | POLICY_COMPRESS; conn->left.rsakey1 = "0sabcdabcdabcd"; conn->left.rsakey2 = "0s23489234ba28934243"; conn->left.cert = "/my/cert/file"; ttoaddr("192.168.2.102", 0, AF_INET, &conn->left.sourceip); ttoaddr("192.168.1.101", 0, AF_INET, &conn->left.addr); conn->left.addr_family = AF_INET; conn->left.addrtype = KH_IPADDR; conn->right.addrtype = KH_DEFAULTROUTE; confwrite(cfg, stdout); exit(0); }
int main(int argc, char *argv[]) { int opt = 0; struct starter_config *cfg = NULL; err_t err = NULL; char *confdir = NULL; char *configfile = NULL; struct starter_conn *conn = NULL; progname = argv[0]; rootdir[0] = '\0'; rootdir2[0] = '\0'; tool_init_log(); while ((opt = getopt_long(argc, argv, "", longopts, 0)) != EOF) { switch (opt) { case 'h': /* usage: */ usage(); break; case 'D': verbose++; lex_verbosity++; break; case 'C': configfile = clone_str(optarg, "config file name"); break; case 'R': printf("#setting rootdir=%s\n", optarg); jam_str(rootdir, sizeof(rootdir), optarg); break; case 'S': printf("#setting rootdir2=%s\n", optarg); jam_str(rootdir2, sizeof(rootdir2), optarg); break; case '?': exit(5); default: fprintf(stderr, "%s: getopt returned %d\n", progname, opt); exit(6); } } if (optind != argc) { fprintf(stderr,"%s: unexpected arguments\n", progname); exit(4); } /* find config file */ if (confdir == NULL) confdir = IPSEC_CONFDIR; if (configfile == NULL) { /* ??? see code clone in programs/addconn/addconn.c */ configfile = alloc_bytes(strlen(confdir) + sizeof("/ipsec.conf"), "conf file"); /* calculate default value for configfile */ strcpy(configfile, confdir); /* safe: see allocation above */ if (configfile[0] != '\0' && configfile[strlen(configfile) - 1] != '/') strcat(configfile, "/"); /* safe: see allocation above */ strcat(configfile, "ipsec.conf"); /* safe: see allocation above */ } if (verbose > 3) { yydebug = 1; } if (verbose) printf("opening file: %s\n", configfile); starter_use_log(verbose != 0, TRUE, verbose == 0); cfg = confread_load(configfile, &err, FALSE, NULL, FALSE); if (cfg == NULL) { fprintf(stderr, "%s: config file \"%s\" cannot be loaded: %s\n", progname, configfile, err); exit(3); } /* load all conns marked as auto=add or better */ for (conn = cfg->conns.tqh_first; conn != NULL; conn = conn->link.tqe_next) printf("#conn %s loaded\n", conn->name); confwrite(cfg, stdout); confread_free(cfg); exit(0); }
int main(int argc, char *argv[]) { int opt = 0; int textout = 1; int whackout = 0; /* if true, write whack messages */ char *whackfile = NULL; struct starter_config *cfg = NULL; err_t err = NULL; char *confdir = NULL; char *configfile = NULL; struct starter_conn *conn = NULL; progname = argv[0]; rootdir[0]='\0'; tool_init_log(); while((opt = getopt_long(argc, argv, "", longopts, 0)) != EOF) { switch(opt) { case 'h': /* usage: */ usage(); break; case 'T': textout = 1; break; case 'w': whackfile = clone_str(optarg, "output file name"); whackout = 1; textout = 0; break; case 'D': verbose++; break; case 'W': warningsarefatal++; break; case 'C': configfile = clone_str(optarg, "config file name"); break; case 'R': if(verbose) printf("#setting rootdir=%s\n", optarg); strlcat(rootdir, optarg, sizeof(rootdir)); break; case 'S': if(verbose) printf("#setting rootdir2=%s\n", optarg); rootdir2[0]='\0'; strlcat(rootdir2, optarg, sizeof(rootdir2)); break; } } /* find config file */ confdir = getenv(IPSEC_CONFDIR_VAR); if(confdir == NULL) { confdir = IPSEC_CONFDIR; } if(!configfile) { configfile = alloc_bytes(strlen(confdir)+sizeof("/ipsec.conf")+2,"conf file"); /* calculate default value for configfile */ configfile[0]='\0'; strcpy(configfile, confdir); if(configfile[strlen(configfile)-1]!='/') { strcat(configfile, "/"); } strcat(configfile, "ipsec.conf"); } if(verbose > 3) { extern int yydebug; yydebug=1; } if(verbose) { printf("opening file: %s\n", configfile); } starter_use_log (verbose, 1, verbose ? 0 : 1); cfg = confread_load(configfile, &err, FALSE, NULL,FALSE); if(!cfg) { printf("config file: %s can not be loaded: %s\n", configfile, err); exit(3); } if(textout) { /* load all conns marked as auto=add or better */ for(conn = cfg->conns.tqh_first; conn != NULL; conn = conn->link.tqe_next) { printf("#conn %s loaded\n", conn->name); } confwrite(cfg, stdout); } if(whackout && whackfile!=NULL) { if(!openwhackrecordfile(whackfile)) { perror(whackfile); exit(5); } /* use file writer above */ cfg->send_whack_msg = send_whack_msg_to_file; /* load all conns marked as auto=add or better, and save them. */ argv+=optind; argc-=optind; for(; argc>0; argc--, argv++) { char *conn_name = *argv; for(conn = cfg->conns.tqh_first; conn != NULL; conn = conn->link.tqe_next) { if(verbose) { printf("processing conn: %s vs %s\n", conn_name, conn->name); } if(strcasecmp(conn->name, conn_name)==0) { if(starter_whack_add_conn(cfg, conn) != 0) { fprintf(stderr, "failed to load conn: %s\n", conn_name); } } } } } confread_free(cfg); exit(0); }
} /* start rtk server ----------------------------------------------------------*/ static int startsvr(vt_t *vt) { double pos[3],npos[3]; char s[3][MAXRCVCMD]={"","",""},*cmds[]={NULL,NULL,NULL}; char *ropts[]={"","",""}; char *paths[]={ strpath[0],strpath[1],strpath[2],strpath[3],strpath[4],strpath[5], strpath[6],strpath[7] }; int i,ret,stropt[8]={0}; trace(3,"startsvr:\n"); /* read start commads from command files */ for (i=0;i<3;i++) { if (!*rcvcmds[i]) continue; if (!readcmd(rcvcmds[i],s[i],0)) { printvt(vt,"no command file: %s\n",rcvcmds[i]); } else cmds[i]=s[i]; } /* confirm overwrite */ for (i=3;i<8;i++) { if (strtype[i]==STR_FILE&&!confwrite(vt,strpath[i])) return 0; } if (prcopt.refpos==4) { /* rtcm */ for (i=0;i<3;i++) prcopt.rb[i]=0.0; } pos[0]=nmeapos[0]*D2R; pos[1]=nmeapos[1]*D2R; pos[2]=0.0; pos2ecef(pos,npos); /* read antenna file */ readant(vt,&prcopt,&svr.nav); /* open geoid data file */ if (solopt[0].geoid>0&&!opengeoid(solopt[0].geoid,filopt.geoid)) { trace(2,"geoid data open error: %s\n",filopt.geoid); printvt(vt,"geoid data open error: %s\n",filopt.geoid); } for (i=0;*rcvopts[i].name;i++) modflgr[i]=0; for (i=0;*sysopts[i].name;i++) modflgs[i]=0; /* set stream options */ stropt[0]=timeout; stropt[1]=reconnect; stropt[2]=1000; stropt[3]=buffsize; stropt[4]=fswapmargin; strsetopt(stropt); if (strfmt[2]==8) strfmt[2]=STRFMT_SP3; /* set ftp/http directory and proxy */ strsetdir(filopt.tempdir); strsetproxy(proxyaddr); /* execute start command */ if (*startcmd&&(ret=system(startcmd))) { trace(2,"command exec error: %s (%d)\n",startcmd,ret); printvt(vt,"command exec error: %s (%d)\n",startcmd,ret); } solopt[0].posf=strfmt[3]; solopt[1].posf=strfmt[4]; /* start rtk server */ if (!rtksvrstart(&svr,svrcycle,buffsize,strtype,paths,strfmt,navmsgsel, cmds,ropts,nmeacycle,nmeareq,npos,&prcopt,solopt,&moni)) { trace(2,"rtk server start error\n"); printvt(vt,"rtk server start error\n"); return 0; }
int main(int argc, char *argv[]) { int opt = 0; struct starter_config *cfg = NULL; err_t err = NULL; char *confdir = NULL; char *configfile = NULL; struct starter_conn *conn = NULL; progname = argv[0]; rootdir[0]='\0'; tool_init_log(); while((opt = getopt_long(argc, argv, "", longopts, 0)) != EOF) { switch(opt) { case 'h': /* usage: */ usage(); break; case 'D': verbose++; break; case 'W': warningsarefatal++; break; case 'C': configfile = clone_str(optarg, "config file name"); break; case 'R': printf("#setting rootdir=%s\n", optarg); strlcat(rootdir, optarg, sizeof(rootdir)); break; case 'S': printf("#setting rootdir2=%s\n", optarg); rootdir2[0]='\0'; strlcat(rootdir2, optarg, sizeof(rootdir2)); break; } } /* find config file */ confdir = getenv(IPSEC_CONFDIR_VAR); if(confdir == NULL) { confdir = IPSEC_CONFDIR; } if(!configfile) { configfile = alloc_bytes(strlen(confdir)+sizeof("/ipsec.conf")+2,"conf file"); /* calculate default value for configfile */ configfile[0]='\0'; strcpy(configfile, confdir); if(configfile[strlen(configfile)-1]!='/') { strcat(configfile, "/"); } strcat(configfile, "ipsec.conf"); } if(verbose > 3) { extern int yydebug; yydebug=1; } if(verbose) { printf("opening file: %s\n", configfile); } starter_use_log (verbose, 1, verbose ? 0 : 1); cfg = confread_load(configfile, &err, FALSE, NULL,FALSE); if(!cfg) { printf("config file: %s can not be loaded: %s\n", configfile, err); exit(3); } /* load all conns marked as auto=add or better */ for(conn = cfg->conns.tqh_first; conn != NULL; conn = conn->link.tqe_next) { printf("#conn %s loaded\n", conn->name); } confwrite(cfg, stdout); confread_free(cfg); exit(0); }