Example #1
0
/*
 * This routine descends through a path to a directory, logging to
 * every cell it encounters along the way.
 */
static int auth_to_path(char *path)
{
  int status = AKLOG_SUCCESS;
  int auth_to_cell_status = AKLOG_SUCCESS;

  char *nextpath;
  char pathtocheck[MAXPATHLEN + 1];
  char mountpoint[MAXPATHLEN + 1];

  char *cell;
  char *endofcell;

  /* Initialize */
  if (path[0] == DIR)
    strcpy(pathtocheck, path);
  else
    {
      if (getcwd(pathtocheck, sizeof(pathtocheck)) == NULL)
	{
	  fprintf(stderr, "Unable to find current working directory:\n");
	  fprintf(stderr, "%s\n", pathtocheck);
	  fprintf(stderr, "Try an absolute pathname.\n");
	  exit(AKLOG_BADPATH);
	}
      else
	{
	  strcat(pathtocheck, DIRSTRING);
	  strcat(pathtocheck, path);
	}
    }
  next_path(pathtocheck);

  /* Go on to the next level down the path */
  while (nextpath = next_path(NULL))
    {
      strcpy(pathtocheck, nextpath);
      if (dflag)
	printf("Checking directory %s\n", pathtocheck);
      /*
       * If this is an afs mountpoint, determine what cell from
       * the mountpoint name which is of the form
       * #cellname:volumename or %cellname:volumename.
       */
      if (get_afs_mountpoint(pathtocheck, mountpoint, sizeof(mountpoint)))
	{
	  /* skip over the '#' or '%' */
	  cell = mountpoint + 1;
	  if (endofcell = strchr(mountpoint, VOLMARKER))
	    {
	      *endofcell = '\0';
	      if (auth_to_cell_status = auth_to_cell(cell, NULL))
		{
		  if (status == AKLOG_SUCCESS)
		    status = auth_to_cell_status;
		  else if (status != auth_to_cell_status)
		    status = AKLOG_SOMETHINGSWRONG;
		}
	    }
	}
      else
	{
	  struct stat st;

	  if (lstat(pathtocheck, &st) < 0)
	    {
	      /*
	       * If we've logged and still can't stat, there's
	       * a problem...
	       */
	      fprintf(stderr, "%s: stat(%s): %s\n", progname,
		      pathtocheck, strerror(errno));
	      return(AKLOG_BADPATH);
	    }
	  else if (!S_ISDIR(st.st_mode))
	    {
	      /* Allow only directories */
	      fprintf(stderr, "%s: %s: %s\n", progname, pathtocheck,
		      strerror(ENOTDIR));
	      return(AKLOG_BADPATH);
	    }
	}
    }

  return(status);
}
Example #2
0
/*
* This routine descends through a path to a directory, logging to
* every cell it encounters along the way.
*/
static int auth_to_path(krb5_context context, char *path)
{
    int status = AKLOG_SUCCESS;
    int auth_to_cell_status = AKLOG_SUCCESS;

    char *nextpath;
    char pathtocheck[MAXPATHLEN + 1];
    char mountpoint[MAXPATHLEN + 1];

    char *cell;
    char *endofcell;

    /* Initialize */
    if (BeginsWithDir(path, TRUE))
        strcpy(pathtocheck, path);
    else
    {
        if (getcwd(pathtocheck, sizeof(pathtocheck)) == NULL)
        {
            fprintf(stderr, "Unable to find current working directory:\n");
            fprintf(stderr, "%s\n", pathtocheck);
            fprintf(stderr, "Try an absolute pathname.\n");
            akexit(AKLOG_BADPATH);
        }
        else
        {
            /* in WIN32, if getcwd returns a root dir (eg: c:\), the returned string
            * will already have a trailing slash ('\'). Otherwise, the string will
            * end in the last directory name */
#ifdef WIN32    
            if(pathtocheck[strlen(pathtocheck) - 1] != BDIR)
#endif  
                strcat(pathtocheck, DIRSTRING);
            strcat(pathtocheck, path);
        }
    }
    next_path(pathtocheck);

    /* Go on to the next level down the path */
    while (nextpath = next_path(NULL))
    {
        strcpy(pathtocheck, nextpath);
        if (dflag)
            printf("Checking directory [%s]\n", pathtocheck);
        /*
        * If this is an afs mountpoint, determine what cell from
        * the mountpoint name which is of the form
        * #cellname:volumename or %cellname:volumename.
        */
        if (get_afs_mountpoint(pathtocheck, mountpoint, sizeof(mountpoint)))
        {
            if(dflag)
                printf("Found mount point [%s]\n", mountpoint);
            /* skip over the '#' or '%' */
            cell = mountpoint + 1;
            if (endofcell = strchr(mountpoint, VOLMARKER))
            {
                *endofcell = '\0';
                if (auth_to_cell_status = auth_to_cell(context, cell, NULL))
                {
                    if (status == AKLOG_SUCCESS)
                        status = auth_to_cell_status;
                    else if (status != auth_to_cell_status)
                        status = AKLOG_SOMETHINGSWRONG;
                }
            }
        }
        else
        {
            struct stat st;

            if (lstat(pathtocheck, &st) < 0)
            {
                /*
                * If we've logged and still can't stat, there's
                * a problem...
                */
                fprintf(stderr, "%s: stat(%s): %s\n", progname,
                         pathtocheck, strerror(errno));
                return(AKLOG_BADPATH);
            }
            else if (!S_ISDIR(st.st_mode))
            {
                /* Allow only directories */
                fprintf(stderr, "%s: %s: %s\n", progname, pathtocheck,
                         strerror(ENOTDIR));
                return(AKLOG_BADPATH);
            }
        }
    }

    return(status);
}
Example #3
0
/* Update cursor to point to next top-level directory to search, if any. */
static int next_directory(vtab_cursor *p_cur)
{
    vtab *p_vt = (vtab*)((sqlite3_vtab_cursor*)p_cur)->pVtab;

    /* Get the next path name in the search list. If there isn't next_path()
     * will return 0, as do we. */
    if (next_path(p_cur) == 0)
    {
        /* No more directories to search. End of result set. */
        p_cur->eof = 1;

        return SQLITE_OK;
    }

    /* Now try to open the directory. If it can be opended, set up the dirent to
    ** return as a row in the rowset.
    */

    /* ZERO-FILL DIRENT: Very important to zero-fill here, otherwise we may have
    ** dirent.fname and/or dirent.name members pointing to invalid addresses
    ** after apr_stat(). Our code depends in being able to check NULL status of
    ** these members, so all pointers must be NULL by default.
    */
    memset(&p_cur->current_node->dirent, 0, sizeof(apr_finfo_t));

    /* Check to see if the directory exists */
    p_cur->status = apr_stat( &p_cur->current_node->dirent, 
                              p_cur->current_node->path, 
                              APR_FINFO_TYPE, p_cur->pool );

    if (p_cur->status != APR_SUCCESS)
    {
        /* Directory does not exist */
        p_cur->eof = 1;

        if (p_vt->base.zErrMsg != NULL)
        {
            sqlite3_free(p_vt->base.zErrMsg);
        }

        printf( "Invalid directory: %s\n", p_cur->current_node->path );

        p_vt->base.zErrMsg = sqlite3_mprintf( "Invalid directory: %s", 
                                              p_cur->current_node->path );

        return SQLITE_ERROR;
    }
    else 
    {
        /* If this entry is a directory, then open it */
        if (p_cur->current_node->dirent.filetype == APR_DIR)
        {
            p_cur->status = apr_dir_open( &p_cur->current_node->dir, 
                                          p_cur->current_node->path, p_cur->pool);

            if (p_cur->status != APR_SUCCESS)
            {
                /* Could not open directory */
                p_cur->eof = 1;
                
                if (p_vt->base.zErrMsg != NULL)
                {
                    sqlite3_free(p_vt->base.zErrMsg);
                }
                
                printf("Could not open directory: %s\n", p_cur->current_node->path );
                
                p_vt->base.zErrMsg = sqlite3_mprintf( "Could not open directory: %s", 
                                                      p_cur->current_node->path );
                
                return SQLITE_ERROR;
            }
        }
        else
        {
            /** Set dir to NULL to indicate that this entry is NOT a
             *  directory. In this case, we have a top-level file, not a
             *  top-level directory. vt_next() will pick up on this and do the
             *  Right Thing.
             */
            p_cur->current_node->dir = NULL;
        }
    }

    /** Move cursor to first row: get the directory information on the top level
     *  directory. 
     */
    apr_stat( &p_cur->current_node->dirent, 
              p_cur->current_node->path, 
              APR_FINFO_DIRENT|APR_FINFO_TYPE|APR_FINFO_NAME, p_cur->pool );

    return SQLITE_OK;
}