Example #1
0
int extl_try_config(const char *fname, const char *cfdir,
                    ExtlTryConfigFn *tryfn, void *tryfnparam,
                    const char *ext1, const char *ext2)
{
    char *files[]={NULL, NULL, NULL, NULL};
    int n=0, ret=EXTL_TRYCONFIG_NOTFOUND, ret2;
    bool search=FALSE, has_ext;
    
    /* Search etcpath only if path is not absolute */
    search=(fname[0]!='/');

    /* Build list of files to look for */
    has_ext=strrchr(fname, '.')>strrchr(fname, '/');

    if(!has_ext){
        if(ext1!=NULL){
            files[n]=extl_scat3(fname, ".", ext1);
            if(files[n]!=NULL)
                n++;
        }

        if(ext2!=NULL){
            files[n]=extl_scat3(fname, ".", ext2);
            if(files[n]!=NULL)
                n++;
        }
    }
    
    if(has_ext || !search){
        files[n]=extl_scopy(fname);
        if(files[n]!=NULL)
            n++;
    }
    
    /* NOTE for future changes: cfdir must not be scanned first for
     * user configuration files to take precedence.
     */

    /* Scan through all possible files */
    if(search){
        ret2=try_etcpath((const char**)&files, tryfn, tryfnparam);
        if(ret==EXTL_TRYCONFIG_NOTFOUND)
            ret=ret2;
        if(ret<0)
            ret=try_dir((const char**)&files, cfdir, tryfn, tryfnparam);
    }else{
        ret=try_dir((const char**)&files, NULL, tryfn, tryfnparam);
    }
    
    while(n>0)
        free(files[--n]);
    
    return ret;
}
Example #2
0
static krb5_error_code
get_from_os_buffer(char *name_buf, unsigned int name_size)
{
    char *prefix = krb5_cc_dfl_ops->prefix;
    unsigned int size;
    char *p;
    DWORD gle;

    SetLastError(0);
    GetEnvironmentVariable(KRB5_ENV_CCNAME, name_buf, name_size);
    gle = GetLastError();
    if (gle == 0)
        return 0;
    else if (gle != ERROR_ENVVAR_NOT_FOUND)
        return ENOMEM;

    if (get_from_registry(HKEY_CURRENT_USER,
                          name_buf, name_size) != 0)
        return 0;

    if (get_from_registry(HKEY_LOCAL_MACHINE,
                          name_buf, name_size) != 0)
        return 0;

    if (get_from_registry_indirect(name_buf, name_size) != 0)
        return 0;

    strncpy(name_buf, prefix, name_size - 1);
    name_buf[name_size - 1] = 0;
    size = name_size - strlen(prefix);
    if (size > 0)
        strcat(name_buf, ":");
    size--;
    p = name_buf + name_size - size;
    if (!strcmp(prefix, "API")) {
        strncpy(p, "krb5cc", size);
    } else if (!strcmp(prefix, "FILE") || !strcmp(prefix, "STDIO")) {
        if (!try_dir(getenv("TEMP"), p, size) &&
            !try_dir(getenv("TMP"), p, size))
        {
            unsigned int len = GetWindowsDirectory(p, size);
            name_buf[name_size - 1] = 0;
            if (len < size - sizeof(APPEND_KRB5CC))
                strcat(p, APPEND_KRB5CC);
        }
    } else {
        strncpy(p, "default_cache_name", size);
    }
    name_buf[name_size - 1] = 0;
    return 0;
}
Example #3
0
static const char *get_tempdir(void)
{
	static const char *tmpdir = NULL;

	if (tmpdir != NULL)
		return tmpdir;

	if (tmpdir == NULL)
		tmpdir = try_dir(getenv("TMPDIR"));
	if (tmpdir == NULL)
		tmpdir = try_dir(getenv("TMP"));
	if (tmpdir == NULL)
		tmpdir = try_dir(getenv("TEMP"));

#ifdef P_tmpdir
	if (tmpdir == NULL)
		tmpdir = try_dir(P_tmpdir);
#endif

	if (tmpdir == NULL)
		tmpdir = try_dir("/tmp");
	if (tmpdir == NULL)
		tmpdir = try_dir("/var/tmp");
	if (tmpdir == NULL)
		tmpdir = try_dir("/usr/tmp");

	if (tmpdir == NULL)
		tmpdir = ".";

	return tmpdir;
}
Example #4
0
File: file.c Project: 8l/aoeui
struct view *text_new(void)
{
	char dir[128], path[128];
	const char *me, *home;
	time_t now = time(NULL);
	struct tm *gmt = gmtime(&now);
	fd_t fd = -1;
	struct view *view;

