Пример #1
0
// remove environment variable(s) or aliases
int unset_cmd( int argc, char **argv )
{
    char *arg;
    int i, rval = 0;
    long fUnset;
    PCH pchList;

    // set the pointer to either the environment or the alias list
    if ( _stricmp( gpInternalName, UNSET_COMMAND ) == 0 )  {

        pchList = 0L;

    } else
        pchList = glpAliasList;

    // strip leading switches
    if (( GetSwitches( argv[1], "MQR", &fUnset, 1 ) != 0 ) || ( first_arg( argv[1] ) == NULL ))
        return ( usage(( pchList == glpAliasList ) ? UNALIAS_USAGE : UNSET_USAGE ));

    // check for master environment set
    if (( pchList == 0L ) && ( fUnset & UNSET_MASTER ))
        pchList = glpMasterEnvironment;

    // read environment or alias file(s)
    if ( fUnset & UNSET_READ )
        return ( SetFromFile( argv[1], pchList, 1 ));

    for ( i = 0; (( arg = ntharg( argv[1], i )) != NULL ); i++ ) {

        if ( _stricmp( arg, "*" ) == 0 ) {

            // wildcard kill - null the environment or alias list
            if ( pchList == 0L )
                pchList = glpEnvironment;
            pchList[0] = '\0';
            pchList[1] = '\0';
            break;
        }

        // kill the variable or alias
        if ( get_list( arg, pchList ) == 0L ) {

            // check for "quiet" switch
            if ( fUnset & UNSET_QUIET )
                rval = ERROR_EXIT;
            else
                rval = error((( pchList == glpAliasList ) ? ERROR_4DOS_NOT_ALIAS : ERROR_4DOS_NOT_IN_ENVIRONMENT ), arg );

        } else if ( add_list( arg, pchList ) != 0)
            rval = ERROR_EXIT;
    }

    return rval;
}
Пример #2
0
/**
 *
 *  Query class values of subkeys at 
 *  HKEY_LOCAL_MACHINE\System\ControlSet00X\Control\Lsa
 *
 */
