void World::importConfig(const std::string& folder_name) { std::string conf_path = GetApplicationBundlePath() + "../Config/" + folder_name + "/config.cfg"; std::ifstream fichier(conf_path.c_str()); std::string spice_name, ground_tex_name, cloud_tex_name, disp_name, model_filename; std::string ligne, nom, param, empty; disp_name = spice_name = ground_tex_name = cloud_tex_name = model_filename = ""; bool is_vessel = false; fichier >> nom >> param; //fichier >> nom >> empty >> param; if ( param.size() >= 4 ) { strip(param); if (nom == "type") { if (param == "Vessel") is_vessel = true; } } do { //fichier >> nom >> empty >> param; fichier >> nom >> param; if ( param.size() >= 4 ) { strip(param); if (nom == "disp_name") disp_name = param; if (nom == "spice_name") spice_name = param; if (nom == "model") model_filename = GetApplicationBundlePath() + "../Meshes/" + folder_name + "/" + param; if (nom == "main_tex_name") { if (isURL(param)) ground_tex_name = param; else ground_tex_name = GetApplicationBundlePath() + "../Textures/" + folder_name + "/" + param; } if (nom == "clouds_tex_name") { if (isURL(param)) cloud_tex_name = param; else cloud_tex_name = GetApplicationBundlePath() + "../Textures/" + folder_name + "/" + param; } } nom = ""; } while( getline(fichier, ligne) ); //Tant qu'on n'est pas a la fin, on lit fichier.close(); if (is_vessel) { std::cout << "Création du vaisseau " << disp_name << std::endl; this->createVessel(disp_name, model_filename); } else { std::cout << "Création de la planète " << disp_name << std::endl; this->createPlanet(disp_name, spice_name, ground_tex_name, cloud_tex_name); } }
BOOL CMotdFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) { BOOL rc = FALSE; CMotdView* pView = new CMotdView(); if (pView) { rc = pView->Create(NULL, NULL, WS_VISIBLE|WS_CHILD, rectDefault, this, AFX_IDW_PANE_FIRST, pContext); if (rc) { #ifdef HTML_VIEW_ if (isURL(motdMessage_)) pView->Navigate2(motdMessage_); else { // save content to temporary file & show it tmpFileName_ = saveToTmpFile(motdMessage_); if (tmpFileName_.GetLength()) { CString url(_T("file://")); url += tmpFileName_; pView->Navigate2(url); } } #endif } } if (rc) rc = CFrameWnd::OnCreateClient(lpcs, pContext); return rc; }
BOOL TSHPath::IsURL(LPCTSTR pszPath) { static TModuleProc1<BOOL,LPCTSTR> isURL(GetModule(), IsURLStr); return isURL(pszPath); }
//////////////////////////////////////////////////////////////////////////////// // When a Lexer object is constructed with a string, this method walks through // the stream of low-level tokens. bool Lexer::token (std::string& token, Lexer::Type& type) { // Eat white space. while (isWhitespace (_text[_cursor])) utf8_next_char (_text, _cursor); // Terminate at EOS. if (isEOS ()) return false; // The sequence is specific, and must follow these rules: // - date < duration < uuid < identifier // - dom < uuid // - uuid < hex < number // - url < pair < identifier // - hex < number // - separator < tag < operator // - path < substitution < pattern // - set < number // - word last if (isString (token, type, "'\"") || isDate (token, type) || isDuration (token, type) || isURL (token, type) || isPair (token, type) || isUUID (token, type, true) || isSet (token, type) || isDOM (token, type) || isHexNumber (token, type) || isNumber (token, type) || isSeparator (token, type) || isTag (token, type) || isPath (token, type) || isSubstitution (token, type) || isPattern (token, type) || isOperator (token, type) || isIdentifier (token, type) || isWord (token, type)) return true; return false; }
int main(int argc, char **argv) { int ch; char **pkgs, **start; char *pkgs_split; whead = malloc(sizeof(struct which_head)); if (whead == NULL) err(2, NULL); TAILQ_INIT(whead); pkgs = start = argv; if (argc == 1) { MatchType = MATCH_ALL; Flags = SHOW_INDEX; } else while ((ch = getopt_long(argc, argv, opts, longopts, NULL)) != -1) { switch(ch) { case 'a': MatchType = MATCH_ALL; break; case 'b': UseBlkSz = TRUE; break; case 'v': Verbose++; /* Reasonable definition of 'everything' */ Flags = SHOW_COMMENT | SHOW_DESC | SHOW_PLIST | SHOW_INSTALL | SHOW_DEINSTALL | SHOW_REQUIRE | SHOW_DISPLAY | SHOW_MTREE; break; case 'E': Flags |= SHOW_PKGNAME; break; case 'I': Flags |= SHOW_INDEX; break; case 'p': Flags |= SHOW_PREFIX; break; case 'c': Flags |= SHOW_COMMENT; break; case 'd': Flags |= SHOW_DESC; break; case 'D': Flags |= SHOW_DISPLAY; break; case 'f': Flags |= SHOW_PLIST; break; case 'g': Flags |= SHOW_CKSUM; break; case 'G': MatchType = MATCH_EXACT; break; case 'i': Flags |= SHOW_INSTALL; break; case 'j': Flags |= SHOW_REQUIRE; break; case 'k': Flags |= SHOW_DEINSTALL; break; case 'K': KeepPackage = TRUE; break; case 'r': Flags |= SHOW_DEPEND; break; case 'R': Flags |= SHOW_REQBY; break; case 'L': Flags |= SHOW_FILES; break; case 'm': Flags |= SHOW_MTREE; break; case 's': Flags |= SHOW_SIZE; break; case 'o': Flags |= SHOW_ORIGIN; break; case 'O': LookUpOrigin = strdup(optarg); if (LookUpOrigin == NULL) err(2, NULL); break; case 'V': Flags |= SHOW_FMTREV; break; case 'l': InfoPrefix = optarg; break; case 'q': Quiet = TRUE; break; case 'Q': Quiet = TRUE; QUIET = TRUE; break; case 't': strlcpy(PlayPen, optarg, sizeof(PlayPen)); break; case 'x': MatchType = MATCH_REGEX; break; case 'X': MatchType = MATCH_EREGEX; break; case 'e': CheckPkg = optarg; break; case 'W': { struct which_entry *entp; entp = calloc(1, sizeof(struct which_entry)); if (entp == NULL) err(2, NULL); strlcpy(entp->file, optarg, PATH_MAX); entp->skip = FALSE; TAILQ_INSERT_TAIL(whead, entp, next); break; } case 'P': Flags = SHOW_PTREV; break; case 'h': default: usage(); break; } } argc -= optind; argv += optind; if (Flags & SHOW_PTREV) { if (!Quiet) printf("Package tools revision: "); printf("%d\n", PKG_INSTALL_VERSION); exit(0); } /* Set some reasonable defaults */ if (!Flags) Flags = SHOW_COMMENT | SHOW_DESC | SHOW_REQBY; /* Get all the remaining package names, if any */ while (*argv) { /* * Don't try to apply heuristics if arguments are regexs or if * the argument refers to an existing file. */ if (MatchType != MATCH_REGEX && MatchType != MATCH_EREGEX && !isfile(*argv) && !isURL(*argv)) while ((pkgs_split = strrchr(*argv, (int)'/')) != NULL) { *pkgs_split++ = '\0'; /* * If character after the '/' is alphanumeric or shell * metachar, then we've found the package name. Otherwise * we've come across a trailing '/' and need to continue our * quest. */ if (isalnum(*pkgs_split) || ((MatchType == MATCH_GLOB) && \ strpbrk(pkgs_split, "*?[]") != NULL)) { *argv = pkgs_split; break; } } *pkgs++ = *argv++; } /* If no packages, yelp */ if (pkgs == start && MatchType != MATCH_ALL && !CheckPkg && TAILQ_EMPTY(whead) && LookUpOrigin == NULL) warnx("missing package name(s)"), usage(); *pkgs = NULL; return pkg_perform(start); }
int sec_url_filter_slow(struct nf_queue_entry *entry, unsigned int queuenum) { if (entry != NULL) { if (filterMode) { struct sk_buff *skb = entry->skb; char *request = NULL; tcp_TrackInfo *gettingNode = NULL; tcp_TrackInfo *notifyNode = NULL; if (skb != NULL) { struct iphdr *iph = (struct iphdr*)ip_hdr(skb); if (iph != NULL) { if (iph->protocol == 6) { struct tcphdr *tcph = (struct tcphdr *)skb_transport_header(skb); if (tcph!= NULL) { notifyNode = find_tcp_TrackInfo(notifying_TrackInfo, skb, 0); if (notifyNode != NULL) // If this is already notified to user, drop it. { unsigned int verdict = NF_DROP; nf_reinject(entry, verdict); return 0; } gettingNode = find_tcp_TrackInfo(getting_TrackInfo, skb, 1); // Find previous TCP Track Info and remove from list if (gettingNode == NULL) // No previous Info { gettingNode = isURL(skb); // If this is URL Request then make TCP Track Info } if (gettingNode != NULL) { request = getPacketData(skb, gettingNode); // Get Packet if (request != NULL) // If there is packet data { getURL(request, gettingNode); // Get URL and update status kfree(request); request = NULL; if (gettingNode->status == GOT_FULL_URL) // If get Full URL, then make notify info { makeNotifyInfo(gettingNode); if ((exceptionURL != NULL) && (gettingNode->url !=NULL)) { if (strstr(&gettingNode->url[sizeof(URL_Info)], exceptionURL) != NULL) // This is exception URL { free_tcp_TrackInfo(gettingNode); nf_reinject(entry, NF_ACCEPT); return 0; } } gettingNode->q_entry = entry; add_tcp_TrackInfo(notifying_TrackInfo, gettingNode); wake_up_interruptible(&user_noti_Q); // Wake Up read function return 0; } } add_tcp_TrackInfo_ToHead(getting_TrackInfo, gettingNode); } } } } } } nf_reinject(entry, NF_ACCEPT); } return 0; }
static bool fixLinks(CStringA& rtf, uidToTitleMap_t *uidToTitleMapPtr) { // quick check, quick exit if (rtf.Find("\\lnkd\\protect") == -1) return false; int clrTableIndex = getColorTableIndex(rtf); if (clrTableIndex == -1) { // something bad happened return false; } // get code page unsigned codepage = CP_ACP; int cpgPos = rtf.Find("\\ansicpg"); if (cpgPos != -1) codepage = atoi((LPCSTR)rtf + cpgPos + sizeof("\\ansicpg")-1); // for each pattern of // \lnkd\protect[<space>]<text>\protect0\lnkd0 // replace with "out", where out is: // sprintf(out, _linkRTF, <nodeurl>, clrTableIndex, <text>) // where <nodeurl> is: // lookupNode(stripRTF(<text>)) int pos, ofs = 0; while ( (pos = rtf.Find("\\lnkd\\protect", ofs)) != -1 ) { // ofs2 points to start of text int ofs2 = pos + sizeof("\\lnkd\\protect")-1; // check if the \protect had a ' ' delimiter, eat it if so if (rtf[ofs2] == ' ') ofs2++; // locate the end tag int pos2 = rtf.Find("\\protect0\\lnkd0", ofs2); ASSERT(pos2 != -1); if (pos2 == -1) return false; // get the text inbetween // here is the link (title of page).. CStringA rtfLink = rtf.Mid(ofs2, pos2-ofs2); CString link = stripRTF(rtfLink, codepage); // look it up CStringA url; if (isURL(link)) { // points to a URL itself (http://, https://, ftp:// etc..) url = escapeRTF(link); // There appears to be a strange bug with the rich edit control, in that if // the hyperlink and the text are exacly the same, the hyperlink effect goes // off. As a workaround, add a space after the URL (this is ignore in our // EN_LINK handler). url += " "; } else { uint32 nodeUid = 0; if (uidToTitleMapPtr->Lookup(link, nodeUid)) // matched a node url.Format("node://./%u", nodeUid); else // unmatched node, we'll handle this later url.Format("oldlink://./%s", escapeRTF(link)); } // make the replacement CStringA replacement; replacement.Format(_linkRTF, url, clrTableIndex, escapeRTF(link)); // delete [pos, pos2+15] rtf.Delete(pos, pos2+15-pos); rtf.Insert(pos, replacement); // repositon to just after the replacement ofs = pos + replacement.GetLength(); } return true; }
/* * Parse /usr/port/UPDATING for corresponding entries. If no argument is * passed to pkg_updating all entries for all installed ports are displayed. * If a list of portnames is passed to pkg_updating only entries for the * given portnames are displayed. Use the -d option to define that only newer * entries as this date are shown. */ int main(int argc, char *argv[]) { /* Keyword for searching portname in UPDATING. */ const char *affects = "AFFECTS"; /* Indicate a date -> end of a entry. Will fail on 2100-01-01... */ const char *end = "20"; /* Keyword for searching origin portname of installed port. */ const char *origin = "@comment ORIGIN:"; const char *pkgdbpath = LOG_DIR; /* Location of pkgdb */ const char *updatingfile = UPDATING; /* Location of UPDATING */ char *date = NULL; /* Passed -d argument */ char *dateline = NULL; /* Saved date of an entry */ /* Tmp lines for parsing file */ char *tmpline1 = NULL; char *tmpline2 = NULL; char originline[LINE_MAX]; /* Line of +CONTENTS */ /* Temporary variable to create path to +CONTENTS for installed ports. */ char tmp_file[MAXPATHLEN]; char updatingline[LINE_MAX]; /* Line of UPDATING */ int ch; /* Char used by getopt */ int found = 0; /* Found an entry */ int linelength; /* Length of parsed line */ int maxcharperline = LINE_MAX; /* Max chars per line */ int dflag = 0; /* -d option set */ /* If pflag = 0 UPDATING will be checked for all installed ports. */ int pflag = 0; size_t n; /* Offset to create path */ struct dirent *pkgdbdir; /* pkgdb directory */ struct stat attribute; /* attribute of pkgdb element */ /* Needed nodes for linked list with installed ports. */ INSTALLEDPORT *head = (INSTALLEDPORT *) NULL; INSTALLEDPORT *curr = (INSTALLEDPORT *) NULL; DIR *dir; FILE *fd; while ((ch = getopt_long(argc, argv, opts, longopts, NULL)) != -1) { switch (ch) { case 'd': dflag = 1; date = optarg; break; case 'f': updatingfile = optarg; break; case 'h': default: usage(); } } argc -= optind; argv += optind; /* Check if passed date has a correct format. */ if (dflag == 1) { linelength = strlen(date); if (linelength != 8) exit(EX_DATAERR); if (strspn(date, "0123456789") != 8) { fprintf(stderr, "unknown date format: %s\n", date); exit(EX_DATAERR); } } /* Save the list of passed portnames. */ if (argc != 0) { pflag = 1; while (*argv) { if ((curr = (INSTALLEDPORT *) malloc(sizeof(INSTALLEDPORT))) == NULL) (void)exit(EXIT_FAILURE); strlcpy(curr->name, *argv, strlen(*argv) + 1); curr->next = head; head = curr; (void)*argv++; } } /* * UPDATING will be parsed for all installed ports * if no portname is passed. */ if (pflag == 0) { /* Open /var/db/pkg and search for all installed ports. */ if ((dir = opendir(pkgdbpath)) != NULL) { while ((pkgdbdir = readdir(dir)) != NULL) { if (strcmp(pkgdbdir->d_name, ".") != 0 && strcmp(pkgdbdir->d_name, "..") != 0) { /* Create path to +CONTENTS file for each installed port */ n = strlcpy(tmp_file, pkgdbpath, strlen(pkgdbpath)+1); n = strlcpy(tmp_file + n, "/", sizeof(tmp_file) - n); n = strlcat(tmp_file + n, pkgdbdir->d_name, sizeof(tmp_file) - n); if (stat(tmp_file, &attribute) == -1) { fprintf(stderr, "can't open %s: %s\n", tmp_file, strerror(errno)); return EXIT_FAILURE; } if (attribute.st_mode & S_IFREG) continue; (void)strlcat(tmp_file + n, "/", sizeof(tmp_file) - n); (void)strlcat(tmp_file + n, CONTENTS_FNAME, sizeof(tmp_file) - n); /* Open +CONTENT file */ fd = fopen(tmp_file, "r"); if (fd == NULL) { fprintf(stderr, "warning: can't open %s: %s\n", tmp_file, strerror(errno)); continue; } /* * Parses +CONTENT for ORIGIN line and * put element into linked list. */ while (fgets(originline, maxcharperline, fd) != NULL) { tmpline1 = strstr(originline, origin); if (tmpline1 != NULL) { /* Tmp variable to store port name. */ char *pname; pname = strrchr(originline, (int)':'); pname++; if ((curr = (INSTALLEDPORT *) malloc(sizeof(INSTALLEDPORT))) == NULL) (void)exit(EXIT_FAILURE); if (pname[strlen(pname) - 1] == '\n') pname[strlen(pname) - 1] = '\0'; strlcpy (curr->name, pname, strlen(pname)+1); curr->next = head; head = curr; } } if (ferror(fd)) { fprintf(stderr, "error reading input\n"); exit(EX_IOERR); } (void)fclose(fd); } } closedir(dir); } } /* Fetch UPDATING file if needed and open file */ if (isURL(updatingfile)) { if ((fd = fetchGetURL(updatingfile, "")) == NULL) { fprintf(stderr, "Error: Unable to get %s: %s\n", updatingfile, fetchLastErrString); exit(EX_UNAVAILABLE); } } else { fd = fopen(updatingfile, "r"); } if (fd == NULL) { fprintf(stderr, "can't open %s: %s\n", updatingfile, strerror(errno)); exit(EX_UNAVAILABLE); } /* Parse opened UPDATING file. */ while (fgets(updatingline, maxcharperline, fd) != NULL) { /* No entry is found so far */ if (found == 0) { /* Search for AFFECTS line to parse the portname. */ tmpline1 = strstr(updatingline, affects); if (tmpline1 != NULL) { curr = head; while (curr != NULL) { tmpline2 = strstr(updatingline, curr->name); if (tmpline2 != NULL) break; curr = curr->next; } if (tmpline2 != NULL) { /* If -d is set, check if entry is newer than the date. */ if ((dflag == 1) && (strncmp(dateline, date, 8) < 0)) continue; printf("%s", dateline); printf("%s", updatingline); found = 1; } } } /* Search for the end of an entry, if not found print the line. */ else { tmpline1 = strstr(updatingline, end); if (tmpline1 == NULL) printf("%s", updatingline); else { linelength = strlen(updatingline); if (linelength == 10) found = 0; else printf("%s", updatingline); } } /* Save the actual line, it could be a date. */ dateline = strdup(updatingline); } if (ferror(fd)) { fprintf(stderr, "error reading input\n"); exit(EX_IOERR); } (void)fclose(fd); exit(EX_OK); }
/* urls can't contain null pointer, caller must ensure this */ static enum phish_status phishingCheck(const struct cl_engine* engine,struct url_check* urls) { struct url_check host_url; enum phish_status rc=CL_PHISH_NODECISION; int phishy=0; const struct phishcheck* pchk = (const struct phishcheck*) engine->phishcheck; if(!urls->realLink.data) return CL_PHISH_CLEAN; cli_dbgmsg("Phishcheck:Checking url %s->%s\n", urls->realLink.data, urls->displayLink.data); if(!strcmp(urls->realLink.data,urls->displayLink.data)) return CL_PHISH_CLEAN;/* displayed and real URL are identical -> clean */ if((rc = cleanupURLs(urls))) { if(isPhishing(rc))/* not allowed to decide this is phishing */ return CL_PHISH_CLEAN; return rc;/* URLs identical after cleanup */ } if(whitelist_check(engine,urls,0)) return CL_PHISH_WHITELISTED;/* if url is whitelist don't perform further checks */ if((!isURL(pchk, urls->displayLink.data) || !isRealURL(pchk, urls->realLink.data) )&& ( (phishy&PHISHY_NUMERIC_IP && !isNumericURL(pchk, urls->displayLink.data)) || !(phishy&PHISHY_NUMERIC_IP))) { cli_dbgmsg("Displayed 'url' is not url:%s\n",urls->displayLink.data); return CL_PHISH_TEXTURL; } if(urls->flags&DOMAINLIST_REQUIRED && domainlist_match(engine,urls->realLink.data,urls->displayLink.data,NULL,0,&urls->flags)) phishy |= DOMAIN_LISTED; else { /* although entire url is not listed, the host might be, * so defer phishing decisions till we know if host is listed*/ } url_check_init(&host_url); if((rc = url_get_host(pchk, urls,&host_url,DOMAIN_DISPLAY,&phishy))) { free_if_needed(&host_url); if(isPhishing(rc)) return CL_PHISH_CLEAN; return rc; } if(urls->flags&DOMAINLIST_REQUIRED) { if(!(phishy&DOMAIN_LISTED)) { if(domainlist_match(engine,host_url.displayLink.data,host_url.realLink.data,&urls->pre_fixup,1,&urls->flags)) phishy |= DOMAIN_LISTED; else { } } } /* link type filtering must occur after last domainlist_match */ if(urls->link_type & LINKTYPE_IMAGE && !(urls->flags&CHECK_IMG_URL)) return CL_PHISH_HOST_NOT_LISTED;/* its listed, but this link type is filtered */ if(urls->flags & DOMAINLIST_REQUIRED && !(phishy & DOMAIN_LISTED) ) { urls->flags &= urls->always_check_flags; if(!urls->flags) { free_if_needed(&host_url); return CL_PHISH_HOST_NOT_LISTED; } } if(urls->flags&CHECK_CLOAKING) { /*Checks if URL is cloaked. Should we check if it contains another http://, https://? No because we might get false positives from redirect services.*/ if(strchr(urls->realLink.data,0x1)) { free_if_needed(&host_url); return CL_PHISH_CLOAKED_NULL; } if(isEncoded(urls->displayLink.data)) { free_if_needed(&host_url); return CL_PHISH_HEX_URL; } } if(urls->displayLink.data[0]=='\0') { free_if_needed(&host_url); return CL_PHISH_CLEAN; } if(urls->flags&CHECK_SSL && isSSL(urls->displayLink.data) && !isSSL(urls->realLink.data)) { free_if_needed(&host_url); return CL_PHISH_SSL_SPOOF; } if(!urls->flags&CHECK_CLOAKING && urls->flags & DOMAINLIST_REQUIRED && !(phishy&DOMAIN_LISTED) ) { free_if_needed(&host_url); return CL_PHISH_HOST_NOT_LISTED; } if((rc = url_get_host(pchk, urls,&host_url,DOMAIN_REAL,&phishy))) { free_if_needed(&host_url); return rc; } if(urls->flags&DOMAINLIST_REQUIRED && !(phishy&DOMAIN_LISTED)) { free_if_needed(&host_url); return CL_PHISH_HOST_NOT_LISTED; } if(whitelist_check(engine,&host_url,1)) { free_if_needed(&host_url); return CL_PHISH_HOST_WHITELISTED; } if(urls->flags&HOST_SUFFICIENT) { if(!strcmp(urls->realLink.data,urls->displayLink.data)) { free_if_needed(&host_url); return CL_PHISH_HOST_OK; } if(urls->flags&DOMAIN_SUFFICIENT) { struct url_check domain_url; url_check_init(&domain_url); url_get_domain(pchk, &host_url,&domain_url); if(!strcmp(domain_url.realLink.data,domain_url.displayLink.data)) { free_if_needed(&host_url); free_if_needed(&domain_url); return CL_PHISH_DOMAIN_OK; } free_if_needed(&domain_url); } free_if_needed(&host_url); }/*HOST_SUFFICIENT*/ /*we failed to find a reason why the 2 URLs are different, this is definitely phishing*/ if(urls->flags&DOMAINLIST_REQUIRED && !(phishy&DOMAIN_LISTED)) return CL_PHISH_HOST_NOT_LISTED; return phishy_map(phishy,CL_PHISH_NOMATCH); }
int main(int argc, char **argv){ uint i,intype=0,outtype=0; bool help = false; char *pathstr = NULL, *outpath = NULL; path pathObj; int (*infunc)(char*,path*,bool); int (*outfunc)(path*,char**); for(i=1;i<argc;++i){ if(!strncmp(argv[i],"--",2)){ char* flag = argv[i]+2; if(!strcmp(flag,"help"))help = true; else if(!strcmp(flag,"to-url"))outtype = URL_TYPE; else if(!strcmp(flag,"from-unix"))intype = UNIX_TYPE; } else if(argv[i][0] == '-'){ uint j,len = strlen(argv[i]); for(j=1;j<len;++j){ switch(argv[i][j]){ case 'h': case '?': help = true; break; case 'l': intype = UNIX_TYPE; break; case 'U': outtype = URL_TYPE; break; } } } else if(pathstr == NULL){ pathstr = argv[i]; } } if(help || pathstr == NULL){ printf("Path Conversion Utility (C) Wa <logicplace.com>\n" "If no from is given it will guess. Can only guess if it's an absolute path.\n" "Relative paths will be resolved to an absolute path as necessary (the cwd).\n" "%s options path\n" "Options:\n" " -h -? --help Show this help and exit.\n" " -l --from-unix Treat given path as unix-style.\n" //" -L --to-unix ...\n" //" -u --from-url Treat given path as a file:// url.\n" " -U --to-url Output path as a file:// url.\n" ,argv[0]); return 0; } #ifdef WINDOWS GetCurrentDirectory(sizeof(cCurrentPath), cCurrentPath) #else getcwd(cCurrentPath, sizeof(cCurrentPath)); #endif if(intype == 0){ if(isURL(pathstr))intype = URL_TYPE; else if(isUnixPath(pathstr))intype = UNIX_TYPE; else return ERROR_CANNOT_GUESS_PATH; } if(intype == outtype){ printf(pathstr); } else { switch(intype){ case UNIX_TYPE: infunc = fromUnixPath; break; } infunc(pathstr,&pathObj,needsAbsolute[outtype]); switch(outtype){ case URL_TYPE: outfunc = toURL; break; default: outfunc = defaultOut; break; } outfunc(&pathObj,&outpath); if(outpath != NULL){ printf("%s",outpath); } } safe_freeall(); return 0; }
/* * Try and fetch a file by URL, returning the directory name for where * it's unpacked, if successful. */ const char * fileGetURL(const char *base, const char *spec, int keep_package) { const char *rp; char *cp, *tmp; char fname[FILENAME_MAX]; char pen[FILENAME_MAX]; char pkg[FILENAME_MAX]; char buf[8192]; FILE *ftp; pid_t tpid; int pfd[2], pstat, r, w = 0; char *hint; int fd, pkgfd = 0; rp = NULL; /* Special tip that sysinstall left for us */ hint = getenv("PKG_ADD_BASE"); if (!isURL(spec)) { if (!base && !hint) return NULL; /* * We've been given an existing URL (that's known-good) and now we need * to construct a composite one out of that and the basename we were * handed as a dependency. */ if (base) { strcpy(fname, base); /* * Advance back two slashes to get to the root of the package * hierarchy */ cp = strrchr(fname, '/'); if (cp) { *cp = '\0'; /* chop name */ cp = strrchr(fname, '/'); } if (cp) { *(cp + 1) = '\0'; strcat(cp, "All/"); strcat(cp, spec); if (getenv("PACKAGESUFFIX")) strcat(cp, getenv("PACKAGESUFFIX")); else strcat(cp, ".tbz"); } else return NULL; } else { /* * Otherwise, we've been given an environment variable hinting * at the right location from sysinstall */ strcpy(fname, hint); strcat(fname, spec); if (getenv("PACKAGESUFFIX")) strcat(fname, getenv("PACKAGESUFFIX")); else strcat(fname, ".tbz"); } } else strcpy(fname, spec); if (keep_package) { tmp = getenv("PKGDIR"); strlcpy(pkg, tmp ? tmp : ".", sizeof(pkg)); tmp = basename(fname); strlcat(pkg, "/", sizeof(pkg)); strlcat(pkg, tmp, sizeof(pkg)); if ((pkgfd = open(pkg, O_WRONLY|O_CREAT|O_TRUNC, 0644)) == -1) { printf("Error: Unable to open %s\n", pkg); perror("open"); return NULL; } } fetchDebug = (Verbose > 0); if ((ftp = fetchGetURL(fname, Verbose ? "v" : NULL)) == NULL) { printf("Error: Unable to get %s: %s\n", fname, fetchLastErrString); /* If the fetch fails, yank the package. */ if (keep_package && unlink(pkg) < 0 && Verbose) { warnx("failed to remove partially fetched package: %s", pkg); } return NULL; } if (isatty(0) || Verbose) printf("Fetching %s...", fname), fflush(stdout); pen[0] = '\0'; if ((rp = make_playpen(pen, 0)) == NULL) { printf("Error: Unable to construct a new playpen for FTP!\n"); fclose(ftp); return NULL; } if (pipe(pfd) == -1) { warn("pipe()"); cleanup(0); exit(2); } if ((tpid = fork()) == -1) { warn("pipe()"); cleanup(0); exit(2); } if (!tpid) { dup2(pfd[0], 0); for (fd = getdtablesize() - 1; fd >= 3; --fd) close(fd); execl("/usr/bin/tar", "tar", Verbose ? "-xpjvf" : "-xpjf", "-", (char *)0); _exit(2); } close(pfd[0]); for (;;) { if ((r = fread(buf, 1, sizeof buf, ftp)) < 1) break; if ((w = write(pfd[1], buf, r)) != r) break; if (keep_package) { if ((w = write(pkgfd, buf, r)) != r) break; } } if (ferror(ftp)) warn("warning: error reading from server"); fclose(ftp); if (keep_package) { close(pkgfd); } close(pfd[1]); if (w == -1) warn("warning: error writing to tar"); tpid = waitpid(tpid, &pstat, 0); if (Verbose) printf("tar command returns %d status\n", WEXITSTATUS(pstat)); if (rp && (isatty(0) || Verbose)) printf(" Done.\n"); return rp; }
/* * This is seriously ugly code following. Written very fast! * [And subsequently made even worse.. Sigh! This code was just born * to be hacked, I guess.. :) -jkh] */ static int pkg_do(char *pkg) { Package Plist; char pkg_fullname[FILENAME_MAX]; char playpen[FILENAME_MAX]; char extract_contents[FILENAME_MAX]; char *extract; const char *where_to; FILE *cfile; int code; PackingList p; struct stat sb; int inPlace, conflictsfound, errcode; /* support for separate pre/post install scripts */ int new_m = 0; char pre_script[FILENAME_MAX] = INSTALL_FNAME; char post_script[FILENAME_MAX]; char pre_arg[FILENAME_MAX], post_arg[FILENAME_MAX]; char *conflict[2]; char **matched; int fd; conflictsfound = 0; code = 0; zapLogDir = 0; LogDir[0] = '\0'; strcpy(playpen, FirstPen); inPlace = 0; memset(&Plist, '\0', sizeof(Plist)); /* Are we coming in for a second pass, everything already extracted? */ if (!pkg) { fgets(playpen, FILENAME_MAX, stdin); playpen[strlen(playpen) - 1] = '\0'; /* pesky newline! */ if (chdir(playpen) == FAIL) { warnx("pkg_add in SLAVE mode can't chdir to %s", playpen); return 1; } read_plist(&Plist, stdin); where_to = playpen; } /* Nope - do it now */ else { /* Is it an ftp://foo.bar.baz/file.t[bg]z specification? */ if (isURL(pkg)) { if (!(where_to = fileGetURL(NULL, pkg, KeepPackage))) { warnx("unable to fetch '%s' by URL", pkg); return 1; } strcpy(pkg_fullname, pkg); cfile = fopen(CONTENTS_FNAME, "r"); if (!cfile) { warnx( "unable to open table of contents file '%s' - not a package?", CONTENTS_FNAME); goto bomb; } read_plist(&Plist, cfile); fclose(cfile); } else { strcpy(pkg_fullname, pkg); /* * Copy for sanity's sake, * could remove pkg_fullname */ if (strcmp(pkg, "-")) { if (stat(pkg_fullname, &sb) == FAIL) { warnx("can't stat package file '%s'", pkg_fullname); goto bomb; } sprintf(extract_contents, "--fast-read %s", CONTENTS_FNAME); extract = extract_contents; } else { extract = NULL; sb.st_size = 100000; /* Make up a plausible average size */ } if (!(where_to = make_playpen(playpen, sb.st_size * 4))) errx(1, "unable to make playpen for %lld bytes", (long long)sb.st_size * 4); /* Since we can call ourselves recursively, keep notes on where we came from */ if (!getenv("_TOP")) setenv("_TOP", where_to, 1); if (unpack(pkg_fullname, extract)) { warnx( "unable to extract table of contents file from '%s' - not a package?", pkg_fullname); goto bomb; } cfile = fopen(CONTENTS_FNAME, "r"); if (!cfile) { warnx( "unable to open table of contents file '%s' - not a package?", CONTENTS_FNAME); goto bomb; } read_plist(&Plist, cfile); fclose(cfile); /* Extract directly rather than moving? Oh goodie! */ if (find_plist_option(&Plist, "extract-in-place")) { if (Verbose) printf("Doing in-place extraction for %s\n", pkg_fullname); p = find_plist(&Plist, PLIST_CWD); if (p) { if (!isdir(p->name) && !Fake) { if (Verbose) printf("Desired prefix of %s does not exist, creating..\n", p->name); vsystem("/bin/mkdir -p %s", p->name); if (chdir(p->name) == -1) { warn("unable to change directory to '%s'", p->name); goto bomb; } } where_to = p->name; inPlace = 1; } else { warnx( "no prefix specified in '%s' - this is a bad package!", pkg_fullname); goto bomb; } } /* * Apply a crude heuristic to see how much space the package will * take up once it's unpacked. I've noticed that most packages * compress an average of 75%, so multiply by 4 for good measure. */ if (!extract && !inPlace && min_free(playpen) < sb.st_size * 4) { warnx("projected size of %lld exceeds available free space.\n" "Please set your PKG_TMPDIR variable to point to a location with more\n" "free space and try again", (long long)sb.st_size * 4); warnx("not extracting %s\ninto %s, sorry!", pkg_fullname, where_to); goto bomb; } /* If this is a direct extract and we didn't want it, stop now */ if (inPlace && Fake) goto success; /* Finally unpack the whole mess. If extract is null we already + did so so don't bother doing it again. */ if (extract && unpack(pkg_fullname, NULL)) { warnx("unable to extract '%s'!", pkg_fullname); goto bomb; } } /* Check for sanity and dependencies */ if (sanity_check(pkg)) goto bomb; /* If we're running in MASTER mode, just output the plist and return */ if (AddMode == MASTER) { printf("%s\n", where_playpen()); write_plist(&Plist, stdout); return 0; } } /* * If we have a prefix, delete the first one we see and add this * one in place of it. */ if (Prefix) { delete_plist(&Plist, FALSE, PLIST_CWD, NULL); add_plist_top(&Plist, PLIST_CWD, Prefix); } setenv(PKG_PREFIX_VNAME, (p = find_plist(&Plist, PLIST_CWD)) ? p->name : ".", 1); /* Protect against old packages with bogus @name and origin fields */ if (Plist.name == NULL) Plist.name = "anonymous"; if (Plist.origin == NULL) Plist.origin = "anonymous/anonymous"; /* * See if we're already registered either with the same name (the same * version) or some other version with the same origin. */ if ((isinstalledpkg(Plist.name) > 0 || matchbyorigin(Plist.origin, NULL) != NULL) && !Force) { warnx("package '%s' or its older version already installed%s", Plist.name, FailOnAlreadyInstalled ? "" : " (ignored)"); code = FailOnAlreadyInstalled != FALSE; goto success; /* close enough for government work */ } /* Now check the packing list for conflicts */ if (!IgnoreDeps){ for (p = Plist.head; p != NULL; p = p->next) { if (p->type == PLIST_CONFLICTS) { int i; conflict[0] = strdup(p->name); conflict[1] = NULL; matched = matchinstalled(MATCH_GLOB, conflict, &errcode); free(conflict[0]); if (errcode == 0 && matched != NULL) for (i = 0; matched[i] != NULL; i++) if (isinstalledpkg(matched[i]) > 0) { warnx("package '%s' conflicts with %s", Plist.name, matched[i]); conflictsfound = 1; } continue; } } if(conflictsfound) { if(!Force) { warnx("please use pkg_delete first to remove conflicting package(s) or -f to force installation"); code = 1; goto bomb; } else warnx("-f specified; proceeding anyway"); } #if ENSURE_THAT_ALL_REQUIREMENTS_ARE_MET /* * Before attempting to do the slave mode bit, ensure that we've * downloaded & processed everything we need. * It's possible that we haven't already installed all of our * dependencies if the dependency list was misgenerated due to * other dynamic dependencies or if a dependency was added to a * package without all REQUIRED_BY packages being regenerated. */ for (p = pkg ? Plist.head : NULL; p; p = p->next) { const char *ext; char *deporigin; if (p->type != PLIST_PKGDEP) continue; deporigin = (p->next->type == PLIST_DEPORIGIN) ? p->next->name : NULL; if (isinstalledpkg(p->name) <= 0 && !(deporigin != NULL && matchbyorigin(deporigin, NULL) != NULL)) { char subpkg[FILENAME_MAX], *sep; strlcpy(subpkg, pkg, sizeof subpkg); if ((sep = strrchr(subpkg, '/')) != NULL) { *sep = '\0'; if ((sep = strrchr(subpkg, '/')) != NULL) { *sep = '\0'; strlcat(subpkg, "/All/", sizeof subpkg); strlcat(subpkg, p->name, sizeof subpkg); if ((ext = strrchr(pkg, '.')) == NULL) { if (getenv("PACKAGESUFFIX")) ext = getenv("PACKAGESUFFIX"); else ext = ".tbz"; } strlcat(subpkg, ext, sizeof subpkg); pkg_do(subpkg); } } } } #endif /* Now check the packing list for dependencies */ for (p = Plist.head; p ; p = p->next) { char *deporigin; if (p->type != PLIST_PKGDEP) continue; deporigin = (p->next->type == PLIST_DEPORIGIN) ? p->next->name : NULL; if (Verbose) { printf("Package '%s' depends on '%s'", Plist.name, p->name); if (deporigin != NULL) printf(" with '%s' origin", deporigin); printf(".\n"); } if (isinstalledpkg(p->name) <= 0 && !(deporigin != NULL && matchbyorigin(deporigin, NULL) != NULL)) { char path[FILENAME_MAX]; const char *cp = NULL; if (!Fake) { char prefixArg[2 + MAXPATHLEN]; /* "-P" + Prefix */ if (PrefixRecursive) { strlcpy(prefixArg, "-P", sizeof(prefixArg)); strlcat(prefixArg, Prefix, sizeof(prefixArg)); } if (!isURL(pkg) && !getenv("PKG_ADD_BASE")) { const char *ext; ext = strrchr(pkg_fullname, '.'); if (ext == NULL) { if (getenv("PACKAGESUFFIX")) { ext = getenv("PACKAGESUFFIX"); } else { ext = ".tbz"; } } snprintf(path, FILENAME_MAX, "%s/%s%s", getenv("_TOP"), p->name, ext); if (fexists(path)) cp = path; else cp = fileFindByPath(pkg, p->name); if (cp) { if (Verbose) printf("Loading it from %s.\n", cp); if (vsystem("%s %s %s '%s'", PkgAddCmd, Verbose ? "-v " : "", PrefixRecursive ? prefixArg : "", cp)) { warnx("autoload of dependency '%s' failed%s", cp, Force ? " (proceeding anyway)" : "!"); if (!Force) ++code; } } else { warnx("could not find package %s %s", p->name, Force ? " (proceeding anyway)" : "!"); if (!Force) ++code; } } else if ((cp = fileGetURL(pkg, p->name, KeepPackage)) != NULL) { if (Verbose) printf("Finished loading %s via a URL\n", p->name); if (!fexists("+CONTENTS")) { warnx("autoloaded package %s has no +CONTENTS file?", p->name); if (!Force) ++code; } else if (vsystem("(pwd; /bin/cat +CONTENTS) | %s %s %s %s -S", PkgAddCmd, Verbose ? "-v" : "", PrefixRecursive ? prefixArg : "", KeepPackage ? "-K" : "")) { warnx("pkg_add of dependency '%s' failed%s", p->name, Force ? " (proceeding anyway)" : "!"); if (!Force) ++code; } else if (Verbose) printf("\t'%s' loaded successfully.\n", p->name); /* Nuke the temporary playpen */ leave_playpen(); } } else { if (Verbose) printf("and was not found%s.\n", Force ? " (proceeding anyway)" : ""); else printf("Package dependency %s for %s not found%s\n", p->name, pkg, Force ? " (proceeding anyway)" : "!"); if (!Force) ++code; } } else if (Verbose) printf(" - already installed.\n"); } } /* if (!IgnoreDeps) */ if (code != 0) goto bomb; /* Look for the requirements file */ if ((fd = open(REQUIRE_FNAME, O_RDWR)) != -1) { fstat(fd, &sb); fchmod(fd, sb.st_mode | S_IXALL); /* be sure, chmod a+x */ close(fd); if (Verbose) printf("Running requirements file first for %s..\n", Plist.name); if (!Fake && vsystem("./%s %s INSTALL", REQUIRE_FNAME, Plist.name)) { warnx("package %s fails requirements %s", pkg_fullname, Force ? "installing anyway" : "- not installed"); if (!Force) { code = 1; goto success; /* close enough for government work */ } } } /* * Test whether to use the old method of passing tokens to installation * scripts, and set appropriate variables.. */ if (fexists(POST_INSTALL_FNAME)) { new_m = 1; sprintf(post_script, "%s", POST_INSTALL_FNAME); pre_arg[0] = '\0'; post_arg[0] = '\0'; } else { if (fexists(INSTALL_FNAME)) { sprintf(post_script, "%s", INSTALL_FNAME); sprintf(pre_arg, "PRE-INSTALL"); sprintf(post_arg, "POST-INSTALL"); } } /* If we're really installing, and have an installation file, run it */ if (!NoInstall && (fd = open(pre_script, O_RDWR)) != -1) { fstat(fd, &sb); fchmod(fd, sb.st_mode | S_IXALL); /* be sure, chmod a+x */ close(fd); if (Verbose) printf("Running pre-install for %s..\n", Plist.name); if (!Fake && vsystem("./%s %s %s", pre_script, Plist.name, pre_arg)) { warnx("install script returned error status"); unlink(pre_script); code = 1; goto success; /* nothing to uninstall yet */ } } /* Now finally extract the entire show if we're not going direct */ if (!inPlace && !Fake) extract_plist(".", &Plist); if (!Fake && fexists(MTREE_FNAME)) { if (Verbose) printf("Running mtree for %s..\n", Plist.name); p = find_plist(&Plist, PLIST_CWD); if (Verbose) printf("mtree -U -f %s -d -e -p %s >%s\n", MTREE_FNAME, p ? p->name : "/", _PATH_DEVNULL); if (!Fake) { if (vsystem("/usr/sbin/mtree -U -f %s -d -e -p %s >%s", MTREE_FNAME, p ? p->name : "/", _PATH_DEVNULL)) warnx("mtree returned a non-zero status - continuing"); } } /* Run the installation script one last time? */ if (!NoInstall && (fd = open(post_script, O_RDWR)) != -1) { fstat(fd, &sb); fchmod(fd, sb.st_mode | S_IXALL); /* be sure, chmod a+x */ close(fd); if (Verbose) printf("Running post-install for %s..\n", Plist.name); if (!Fake && vsystem("./%s %s %s", post_script, Plist.name, post_arg)) { warnx("install script returned error status"); unlink(post_script); code = 1; goto fail; } } /* Time to record the deed? */ if (!NoRecord && !Fake) { char contents[FILENAME_MAX]; char **depnames = NULL, **deporigins = NULL, ***depmatches; int i, dep_count = 0; FILE *contfile; if (getuid() != 0) warnx("not running as root - trying to record install anyway"); sprintf(LogDir, "%s/%s", LOG_DIR, Plist.name); zapLogDir = 1; if (Verbose) printf("Attempting to record package into %s..\n", LogDir); if (make_hierarchy(LogDir, FALSE)) { warnx("can't record package into '%s', you're on your own!", LogDir); bzero(LogDir, FILENAME_MAX); code = 1; goto success; /* close enough for government work */ } /* Make sure pkg_info can read the entry */ fd = open(LogDir, O_RDWR); fstat(fd, &sb); fchmod(fd, sb.st_mode | S_IRALL | S_IXALL); /* be sure, chmod a+rx */ close(fd); move_file(".", DESC_FNAME, LogDir); move_file(".", COMMENT_FNAME, LogDir); if (fexists(INSTALL_FNAME)) move_file(".", INSTALL_FNAME, LogDir); if (fexists(POST_INSTALL_FNAME)) move_file(".", POST_INSTALL_FNAME, LogDir); if (fexists(DEINSTALL_FNAME)) move_file(".", DEINSTALL_FNAME, LogDir); if (fexists(POST_DEINSTALL_FNAME)) move_file(".", POST_DEINSTALL_FNAME, LogDir); if (fexists(REQUIRE_FNAME)) move_file(".", REQUIRE_FNAME, LogDir); if (fexists(DISPLAY_FNAME)) move_file(".", DISPLAY_FNAME, LogDir); if (fexists(MTREE_FNAME)) move_file(".", MTREE_FNAME, LogDir); sprintf(contents, "%s/%s", LogDir, CONTENTS_FNAME); contfile = fopen(contents, "w"); if (!contfile) { warnx("can't open new contents file '%s'! can't register pkg", contents); goto success; /* can't log, but still keep pkg */ } write_plist(&Plist, contfile); fclose(contfile); for (p = Plist.head; p ; p = p->next) { char *deporigin; if (p->type != PLIST_PKGDEP) continue; deporigin = (p->next->type == PLIST_DEPORIGIN) ? p->next->name : NULL; if (Verbose) { printf("Trying to record dependency on package '%s'", p->name); if (deporigin != NULL) printf(" with '%s' origin", deporigin); printf(".\n"); } if (deporigin) { /* Defer to origin lookup */ depnames = realloc(depnames, (dep_count + 1) * sizeof(*depnames)); depnames[dep_count] = p->name; deporigins = realloc(deporigins, (dep_count + 2) * sizeof(*deporigins)); deporigins[dep_count] = deporigin; deporigins[dep_count + 1] = NULL; dep_count++; } else { /* No origin recorded, try to register on literal package name */ sprintf(contents, "%s/%s/%s", LOG_DIR, p->name, REQUIRED_BY_FNAME); contfile = fopen(contents, "a"); if (!contfile) { warnx("can't open dependency file '%s'!\n" "dependency registration is incomplete", contents); } else { fprintf(contfile, "%s\n", Plist.name); if (fclose(contfile) == EOF) { warnx("cannot properly close file %s", contents); } } } } if (dep_count > 0) { depmatches = matchallbyorigin((const char **)deporigins, NULL); free(deporigins); if (!IgnoreDeps && depmatches) { for (i = 0; i < dep_count; i++) { if (depmatches[i]) { int j; char **tmp = depmatches[i]; for (j = 0; tmp[j] != NULL; j++) { /* Origin looked up */ sprintf(contents, "%s/%s/%s", LOG_DIR, tmp[j], REQUIRED_BY_FNAME); if (depnames[i] && strcmp(depnames[i], tmp[j]) != 0) warnx("warning: package '%s' requires '%s', but '%s' " "is installed", Plist.name, depnames[i], tmp[j]); contfile = fopen(contents, "a"); if (!contfile) { warnx("can't open dependency file '%s'!\n" "dependency registration is incomplete", contents); } else { fprintf(contfile, "%s\n", Plist.name); if (fclose(contfile) == EOF) warnx("cannot properly close file %s", contents); } } } else if (depnames[i]) { /* No package present with this origin, try literal package name */ sprintf(contents, "%s/%s/%s", LOG_DIR, depnames[i], REQUIRED_BY_FNAME); contfile = fopen(contents, "a"); if (!contfile) { warnx("can't open dependency file '%s'!\n" "dependency registration is incomplete", contents); } else { fprintf(contfile, "%s\n", Plist.name); if (fclose(contfile) == EOF) { warnx("cannot properly close file %s", contents); } } } } } } if (Verbose) printf("Package %s registered in %s\n", Plist.name, LogDir); } if ((p = find_plist(&Plist, PLIST_DISPLAY)) != NULL) { FILE *fp; char buf[BUFSIZ]; snprintf(buf, sizeof buf, "%s/%s", LogDir, p->name); fp = fopen(buf, "r"); if (fp) { putc('\n', stdout); while (fgets(buf, sizeof(buf), fp)) fputs(buf, stdout); putc('\n', stdout); (void) fclose(fp); } else { if (!Fake) { warnx("cannot open %s as display file", buf); } } } goto success; bomb: code = 1; goto success; fail: /* Nuke the whole (installed) show, XXX but don't clean directories */ if (!Fake) delete_package(FALSE, FALSE, &Plist); success: /* delete the packing list contents */ free_plist(&Plist); leave_playpen(); return code; }
/* urls can't contain null pointer, caller must ensure this */ static enum phish_status phishingCheck(const struct cl_engine* engine,struct url_check* urls) { struct url_check host_url; int rc = CL_PHISH_NODECISION; int phishy=0; const struct phishcheck* pchk = (const struct phishcheck*) engine->phishcheck; if(!urls->realLink.data) return CL_PHISH_CLEAN; cli_dbgmsg("Phishcheck:Checking url %s->%s\n", urls->realLink.data, urls->displayLink.data); if(!isURL(urls->realLink.data, 0)) { cli_dbgmsg("Real 'url' is not url:%s\n",urls->realLink.data); return CL_PHISH_CLEAN; } if(( rc = url_hash_match(engine->domainlist_matcher, urls->realLink.data, strlen(urls->realLink.data)) )) { if (rc == CL_PHISH_CLEAN) { cli_dbgmsg("not analyzing, not a real url: %s\n", urls->realLink.data); return CL_PHISH_CLEAN; } else { cli_dbgmsg("Hash matched for: %s\n", urls->realLink.data); return rc; } } if(!strcmp(urls->realLink.data,urls->displayLink.data)) return CL_PHISH_CLEAN;/* displayed and real URL are identical -> clean */ if (urls->displayLink.data[0] == '\0') { return CL_PHISH_CLEAN; } if((rc = cleanupURLs(urls))) { /* it can only return an error, or say its clean; * it is not allowed to decide it is phishing */ return rc < 0 ? rc : CL_PHISH_CLEAN; } cli_dbgmsg("Phishcheck:URL after cleanup: %s->%s\n", urls->realLink.data, urls->displayLink.data); if((!isURL(urls->displayLink.data, 1) ) && ( (phishy&PHISHY_NUMERIC_IP && !isNumericURL(pchk, urls->displayLink.data)) || !(phishy&PHISHY_NUMERIC_IP))) { cli_dbgmsg("Displayed 'url' is not url:%s\n",urls->displayLink.data); return CL_PHISH_CLEAN; } if(whitelist_check(engine, urls, 0)) return CL_PHISH_CLEAN;/* if url is whitelisted don't perform further checks */ url_check_init(&host_url); if((rc = url_get_host(urls, &host_url, DOMAIN_DISPLAY, &phishy))) { free_if_needed(&host_url); return rc < 0 ? rc : CL_PHISH_CLEAN; } if (domainlist_match(engine, host_url.displayLink.data,host_url.realLink.data,&urls->pre_fixup,1)) { phishy |= DOMAIN_LISTED; } else { urls->flags &= urls->always_check_flags; /* don't return, we may need to check for ssl/cloaking */ } /* link type filtering must occur after last domainlist_match */ if(urls->link_type & LINKTYPE_IMAGE && !(urls->flags&CHECK_IMG_URL)) { free_if_needed(&host_url); return CL_PHISH_CLEAN;/* its listed, but this link type is filtered */ } if(urls->flags&CHECK_CLOAKING) { /*Checks if URL is cloaked. Should we check if it contains another http://, https://? No because we might get false positives from redirect services.*/ if(strchr(urls->realLink.data,0x1)) { free_if_needed(&host_url); return CL_PHISH_CLOAKED_NULL; } } if(urls->flags&CHECK_SSL && isSSL(urls->displayLink.data) && !isSSL(urls->realLink.data)) { free_if_needed(&host_url); return CL_PHISH_SSL_SPOOF; } if (!(phishy & DOMAIN_LISTED)) { free_if_needed(&host_url); return CL_PHISH_CLEAN; } if((rc = url_get_host(urls,&host_url,DOMAIN_REAL,&phishy))) { free_if_needed(&host_url); return rc < 0 ? rc : CL_PHISH_CLEAN; } if(whitelist_check(engine,&host_url,1)) { free_if_needed(&host_url); return CL_PHISH_CLEAN; } if(!strcmp(urls->realLink.data,urls->displayLink.data)) { free_if_needed(&host_url); return CL_PHISH_CLEAN; } { struct url_check domain_url; url_check_init(&domain_url); url_get_domain(&host_url,&domain_url); if(!strcmp(domain_url.realLink.data,domain_url.displayLink.data)) { free_if_needed(&host_url); free_if_needed(&domain_url); return CL_PHISH_CLEAN; } free_if_needed(&domain_url); } free_if_needed(&host_url); /*we failed to find a reason why the 2 URLs are different, this is definitely phishing*/ return phishy_map(phishy,CL_PHISH_NOMATCH); }
Planet::Planet(osg::ref_ptr<osg::Group>& root, const std::string& disp_name, const std::string& spice_name, const std::string& ground_tex_name, const std::string& cloud_tex_name) { _nom = disp_name; _spice = Spice::Object(spice_name); // Importation des parametres physiques dans SPICE double Req, Rpo; _spice.getRadii(&Req, &Rpo); // OSG part osg::Uniform* lightPositionUniform; osg::Uniform* cloudPositionUniform; _osg_node = new osg::Geode(); _osg_node->addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(), 1.0f))); osg::StateSet *planetStateSet = _osg_node->getOrCreateStateSet(); planetStateSet->ref(); osg::Program *programObject = new osg::Program(); osg::Shader *vertexObject = new osg::Shader(osg::Shader::VERTEX); osg::Shader *fragmentObject = new osg::Shader(osg::Shader::FRAGMENT); programObject->addShader(fragmentObject); programObject->addShader(vertexObject); vertexObject->loadShaderSourceFromFile(GetApplicationResourcesPath() + "planet.vert"); fragmentObject->loadShaderSourceFromFile(GetApplicationResourcesPath() + "planet.frag"); planetStateSet->setAttributeAndModes(programObject, osg::StateAttribute::ON); // TEXTURES // EARTH if (isURL(ground_tex_name)) std::cout << "Téléchargement de " + ground_tex_name; osg::Image *image = osgDB::readImageFile(ground_tex_name); if (isURL(ground_tex_name)) std::cout << " Terminé" << std::endl; if (!image) { std::cout << "Couldn't load texture " << ground_tex_name << std::endl; } osg::Texture2D *texture = new osg::Texture2D; texture->setDataVariance(osg::Object::DYNAMIC); texture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR); texture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); texture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT); texture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP); texture->setImage(image); planetStateSet->setTextureAttributeAndModes( // use texture unit 0 0, texture, osg::StateAttribute::ON ); // use texture unit 0 planetStateSet->addUniform(new osg::Uniform("planet_map", 0)); // CLOUDS if (isURL(cloud_tex_name)) std::cout << "Téléchargement de " + cloud_tex_name; osg::Image *image_clouds = osgDB::readImageFile(cloud_tex_name); if (isURL(cloud_tex_name)) std::cout << " Terminé" << std::endl; if (!image_clouds) { std::cout << "Couldn't load texture " << cloud_tex_name << std::endl; } osg::Texture2D *texture_clouds = new osg::Texture2D; texture_clouds->setDataVariance(osg::Object::DYNAMIC); texture_clouds->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR); texture_clouds->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); texture_clouds->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT); texture_clouds->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP); texture_clouds->setImage(image_clouds); planetStateSet->setTextureAttributeAndModes( // use texture unit 1 1, texture_clouds, osg::StateAttribute::ON ); // use texture unit 0 planetStateSet->addUniform(new osg::Uniform("planet_map_clouds", 1)); // END TEXTURES lightPositionUniform = new osg::Uniform("light_position", osg::Vec4()); planetStateSet->addUniform(lightPositionUniform); cloudPositionUniform = new osg::Uniform("cloud_position", osg::Vec2()); planetStateSet->addUniform(cloudPositionUniform); lightPositionUniform->set(osg::Vec4(-1.0, 0.0, 0.0, 0.0)); cloudPositionUniform->set(osg::Vec2(0.0, 0.0)); root->addChild( _osg_node.get() ); osg::notify( osg::ALWAYS ) << "Planète " << _nom << " crée" << std::endl; }