コード例 #1
0
bool
EnvFilter::ImportFilter( const MyString &var, const MyString &val ) const
{
	if ( (var.find(";") >= 0) || (val.find(";") >= 0) ) {
		return false;
	}
	return IsSafeEnvV2Value( val.Value() );
}
コード例 #2
0
ファイル: ipv6_hostname.cpp プロジェクト: AlainRoy/htcondor
condor_sockaddr convert_hostname_to_ipaddr(const MyString& fullname)
{
	MyString hostname;
	MyString default_domain;
	bool truncated = false;
	if (param(default_domain, "DEFAULT_DOMAIN_NAME")) {
		MyString dotted_domain = ".";
		dotted_domain += default_domain;
		int pos = fullname.find(dotted_domain.Value());
		if (pos != -1) {
			truncated = true;
			hostname = fullname.Substr(0, pos - 1);
		}
	}
	if (!truncated)
		hostname = fullname;

	// detects if hostname is IPv6
	//
	// hostname is NODNS coded address
	//
	// for example,
	// it could be 127-0-0-1 (127.0.0.1) as IPv4 address
	// it could be fe80-3577--1234 ( fe80:3577::1234) as IPv6 address
	//
	// it is IPv6 address
	// 1) if there are 7 '-'
	// 2) if there are '--' which means compaction of zeroes in IPv6 adress

	char target_char;
	bool ipv6 = false;
	if (hostname.find("--") != -1)
		ipv6 = true;
	else {
		int dash_count = 0;
		for (int i = 0; i < hostname.Length(); ++i)
			if (hostname[i] == '-')
				++dash_count;

		if (dash_count == 7)
			ipv6 = true;
	}

	if (ipv6)
		target_char = ':';
	else
		target_char ='.';
		// converts hostname to IP address string
	for (int i = 0; i < hostname.Length(); ++i) {
		if (hostname[i] == '-')
			hostname.setChar(i, target_char);
	}

	condor_sockaddr ret;
	ret.from_ip_string(hostname);
	return ret;
}
コード例 #3
0
ファイル: path.cpp プロジェクト: unoyx/vfs
Vector<MyString> split(const MyString& path)
{
    Vector<MyString> ret;
    int spos = 0;
    while (spos < path.size())
    {
        int epos = path.find(_T('\\'), spos);
        if (epos != -1)
        {
            int i = epos + 1;
            while (i < path.size() && path[i] == _T('\\'))
                ++i;
            MyString name(path.substr(spos, epos - spos));
            ret.append(name);
            spos = i;
        }
        else if (spos < path.size())
        {
            MyString name(path.substr(spos));
            ret.append(name);
            spos = path.size();
        }
    }
    return ret;
}
コード例 #4
0
ファイル: ccb_listener.cpp プロジェクト: osg-bosco/htcondor
bool
CCBListener::HandleCCBRequest( ClassAd &msg )
{
	MyString address;
	MyString connect_id;
	MyString request_id;
	MyString name;
	if( !msg.LookupString( ATTR_MY_ADDRESS, address) ||
		!msg.LookupString( ATTR_CLAIM_ID, connect_id) ||
		!msg.LookupString( ATTR_REQUEST_ID, request_id) )
	{
		MyString msg_str;
		msg.sPrint(msg_str);
		EXCEPT("CCBListener: invalid CCB request from %s: %s\n",
			   m_ccb_address.Value(),
			   msg_str.Value() );
	}

	msg.LookupString( ATTR_NAME, name );

	if( name.find(address.Value())<0 ) {
		name.formatstr_cat(" with reverse connect address %s",address.Value());
	}
	dprintf(D_FULLDEBUG|D_NETWORK,
			"CCBListener: received request to connect to %s, request id %s.\n",
			name.Value(), request_id.Value());

	return DoReversedCCBConnect( address.Value(), connect_id.Value(), request_id.Value(), name.Value() );
}
コード例 #5
0
/** Parse arguments that are to be preserved when updating a .condor.sub
	file.  If the given argument such an argument, parse it and update the
	shallowOpts structure accordingly.  (This function is meant to be called
	both when parsing "normal" command-line arguments, and when parsing the
	existing arguments line of a .condor.sub file we're overwriting.)
	@param strArg: the argument we're parsing
	@param argNum: the argument number of the current argument
	@param argc: the argument count (passed to get value for flag)
	@param argv: the argument vector (passed to get value for flag)
	@param shallowOpts: the condor_submit_dag shallow options
	@return true iff the argument vector contained any arguments
		processed by this function
*/
bool
parsePreservedArgs(const MyString &strArg, int &argNum, int argc,
			const char * const argv[], SubmitDagShallowOptions &shallowOpts)
{
	bool result = false;

	if (strArg.find("-maxi") != -1) // -maxidle
	{
		if (argNum + 1 >= argc) {
			fprintf(stderr, "-maxidle argument needs a value\n");
			printUsage();
		}
		shallowOpts.iMaxIdle = atoi(argv[++argNum]);
		result = true;
	}
	else if (strArg.find("-maxj") != -1) // -maxjobs
	{
		if (argNum + 1 >= argc) {
			fprintf(stderr, "-maxjobs argument needs a value\n");
			printUsage();
		}
		shallowOpts.iMaxJobs = atoi(argv[++argNum]);
		result = true;
	}
	else if (strArg.find("-maxpr") != -1) // -maxpre
	{
		if (argNum + 1 >= argc) {
			fprintf(stderr, "-maxpre argument needs a value\n");
			printUsage();
		}
		shallowOpts.iMaxPre = atoi(argv[++argNum]);
		result = true;
	}
	else if (strArg.find("-maxpo") != -1) // -maxpost
	{
		if (argNum + 1 >= argc) {
			fprintf(stderr, "-maxpost argument needs a value\n");
			printUsage();
		}
		shallowOpts.iMaxPost = atoi(argv[++argNum]);
		result = true;
	}

	return result;
}
コード例 #6
0
void HTTPServer::onIncomingConnection ( SOCKET sock )
{

	//read data from socket
	char buffer[1024];
	int n;
	bzero ( buffer, sizeof ( buffer ) );

	n = read ( sock,buffer,1024 );
	if ( n < 0 ) {
		mLog ( "ERROR reading from socket", LOG_PERROR );
		exit ( 1 );
	}
	//mLog((string)"Read from buffer: " + buffer);

	MyString data ( buffer );
	//data now contains incoming data.

	string firstLine;
	firstLine = data.substr ( 0, data.find ( "\r\n" ) );

	//we should check if header is correct
	const string prefix ( "GET" );
	const string postfix ( "HTTP/1." );
#ifdef FULLDEBUG
	mLog ( ( "Data received: " + data ).c_str() );
#endif

	if ( firstLine.find ( prefix ) != 0 // doesn't start with prefix
	     || firstLine.find ( postfix ) != firstLine.length()-1 - postfix.length() // doesn't end with postfix
	     || firstLine.length() < 14 ) { // length is small
		// header is incorrect
		mLog ( "Bad request: " + firstLine );
		exit ( 1 );
	} else {
		// header is correct
		MyString req = firstLine.substr ( 4, firstLine.find ( postfix )-4 );
		req.trim();
#if defined(FULLDEBUG)
		mLog ( "request is:" + req );
		mLog ( "first line is:" + firstLine );
#endif

		onUrlRequested ( req, sock );
	}

	close ( sock );
	lock();
	openConnCount--;
	unlock();


}
コード例 #7
0
ファイル: SubmitterUtils.cpp プロジェクト: AlainRoy/htcondor
void SanitizeSubmitterName(MyString &name)
{
		// We /may/ (will!) use the name as the name of an
		// attribute, so we must strip invalid characters that we
		// expect to find in the name.

	static const int invalid_char_len = 4;
	static const char *invalid_chars[invalid_char_len] =
		{"-", "@", ".", " "}; // XXX: Invert this, use [a-zA-Z_][a-zA-Z0-9_]*
	for (int i = 0; i < invalid_char_len; i++) {
		while (-1 != name.find(invalid_chars[i])) {
			name.replaceString(invalid_chars[i], "_");
		}
	}
}
コード例 #8
0
ファイル: path.cpp プロジェクト: unoyx/vfs
// 在src中确定从位置pos开始,长度为len的范围内的首个与c匹配字符的位置
static int skipToEqual(const MyString& src, int pos, TCHAR c, int len = 0)
{
    assert(len >= 0);
    if (len == 0)
    {
        return src.find(c, pos);
    }
    for (int i = 0; i < len && (pos + i) < src.size(); ++i)
    {
        if (src[pos + i] == c)
        {
            return pos + i;
        }
    }
    return -1;
}
コード例 #9
0
ファイル: path.cpp プロジェクト: unoyx/vfs
// .
// ..
// .\
// ..\
// name
bool isRelative(MyString path)
{
    assert(!path.isEmpty());
    if (path.startWith(_T(".")))
    {
        return true;
    }
    else
    {
        int pos = path.find(_T('\\'));
        MyString head = path.substr(0, pos);
        if (!head.isEmpty() && isLegalName(head))
            return true;
    }
    return false;
}
コード例 #10
0
ファイル: pigeon.cpp プロジェクト: bbockelm/htcondor
void Pigeon::stdoutHandler(int /*pipe*/) {
  char buff[STDOUT_READBUF_SIZE];
  int bytes = 0;
  int ad_type = AD_NULL;

  while ( (bytes = daemonCore->Read_Pipe(m_stdOut, buff, 
          STDOUT_READBUF_SIZE)) > 0) {
    buff[bytes] = '\0';
    m_line_stdout += buff;
    int pos = m_line_stdout.FindChar('\n', 0);
    while (pos > 0) {                
      //Here we get a newline terminated string to process.
      MyString line = m_line_stdout.substr(0, pos);
      m_line_stdout = m_line_stdout.substr(pos+1, m_line_stdout.Length());

      if (line.find("START_AD") >= 0) {
        MyString adKey, adValue;

        ad_type = getKeyValue(line, &adKey, &adValue);
        dprintf(D_FULLDEBUG, "AD: %s type=%d\n", line.Value(), ad_type);

        if (ad_type == AD_NULL) {
          pos = m_line_stdout.FindChar('\n', 0);
          continue;
        }

        dprintf(D_FULLDEBUG, "AD: key %s, value %s\n", adKey.Value(), adValue.Value());                                        
        if (ad_type == AD_STRING)
          m_qpidAd.Assign(adKey.Value(), adValue);

        else if (ad_type == AD_INT || ad_type == AD_BOOLEAN)
          m_qpidAd.Assign(adKey.Value(), atoi(adValue.Value()));

        else if (ad_type == AD_DOUBLE)
          m_qpidAd.Assign(adKey.Value(), atof(adValue.Value()));
      }
      dprintf(D_ALWAYS, "STDOUT: %s\n", line.Value());
      pos = m_line_stdout.FindChar('\n', 0);
    }
  }
}
コード例 #11
0
ファイル: vm_univ_utils.cpp プロジェクト: emaste/htcondor
bool 
create_name_for_VM(ClassAd *ad, MyString& vmname)
{
	if( !ad ) {
		return false;
	}

	int cluster_id = 0;
	if( ad->LookupInteger(ATTR_CLUSTER_ID, cluster_id) != 1 ) {
		dprintf(D_ALWAYS, "%s cannot be found in job classAd\n", 
				ATTR_CLUSTER_ID); 
		return false;
	}

	int proc_id = 0;
	if( ad->LookupInteger(ATTR_PROC_ID, proc_id) != 1 ) {
		dprintf(D_ALWAYS, "%s cannot be found in job classAd\n", 
				ATTR_PROC_ID); 
		return false;
	}

	MyString stringattr;
	if( ad->LookupString(ATTR_USER, stringattr) != 1 ) {
		dprintf(D_ALWAYS, "%s cannot be found in job classAd\n", 
				ATTR_USER); 
		return false;
	}

	// replace '@' with '_'
	int pos = -1;
	while( (pos = stringattr.find("@") ) >= 0 ) {
		stringattr.setChar(pos, '_');
	}

	vmname = stringattr;
	vmname += "_";
	vmname += cluster_id;
	vmname += "_";
	vmname += proc_id;
	return true;
}
コード例 #12
0
ファイル: path.cpp プロジェクト: unoyx/vfs
bool hasWildcard(const MyString& s)
{
    return (s.find('*') != -1) || (s.find('?') != -1);
}
コード例 #13
0
//---------------------------------------------------------------------------
void
parseCommandLine(SubmitDagDeepOptions &deepOpts,
			SubmitDagShallowOptions &shallowOpts, int argc,
			const char * const argv[])
{
	for (int iArg = 1; iArg < argc; iArg++)
	{
		MyString strArg = argv[iArg];

		if (strArg[0] != '-')
		{
				// We assume an argument without a leading hyphen is
				// a DAG file name.
			shallowOpts.dagFiles.append(strArg.Value());
			if ( shallowOpts.primaryDagFile == "" ) {
				shallowOpts.primaryDagFile = strArg;
			}
		}
		else if (shallowOpts.primaryDagFile != "")
		{
				// Disallow hyphen args after DAG file name(s).
			printf("ERROR: no arguments allowed after DAG file name(s)\n");
			printUsage();
		}
		else
		{
			strArg.lower_case();

			// Note: in checking the argument names here, we only check for
			// as much of the full name as we need to unambiguously define
			// the argument.
			if (strArg.find("-no_s") != -1) // -no_submit
			{
				shallowOpts.bSubmit = false;
			}
			else if (strArg.find("-vers") != -1) // -version
			{
				printf( "%s\n%s\n", CondorVersion(), CondorPlatform() );
				exit( 0 );
			}
			else if (strArg.find("-help") != -1 || strArg.find("-h") != -1) // -help
			{
				printUsage(0);
			}
				// submit and stick to a specific schedd
			else if (strArg.find("-schedd-daemon-ad-file") != -1)
			{
				if (iArg + 1 >= argc) {
					fprintf(stderr, "-schedd-daemon-ad-file argument needs a value\n");
					printUsage();
				}
				shallowOpts.strScheddDaemonAdFile = argv[++iArg];
			}
				// submit and stick to a specific schedd
			else if (strArg.find("-schedd-address-file") != -1)
			{
				if (iArg + 1 >= argc) {
					fprintf(stderr, "-schedd-address-file argument needs a value\n");
					printUsage();
				}
				shallowOpts.strScheddAddressFile = argv[++iArg];
			}
			else if (strArg.find("-f") != -1) // -force
			{
				deepOpts.bForce = true;
			}
			else if (strArg.find("-not") != -1) // -notification
			{
				if (iArg + 1 >= argc) {
					fprintf(stderr, "-notification argument needs a value\n");
					printUsage();
				}
				deepOpts.strNotification = argv[++iArg];
			}
			else if (strArg.find("-r") != -1) // submit to remote schedd
			{
				if (iArg + 1 >= argc) {
					fprintf(stderr, "-r argument needs a value\n");
					printUsage();
				}
				shallowOpts.strRemoteSchedd = argv[++iArg];
			}
			else if (strArg.find("-dagman") != -1)
			{
				if (iArg + 1 >= argc) {
					fprintf(stderr, "-dagman argument needs a value\n");
					printUsage();
				}
				deepOpts.strDagmanPath = argv[++iArg];
			}
			else if (strArg.find("-de") != -1) // -debug
			{
				if (iArg + 1 >= argc) {
					fprintf(stderr, "-debug argument needs a value\n");
					printUsage();
				}
				shallowOpts.iDebugLevel = atoi(argv[++iArg]);
			}
			else if (strArg.find("-noev") != -1) // -noeventchecks
			{
				shallowOpts.bNoEventChecks = true;
			}
			else if (strArg.find("-allowlog") != -1) // -allowlogerror
			{
				deepOpts.bAllowLogError = true;
			}
			else if (strArg.find("-use") != -1) // -usedagdir
			{
				deepOpts.useDagDir = true;
			}
			else if (strArg.find("-out") != -1) // -outfile_dir
			{
				if (iArg + 1 >= argc) {
					fprintf(stderr, "-outfile_dir argument needs a value\n");
					printUsage();
				}
				deepOpts.strOutfileDir = argv[++iArg];
			}
			else if (strArg.find("-con") != -1) // -config
			{
				if (iArg + 1 >= argc) {
					fprintf(stderr, "-config argument needs a value\n");
					printUsage();
				}
				shallowOpts.strConfigFile = argv[++iArg];
					// Internally we deal with all configuration file paths
					// as full paths, to make it easier to determine whether
					// several paths point to the same file.
				MyString	errMsg;
				if (!MakePathAbsolute(shallowOpts.strConfigFile, errMsg)) {
					fprintf( stderr, "%s\n", errMsg.Value() );
   					exit( 1 );
				}
			}
			else if (strArg.find("-app") != -1) // -append
			{
				if (iArg + 1 >= argc) {
					fprintf(stderr, "-append argument needs a value\n");
					printUsage();
				}
				shallowOpts.appendLines.append(argv[++iArg]);
			}
			else if (strArg.find("-insert") != -1) // -insert_sub_file
			{
				if (iArg + 1 >= argc) {
					fprintf(stderr, "-insert_sub_file argument needs a value\n");
					printUsage();
				}
				++iArg;
				if (shallowOpts.appendFile != "") {
					printf("Note: -insert_sub_file value (%s) overriding "
								"DAGMAN_INSERT_SUB_FILE setting (%s)\n",
								argv[iArg], shallowOpts.appendFile.Value());
				}
				shallowOpts.appendFile = argv[iArg];
			}
			else if (strArg.find("-autor") != -1) // -autorescue
			{
				if (iArg + 1 >= argc) {
					fprintf(stderr, "-autorescue argument needs a value\n");
					printUsage();
				}
				deepOpts.autoRescue = (atoi(argv[++iArg]) != 0);
			}
			else if (strArg.find("-dores") != -1) // -dorescuefrom
			{
				if (iArg + 1 >= argc) {
					fprintf(stderr, "-dorescuefrom argument needs a value\n");
					printUsage();
				}
				deepOpts.doRescueFrom = atoi(argv[++iArg]);
			}
			else if (strArg.find("-allowver") != -1) // -AllowVersionMismatch
			{
				deepOpts.allowVerMismatch = true;
			}
			else if (strArg.find("-no_rec") != -1) // -no_recurse
			{
				deepOpts.recurse = false;
			}
			else if (strArg.find("-do_rec") != -1) // -do_recurse
			{
				deepOpts.recurse = true;
			}
			else if (strArg.find("-updat") != -1) // -update_submit
			{
				deepOpts.updateSubmit = true;
			}
			else if (strArg.find("-import_env") != -1) // -import_env
			{
				deepOpts.importEnv = true;
			}			     
			else if (strArg.find("-dumpr") != -1) // -DumpRescue
			{
				shallowOpts.dumpRescueDag = true;
			}
			else if (strArg.find("-valgrind") != -1) // -valgrind
			{
				shallowOpts.runValgrind = true;
			}
				// This must come last, so we can have other arguments
				// that start with -v.
			else if ( (strArg.find("-v") != -1) ) // -verbose
			{
				deepOpts.bVerbose = true;
			}
			else if ( (strArg.find("-dontalwaysrun") != -1) ) // DontAlwaysRunPost
			{
				shallowOpts.bPostRun = false;
			}
			else if ( (strArg.find("-dont_use_default_node_log") != -1) )
			{
				fprintf( stderr, "Error: -dont_use_default_node_log is no longer allowed\n" );
				printUsage();
			}
			else if ( (strArg.find("-suppress_notification") != -1) )
			{
				deepOpts.suppress_notification = true;
			}
			else if ( (strArg.find("-dont_suppress_notification") != -1) )
			{
				deepOpts.suppress_notification = false;
			}
			else if( (strArg.find("-prio") != -1) ) // -priority
			{
				if(iArg + 1 >= argc) {
					fprintf(stderr, "-priority argument needs a value\n");
					printUsage();
				}
				deepOpts.priority = atoi(argv[++iArg]);
			}
			else if ( (strArg.find("-dorecov") != -1) )
			{
				shallowOpts.doRecovery = true;
			}
			else if ( parsePreservedArgs( strArg, iArg, argc, argv,
						shallowOpts) )
			{
				// No-op here
			}
			else
			{
				fprintf( stderr, "ERROR: unknown option %s\n", strArg.Value() );
				printUsage();
			}
		}
	}

	if (shallowOpts.primaryDagFile == "")
	{
		fprintf( stderr, "ERROR: no dag file specified; aborting.\n" );
		printUsage();
	}

	if (deepOpts.doRescueFrom < 0)
	{
		fprintf( stderr, "-dorescuefrom value must be non-negative; aborting.\n");
		printUsage();
	}
}
コード例 #14
0
void HTTPServer::onUrlRequested ( MyString req, SOCKET sock )
{
	if ( req.find ( ".." ) !=-1 ||
	     req.find ( "/.ht" ) !=-1 || req.endsWith ( "~" ) ) {
		// evil hacker trying to read non-wwwhome or secret file
		errorReport ( sock, "403", "Forbidden",
		              "You don't have permission to access the requested URL." );
	} else {
		MyString path = req;
		MyFile f ( path );
		if ( f.isDirectory() && !path.endsWith ( "/" ) ) {
			// redirect browser if referring to directory without final '/'
			path += "/";
		}

		if ( f.isDirectory() ) {
#if defined(FULLDEBUG) || defined(DEBUG)
			mLog ( "Is a directory: " + path );
#endif
			// if directory, implicitly add 'index.html'
			string header;
			header =  ( string ) "HTTP/1.1 200 OK\r\n"
			          + "Content-Type: text/html\r\n";

			string length = "Content-Length: ";

			string html_header = "<html><body>";
			// out all files here
			string files;
			getDirFiles ( path, &files );

			string html_footer = "</body></html>\r\n\r\n";
			string data = html_header + files + html_footer;


			//count content-length.
			stringstream sstm;
			sstm << data.length();
			length += sstm.str() + "\r\n\r\n";

			data = header + length + html_header + files + html_footer;

			int n = write ( sock, data.c_str(), data.length() +1 );
			if ( n < 0 ) {
				mLog ( "ERROR writing to socket" );
				exit ( 1 );
			}
#ifdef FULLDEBUG
			mLog ( "Wrote: " + data );
#endif

		} else {
			try {
				// send files

				MyString temp;
				temp = ( string ) "HTTP/1.0 200 OK\r\n";
				temp += 		"Content-Type: " + guessContentType ( path ) + "\r\n";


				string data;
				parseFile ( sock, path, &data ); // send raw file

				//count content-length.
				string length = "Content-Length: ";
				stringstream sstm;
				sstm << data.length();
				length += sstm.str() + "\r\n\r\n";

				temp += length + data;

				int n = write ( sock, temp.c_str(), temp.length() );
				if ( n < 0 ) {
					mLog ( "ERROR writing to socket" );
					exit ( 1 );
				}
#if defined(DEBUG) || defined(FULLDEBUG)
				mLog ( "200 OK" );
#endif
			} catch ( ... ) {
				// file not found
				errorReport ( sock, "404", "Not Found",
				              "The requested URL was not found on this server." );
			}//try-catch
		}//else

	}//else
}