BOOL SystemKey::SetKey (std::wstring param) {
  switch (dwKeyType) {
    case AUTH_REGISTRY : {
      return SetFromRegistry ();
    }
    case AUTH_PASSWORD : {
      return SetFromPassword (param);
    }
    case AUTH_FILE : {
      return SetFromFile (param);
    }
    default : {
      return SetFromRegistry ();
    }
  }
}
Пример #3
0
// create or display environment variables or aliases
int set_cmd( int argc, char **argv )
{
    char *arg;
    long fSet;
    PCH feptr, pchList;
    char szBuffer[CMDBUFSIZ];

    init_page_size();

    // set the pointer to either the environment or the alias list
    if ( _stricmp( gpInternalName, SET_COMMAND ) == 0 )  {

        pchList = 0L;

    } else
        pchList = glpAliasList;

    // strip leading switches
    if (( GetSwitches( argv[1], "AMPR", &fSet, 1 ) != 0) || (( fSet & SET_READ ) && ( first_arg( argv[1] ) == NULL )))
        return ( usage(( pchList == glpAliasList ) ? ALIAS_USAGE : SET_USAGE ));

    // check for master environment set
    if (( pchList == 0L ) && ( fSet & SET_MASTER ))
        pchList = glpMasterEnvironment;

    // read environment or alias file(s)
    if ( fSet & SET_READ )
        return ( SetFromFile( argv[1], pchList, 0 ));

    // pause after each page
    if ( fSet & SET_PAUSE ) {
        gnPageLength = GetScrRows();
    }

    if ( first_arg( argv[1] ) == NULL ) {

        if ( pchList == 0L )
            pchList = glpEnvironment;

        // print all the variables or aliases
        for ( feptr = pchList; ( *feptr != '\0' ); feptr = next_env( feptr ) ) {
            more_page( feptr, 0 );
        }

        if ( pchList == glpEnvironment ) {

            if (( arg = get_list( BEGINLIBPATH, pchList )) != 0L ) {
                sprintf( szBuffer, FMT_TWO_EQUAL_STR, BEGINLIBPATH, arg );
                more_page( szBuffer, 0 );
            }

            if (( arg = get_list( ENDLIBPATH, pchList )) != 0L ) {
                sprintf( szBuffer, FMT_TWO_EQUAL_STR, ENDLIBPATH, arg );
                more_page( szBuffer, 0 );
            }
        }

        // return an error message if no aliases exist
        // just return if no environment variables exist
        return (( feptr == glpAliasList ) ? error( ERROR_4DOS_NO_ALIASES, NULL ) : 0 );
    }

    if ( fSet & SET_EXPRESSION ) {

        if (( arg = strchr( argv[1], '=' )) != NULL )
            arg = skipspace( ++arg );
        else
            arg = argv[1];

        evaluate( arg );
        if ( cv.bn < 0 )
            qputs( arg );

        // create/modify/delete a variable
        return (( arg == argv[1] ) ? 0 : add_list( argv[1], pchList ));
    }

    // display the current variable or alias argument?
    // (setting environment vars requires a '='; it's optional with aliases)
    if ((( arg = strchr( argv[1], '=' )) == NULL ) && (( pchList == 0L ) || ( ntharg( argv[1], 1 ) == NULL ))) {

        if (( feptr = get_list( argv[1], pchList )) == 0L ) {
            return ( error((( pchList == glpAliasList ) ? ERROR_4DOS_NOT_ALIAS : ERROR_4DOS_NOT_IN_ENVIRONMENT),argv[1]));
        }

        printf( FMT_FAR_STR_CRLF, feptr );
        return 0;
    }

    // create/modify/delete a variable or alias
    return ( add_list( argv[1], pchList ));
}
Пример #4
0
// remove environment variable(s) or aliases
int _fastcall __Unset( LPTSTR pszCmdLine, char _far *pchList )
{
	register LPTSTR pszArg;
	register int i, nReturn = 0;
	long fUnset;
	TCHAR _far *lpszVars;

	// strip leading switches
	if (( GetSwitches( pszCmdLine, "MQR", &fUnset, 1 ) != 0 ) || ( first_arg( pszCmdLine ) == NULL ))
		return USAGE_ERR;

	// check for master environment set
	if (( pchList == glpEnvironment ) && ( fUnset & UNSET_MASTER ))
		pchList = glpMasterEnvironment;

	// read environment or alias file(s)
	if ( fUnset & UNSET_READ )
		return ( SetFromFile( pszCmdLine, pchList, ( fUnset & ( UNSET_DEFAULT | UNSET_SYSTEM | UNSET_USER | UNSET_VOLATILE )) | 1 ));

	for ( i = 0; (( pszArg = ntharg( pszCmdLine, i )) != NULL ); i++ ) {


		if ( _stricmp( pszArg, _TEXT("*") ) == 0 ) {

			// wildcard kill - null the environment or alias list
			pchList[0] = _TEXT('\0');
			pchList[1] = _TEXT('\0');
			break;

		} else if ( strpbrk( pszArg, _TEXT("*?[") ) != NULL ) {

			// wildcard delete!
			lpszVars = pchList;

			while ( *lpszVars ) {

				TCHAR szVarName[128];

				sscanf_far( lpszVars, _TEXT("%127[^=]"), szVarName );

				// treat it like a "unset varname*"
				if (( szVarName[0] ) && ( wild_cmp( pszArg, szVarName, FALSE, TRUE ) == 0 )) {

					// got a match -- remove it
					if ( add_list( szVarName, pchList ) != 0 ) {
						// check for "quiet" switch
						nReturn = (( fUnset & UNSET_QUIET ) ? ERROR_EXIT : ERROR_NOT_IN_LIST );
					}

				} else
					lpszVars = next_env( lpszVars );
			}

		} else {

			// kill the variable or alias
			if ( get_list( pszArg, pchList ) == 0L ) {

				// check for "quiet" switch
				if ( fUnset & UNSET_QUIET )
					nReturn = ERROR_EXIT;
				else
					nReturn = ERROR_NOT_IN_LIST;

			} else if ( add_list( pszArg, pchList ) != 0 )
				nReturn = ERROR_EXIT;
		}

		// remove argument so it won't appear in error list
		if ( nReturn == 0 ) {
			strcpy( gpNthptr, skipspace( gpNthptr + strlen( pszArg )));
			i--;
		}
	}

	return nReturn;
}
Пример #5
0
// create or display environment variables or aliases
static int _fastcall __Set( LPTSTR pszCmdLine, TCHAR _far * pchList )
{
	LPTSTR pszArg;
	long fSet = 0L;
	TCHAR _far *lpszVars;

	init_page_size();

	// set the pointer to the environment, alias, or function list

	// strip leading switches
	if (( pszCmdLine != NULL ) && ( *pszCmdLine == gpIniptr->SwChr )) {
		if ( GetSwitches( pszCmdLine, "AMPR", &fSet, 1 ) != 0 )
			return USAGE_ERR;
	}

	// check for master environment set
	if (( pchList == glpEnvironment ) && ( fSet & SET_MASTER ))
		pchList = glpMasterEnvironment;

	// read environment or alias file(s)
	if ( fSet & SET_READ )
		return ( SetFromFile( pszCmdLine, pchList, fSet & ( SET_DEFAULT | SET_SYSTEM | SET_USER | SET_VOLATILE )));

	if ( setjmp( cv.env ) == -1 )
		return CTRLC;

	// pause after each page
	if ( fSet & SET_PAUSE ) {
		gnPageLength = GetScrRows();
	}

	if (( pszCmdLine == NULL ) || ( *(pszCmdLine = skipspace( pszCmdLine )) == _TEXT('\0'))) {

		// print all the variables or aliases
		for ( lpszVars = pchList; ( *lpszVars != _TEXT('\0') ); lpszVars = next_env( lpszVars ) ) {

			more_page( lpszVars, 0 );
		}

		// return an error if no entries exist
		return (( lpszVars == pchList ) ? ERROR_LIST_EMPTY : 0 );
	}

	if ( fSet & SET_EXPRESSION ) {

		if (( pszArg = strchr( pszCmdLine, _TEXT('=') )) != NULL ) {

			if (( pszArg > pszCmdLine ) && ( strchr( _TEXT("+-*/%&^|><"), pszArg[-1] ) != NULL )) {

				TCHAR szBuf[256];

				// it's an assignment operator ("set /a test+=2")
				sscanf( pszCmdLine, _TEXT(" %[^ +-*/%&^|><=]"), szBuf );
				strcpy( pszArg, pszArg+1 );

				strins( pszCmdLine, _TEXT("=") );
				strins( pszCmdLine, szBuf );
				pszArg = pszCmdLine + strlen( szBuf ) + 1;

			} else
				pszArg = skipspace( pszArg+1 );

		} else
			pszArg = pszCmdLine;
		StripQuotes( pszArg );

		evaluate( pszArg );
		if ( cv.bn < 0 ) {
			qputs( pszArg );
			crlf();
		}

		// create/modify/delete a variable
		return (( pszArg == pszCmdLine ) ? 0 : add_list( pszCmdLine, pchList ));
	}

	// display the current variable or alias argument?
	// (setting environment vars requires a '='; it's optional with aliases)
	if ((( pszArg = strchr( pszCmdLine, _TEXT('=') )) == NULL ) && (( pchList == 0L ) || ( ntharg( pszCmdLine, 0x8001 ) == NULL ))) {

		if (( lpszVars = get_list( pszCmdLine, pchList )) == 0L ) {

			return ERROR_NOT_IN_LIST;
		}

		printf( FMT_FAR_STR_CRLF, lpszVars );
		return 0;
	}

	// create/modify/delete a variable or alias
	return ( add_list( pszCmdLine, pchList ));
}