	if ((home = getenv("HOME"))) {
		sprintf(dir, "%s/.aoeui", home);
		fd = try_dir(path, dir, gmt);
	}
	if (fd < 0 && (me = getenv("LOGNAME"))) {
		sprintf(dir, "/tmp/aoeui-%s", me);
		fd = try_dir(path, dir, gmt);
	}
#if !defined __APPLE__ && !defined BSD
	if (fd < 0 && (me = cuserid(NULL))) {
		sprintf(dir, "/tmp/aoeui-%s", me);
		fd = try_dir(path, dir, gmt);
	}
#endif
	if (fd < 0)
		fd = try_dir(path, "/tmp/aoeui", gmt);
	if (fd < 0)
		fd = try_dir(path, "./aoeui", gmt);

	if (fd < 0)
		view = text_create("* New *", TEXT_EDITOR);
	else {
		view = text_create(path, TEXT_CREATED | TEXT_SCRATCH);
		view->text->fd = fd;
	}
	return view;
}
Example #5
0
/*EXTL_DOC
 * Lookup script \var{file}. If \var{try_in_dir} is set, it is tried
 * before the standard search path.
 */
EXTL_EXPORT
char *extl_lookup_script(const char *file, const char *sp)
{
    const char *files[]={NULL, NULL};
    char* tmp=NULL;
    
    if(file!=NULL){
        files[0]=file;

        if(sp!=NULL)
            try_dir(files, sp, (ExtlTryConfigFn*)try_lookup, &tmp);
        if(tmp==NULL)
            try_etcpath(files, (ExtlTryConfigFn*)try_lookup, &tmp);
    }
    
    return tmp;
}
Example #6
0
static CHAR_TYPE *try_dir( CHAR_TYPE *dir, CHAR_TYPE *prefix )
{
    CHAR_TYPE *         buf;
    size_t              numchars;
    int                 addslash = 0;
    unsigned            number;
    int                 alive;

    /*** Ensure the directory exists ***/
    if( dir[0] != NULLCHAR ) {
        if( __F_NAME(access,_waccess)( dir, F_OK )  ==  -1 ) {
            return( NULL );
        }
    }

    /*** Initialize addslash ***/
    numchars = __F_NAME(_mbslen,wcslen)( dir );
    if( numchars > 0  &&  prefix[0] != STRING( '\\' ) ) {
#ifdef __WIDECHAR__
        if( dir[numchars-1] != L'\\' ) {
#else
        if( _mbccmp( _mbsninc(dir,numchars-1), "\\" ) ) {
#endif
            addslash = 1;
        }
    }

    /*** Ensure the filename wouldn't be too long ***/
    /* dir + slash if needed + prefix + room for unique characters */
    /* strlen is ok for DBCS, since we want the byte count */
    numchars = __F_NAME(strlen,wcslen)( dir )  +  addslash  +  __F_NAME(strlen,wcslen)( prefix )  +  UNIQUE;
    if( numchars > _MAX_PATH )  return( NULL );

    /*** Try to build a unique filename ***/
    buf = malloc( CHARSIZE * (numchars+1) );
    for( number=1,alive=1; alive; number++ ) {
        __F_NAME(strcpy,wcscpy)( buf, dir );
        if( addslash ) {
            __F_NAME(strcat,wcscat)( buf, STRING( "\\" ) );
        }
        __F_NAME(strcat,wcscat)( buf, prefix );
        __F_NAME(utoa,_utow)( number, buf + __F_NAME(strlen,wcslen)(buf), 10 );

        if( __F_NAME(access,_waccess)( buf, F_OK )  !=  0 ) {
            return( buf );
        }
        if( number == 65535u )  alive = 0;
    }

    return( NULL );
}


_WCRTLINK CHAR_TYPE *__F_NAME(_tempnam,_wtempnam)( CHAR_TYPE *dir, CHAR_TYPE *prefix )
{
    CHAR_TYPE *         p;
    CHAR_TYPE *         envp;

    /*** Try the directory given by the TMP environment variable ***/
    envp = __F_NAME(getenv,_wgetenv)( STRING( "TMP" ) );
    if( envp != NULL ) {
        p = try_dir( envp, prefix );
        if( p != NULL )  return( p );
    }

    /*** Try the directory passed to this function (dir) ***/
    if( dir != NULL ) {
        p = try_dir( dir, prefix );
        if( p != NULL )  return( p );
    }

    /*** Try the _P_tmpdir directory (#defined in stdio.h) ***/
    p = try_dir( __F_NAME(_P_tmpdir,_wP_tmpdir), prefix );
    if( p != NULL )  return( p );

    /*** Try the current directory ***/
    p = try_dir( STRING( "" ), prefix );
    if( p != NULL )  return( p );

    return( NULL );
}