Ejemplo n.º 1
0
/**
 * Get attributes from an open file
 *
 * This method is called instead of the getattr() method if the
 * file information is available.
 *
 * Currently this is only called after the create() method if that
 * is implemented (see above).  Later it may be called for
 * invocations of fstat() too.
 *
 */
int nphfuse_fgetattr(const char *path, struct stat *statbuf, struct fuse_file_info *fi)
{
    log_msg("Into fgetattr.\n");
    npheap_store *inode = NULL;
    char dir[236];
    char filename[128];

    if(strcmp(path,"/")==0){
        inode = getRootDirectory();
        if(inode==NULL)
        {
            log_msg("Root directory not found in getattr.\n");
            return -ENOENT;
        }else{
            log_msg("Everything worked fine\n");
            memcpy(statbuf, &inode->mystat, sizeof(struct stat));
            return 0;
        }
    }

    inode = retrieve_inode(path);
    if(inode==NULL){
        return -ENOENT;
    }

    log_msg("Worked fine\n");
    memcpy(statbuf, &inode->mystat, sizeof(struct stat));
    return 0;
}
Ejemplo n.º 2
0
/** Get file attributes.
 *
 * Similar to stat().  The 'st_dev' and 'st_blksize' fields are
 * ignored.  The 'st_ino' field is ignored except if the 'use_ino'
 * mount option is given.
 */
int nphfuse_getattr(const char *path, struct stat *stbuf){
    // extract_directory_file(dir,filename,path);
    npheap_store *inode = NULL;
    
    if(strcmp(path,"/")==0){
        inode = getRootDirectory();
        if(inode==NULL)
        {
            log_msg("Root directory not found in getattr.\n");
            return -ENOENT;
        }
        else
        {
            log_msg("Assigning root stbuf in getattr\n");
            memcpy(stbuf, &inode->mystat, sizeof(struct stat));
            return 0;
        }
    }

    inode = retrieve_inode(path);

    if(inode == NULL){
        return -ENOENT;
    }

    // else return the proper value
    log_msg("Assigning normal stbuf in getattr\n");
    memcpy(stbuf, &inode->mystat, sizeof(struct stat));
    return 0;
}
Ejemplo n.º 3
0
/** Change the owner and group of a file */
int nphfuse_chown(const char *path, uid_t uid, gid_t gid){
    log_msg("Entry into CHOWN.\n");
    npheap_store *inode = NULL;
    struct timeval currTime;

    if(strcmp (path,"/")==0){
        log_msg("Calling getRootDirectory() in CHOWN.\n");
        
        inode = getRootDirectory();
        if(inode==NULL)
        {
            log_msg("Root directory not found. in CHOWN.\n");
            return -ENOENT;
        }
        else
        {
            log_msg("Root directory found. in CHOWN.\n");
            //Check if accessibilty can be given
            int flag = checkAccess(inode);
            //Deny the access
            if(flag == 0){
                return -EACCES;
            }
            //else set correct value
            log_msg("Owner of root  changed in CHOWN.\n", path);
            gettimeofday(&currTime, NULL);
            inode->mystat.st_uid = uid;
            inode->mystat.st_gid = gid;
            inode->mystat.st_ctime = currTime.tv_sec;
            log_msg("Exit from CHOWN.\n");
            return 0;
        }
    }
    
    inode = retrieve_inode(path);
    
    if(inode == NULL){
        log_msg("Couldn't find path - %s - in CHOWN.\n", path);
        return -ENOENT;
    }
    //Check Accessibility
    int flag1 = checkAccess(inode);
    
    //Deny the access
    if(flag1 == 0){
        return -EACCES;
    }
    
    //else set correct value
    log_msg("Owner of path - %s - changed in CHOWN.\n", path);
    gettimeofday(&currTime, NULL);
    inode->mystat.st_uid = uid;
    inode->mystat.st_gid = gid;
    inode->mystat.st_ctime = currTime.tv_sec;
    log_msg("Exit from CHOWN.\n");
    return 0;
}
Ejemplo n.º 4
0
ConfigImpl::ConfigImpl(MemoryPool& p) : ConfigRoot(p), confMessage(p)
{
    // Prepare some stuff

    ConfigFile file(p);
    root_dir = getRootDirectory();
    const int size = FB_NELEM(entries);
    values = FB_NEW(p) ConfigValue[size];

    //string val_sep = ",";
    file.setConfigFilePath(getConfigFilePath());

    // Iterate through the known configuration entries

    for (int i = 0; i < size; i++)
    {
        const ConfigEntry entry = entries[i];
        const string value = getValue(file, entries[i].key);

        if (!value.length())
        {
            // Assign the default value

            values[i] = entries[i].default_value;
            continue;
        }

        // Assign the actual value

        switch (entry.data_type)
        {
        case TYPE_BOOLEAN:
            values[i] = (ConfigValue) asBoolean(value);
            break;
        case TYPE_INTEGER:
            values[i] = (ConfigValue) asInteger(value);
            break;
        case TYPE_STRING:
        {
            const char* src = asString(value);
            char* dst = FB_NEW(p) char[strlen(src) + 1];
            strcpy(dst, src);
            values[i] = (ConfigValue) dst;
        }
        break;
            //case TYPE_STRING_VECTOR:
            //	break;
        }
    }

    if (file.getMessage())
    {
        confMessage = file.getMessage();
    }
}
Ejemplo n.º 5
0
/** Change the access and/or modification times of a file */
int nphfuse_utime(const char *path, struct utimbuf *ubuf){
    log_msg("Into utime.\n");
    npheap_store *temp = NULL;

    if(strcmp(path,"/")==0){
        temp = getRootDirectory();
        if(temp==NULL)
        {
            log_msg("Root directory not found in utime.\n");
            return -ENOENT;
        }
        else
        {
            int flag = checkAccess(temp);
            if(flag==0){
                log_msg("Cannot access in root.\n");
                return - EACCES;
            }

            // Set from ubuf
            if(ubuf->actime){
                temp->mystat.st_atime = ubuf->actime;
            }
            if(ubuf->modtime){
                temp->mystat.st_mtime = ubuf->modtime;
            }
            log_msg("Ubuf ran successfully.! \n");
            return 0;
        }
    }

    temp = retrieve_inode(path);

    if(temp==0){
        log_msg("Cannot find the inode in ubuf.\n");
        return -ENOENT;
    }

    int flag1 = checkAccess(temp);
    if(flag1==0){
        log_msg("Cannot access the asked inode.\n");
        return - EACCES;
    }

    if(ubuf->actime){
        temp->mystat.st_atime = ubuf->actime;
    }
    if(ubuf->modtime){
        temp->mystat.st_mtime = ubuf->modtime;
    }
    log_msg("Ubuf ran successfully.! \n");
    return 0;

}
WidgetErrorType WidgetDigSignValidation::updateInstallationPaths( const QString& processUid )
{
    if( processUid.isEmpty() )
        return EErrorDigSigValidationGeneral;

    QString rootDirectory = m_WidgetInfo[ EPropertyInstallDirectory ].toString();
    QString rootDir = getRootDirectory( rootDirectory, processUid );
    if(rootDir.isEmpty() || rootDir.isNull() )
        return EErrorFileSystemPermissionDenied;
    
    m_WidgetInfo[ EPropertyInstallDirectory ] = rootDir;
    m_WidgetInfo[ EPropertySettingsDirectory ]  = DefaultDrive + QDir::separator() + PrivateDirectory + QDir::separator() + processUid + QDir::separator() + DataFolderName; //DataPath;

    return EErrorNone;
}
Ejemplo n.º 7
0
//Allocate the superblock and the inode
static void initialAllocationNPheap(void){
    uint64_t offset = 1;
    npheap_store *npheap_dt = NULL;
    char *block_dt = NULL;
    npheap_store *head_dir = NULL;


    npheap_fd = open(nphfuse_data->device_name, O_RDWR);
    log_msg("Allocation started for %d.\n", offset);

    if(npheap_getsize(npheap_fd, offset) == 0){
        log_msg("Allocating root block into NPHeap!\n");
        block_dt = (char *)npheap_alloc(npheap_fd,offset, 8192);

        if(block_dt == NULL){
            log_msg("Allocation of root block failed.\n");
            return;
        }
        memset(block_dt,0, npheap_getsize(npheap_fd, offset));
        memset(blk_array,0, sizeof(char *) * 9999);
        memset(&dt_link,0,sizeof(dt_link));
    }

    log_msg("Allocation done for npheap %d.\n", npheap_getsize(npheap_fd, offset));
    for(offset = 2; offset < 502; offset++){
        //log_msg("Inode allocation for %d offset\n", offset);
        if(npheap_getsize(npheap_fd, offset)==0){
            block_dt = npheap_alloc(npheap_fd, offset, BLOCK_SIZE);
            memset(block_dt, 0, npheap_getsize(npheap_fd, offset));
        }
        log_msg("Inode allocation for %d offset and %d size\n", offset,(npheap_getsize(npheap_fd, offset)));
    }

    head_dir = getRootDirectory();
    log_msg("Assigning stat values\n");
    strcpy(head_dir->dirname, "/");
    strcpy(head_dir->filename, "/");
    head_dir->mystat.st_ino = inode_off;
    inode_off++;
    head_dir->mystat.st_mode = S_IFDIR | 0755;
    head_dir->mystat.st_nlink = 2;
    head_dir->mystat.st_size = npheap_getsize(npheap_fd,1);
    head_dir->mystat.st_uid = getuid();
    head_dir->mystat.st_gid = getgid();

    return;
}
Ejemplo n.º 8
0
/** File open operation
 *
 * No creation, or truncation flags (O_CREAT, O_EXCL, O_TRUNC)
 * will be passed to open().  Open should check if the operation
 * is permitted for the given flags.  Optionally open may also
 * return an arbitrary filehandle in the fuse_file_info structure,
 * which will be passed to all file operations.
 *
 * Changed in version 2.2
 */
int nphfuse_open(const char *path, struct fuse_file_info *fi){
    struct timeval currTime;
    npheap_store *temp = NULL;

    //Check for root directory
    if(strcmp(path,"/")==0){
        temp = getRootDirectory();
        if(temp==NULL)
        {
            log_msg("Root directory not found in open.\n");
            return -ENOENT;
        }
        else
        {
            int flag = checkAccess(temp);

            //If cannot access
            if(flag == 0){
                log_msg("Root access denied.\n");
                return -EACCES;
            }
            // Worked fine
            log_msg("Access granted to root.\n");
            return 0;
        }
    }

    temp = retrieve_inode(path);
    if(temp == NULL){
        return -ENOENT;
    }

    int flag1 = checkAccess(temp);

    //if cannot access
    if(flag1 == 0){
        log_msg("Access denied.\n");
        return -EACCES;
    }
    //Everything worked fine
    fi->fh = temp->mystat.st_ino;
    gettimeofday(&currTime, NULL);
    temp->mystat.st_atime = currTime.tv_sec;
    return 0;
}
Ejemplo n.º 9
0
/** Open directory
 *
 * This method should check if the open operation is permitted for
 * this directory
 *
 * Introduced in version 2.3
 */
int nphfuse_opendir(const char *path, struct fuse_file_info *fi){
    // char *filename, *dir;
    // extract_directory_file(&dir,&filename,path);
    npheap_store *inode = NULL;
    log_msg("Entry into OPENDIR.\n");
    if(strcmp (path,"/")==0){
        inode = getRootDirectory();
        if(inode==NULL)
        {
            log_msg("Root directory not found in opendir.\n");
            return -ENOENT;
        }
        else
        {
            //Check if accessibilty can be given
            int flag = checkAccess(inode);
            //Deny the access
            log_msg("Root access %d (if 1 then yes)",flag);
            if(flag == 0){
                return -EACCES;
            }
            return 0;
        }
    }

    inode = retrieve_inode(path);

    if(inode == NULL){
        log_msg("Couldn't find path - %s - in OPENDIR.\n", path);
        return -ENOENT;
    }
    //Check Accessibility
    int flag1 = checkAccess(inode);

    //Deny the access
    log_msg("Normal access %d (if 1 then yes)",flag1);
    if(flag1 == 0){
        return -EACCES;
    }
    //else return correct value
    log_msg("Exit into OPENDIR.\n");
    return 0;
}
Ejemplo n.º 10
0
int nphfuse_access(const char *path, int mask){

    npheap_store *inode = NULL;
    
    if(strcmp(path,"/")==0){
        inode = getRootDirectory();
        if(inode==NULL)
        {
            log_msg("Root directory not found in access.\n");
            return -ENOENT;
        }
        else
        {
            log_msg("Checking Access of root\n");
            int flag = checkAccess(inode);
            if(flag==0){
                log_msg("Cannot access the directory\n");
                return -EACCES;
            }
            return 0;
        }
    }

    inode = retrieve_inode(path);

    if(inode == NULL){
        return -ENOENT;
    }
    int flag = checkAccess(inode);
    if(flag==0){
        log_msg("Cannot access the directory\n");
        return -EACCES;
    }
    
    return 0;
}
Ejemplo n.º 11
0
void ossimRpfToc::buildTocEntryList(ossimRpfHeader* rpfHeader)
{
   if(traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << "ossimRpfToc::buildTocEntryList: entered.....\n";
   }
   std::ifstream in(m_filename.c_str(), std::ios::in | std::ios::binary);

   if(!in)
   {
      if(traceDebug())
      {
         ossimNotify(ossimNotifyLevel_DEBUG)
            << "ossimRpfToc::buildTocEntryList: invalid input leaving..... " << std::endl;
      }
      return;
   }
   
   if(rpfHeader)
   {
      if(traceDebug())
      {
         rpfHeader->print(ossimNotify(ossimNotifyLevel_DEBUG));
      }
      
      deleteTocEntryList();
      ossimRpfBoundaryRectSectionSubheader *boundaryRect =
         rpfHeader->getNewBoundaryRectSectSubheader(in);

      if(boundaryRect)
      {
         if(traceDebug())
         {
            ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG: Got boundary rect\n";
         }
         std::streamoff current = in.tellg();

         // they give the offset from the
         // end of the boundary subheader to the start of the 
         // entry table.  We have to create an absolute
         // offset.
         current += boundaryRect->getTableOffset();

         // take to the start of the table entries
         in.seekg(current, ios::beg);
         allocateTocEntryList(boundaryRect->getNumberOfEntries());

         // now we can read the entries
         if(m_tocEntryList.size() > 0)
         {
            for(ossim_uint32 index = 0; index < m_tocEntryList.size(); index++)
            {
               m_tocEntryList[index]->parseStream(in, rpfHeader->getByteOrder());
            }
         }
         
         ossimRpfFrameFileIndexSectionSubheader* frameFileIndexHead = rpfHeader->getNewFrameFileIndexSectionSubheader(in);
         // get the offset to the table
         long offsetToIndexSubsection = in.tellg();
         if(frameFileIndexHead)
         {
            ossimRpfFrameFileIndexRecord tempIndexRec;
            ossimRpfPathnameRecord       tempPathNameRec;
            
            ossim_int32 count = frameFileIndexHead->getNumberOfIndexRecords();
            while(count > 0)
            {
               tempIndexRec.parseStream(in, rpfHeader->getByteOrder() );

               // get the path information.  we must seek to a different location
               // within the file.  So we must remember where we currently are at
               std::streamoff currentPosition = in.tellg();
               
               in.seekg(offsetToIndexSubsection + tempIndexRec.getPathnameRecordOffset(), ios::beg);
               tempPathNameRec.parseStream(in, rpfHeader->getByteOrder());

               // We have the root directory where all frame files are subfiles of
//               ossimString rootDirectory(ossimFilename(m_filename.path())+
               // ossimFilename(ossimFilename::thePathSeparator));
               ossimFilename rootDirectory;
               getRootDirectory(rootDirectory);

               // we have the actual path from the root directory to the
               // frame file.  We must separate the two.  There have been
               // occurrences where the path in the A.TOC file
               // is upper case but the path in the directory on the file
               // system is lower case.  This
               // will fool the system in thinking the file does not exist
               // when it actually does.
               ossimString pathToFrameFile( ossimFilename(tempPathNameRec.getPathname()) +
                                              tempIndexRec.getFilename());

               ossimRpfFrameEntry entry(rootDirectory,
                                        pathToFrameFile);
               m_tocEntryList[tempIndexRec.getBoundaryRecNumber()]->setEntry(entry,
                                                                              tempIndexRec.getLocationRowNumber(),
                                                                              tempIndexRec.getLocationColNumber());
               // now go back to where we were
               in.seekg(currentPosition, ios::beg);
               
               --count;
            }
            delete frameFileIndexHead;
            frameFileIndexHead = 0;
         }
      }
      delete boundaryRect;
      boundaryRect = NULL;
   }
   if(traceDebug())
   {
      ossimNotify(ossimNotifyLevel_DEBUG)
         << "ossimRpfToc::buildTocEntryList: leaving....." << std::endl;
   }
}
Ejemplo n.º 12
0
uHTTP::HTTP::StatusCode FileServer::httpRequestRecieved(uHTTP::HTTPRequest *httpReq)
{
    if (isVerbose()) {
        std::string firstHeader;
        std::cout << "> " << httpReq->getRequestLine(firstHeader) <<  std::endl;
        for (uHTTP::HTTPHeaderList::iterator header = httpReq->getHeaders().begin(); header != httpReq->getHeaders().end(); header++) {
            std::cout << "> " << (*header)->getName() << " : " << (*header)->getValue() << std::endl;
        }
    }
    
	if (!httpReq->isGetRequest()) {
    return httpReq->returnBadRequest();
	}

    uHTTP::URI reqUri;
    httpReq->getURI(reqUri);
  
    std::string systemPath;
    systemPath.append(getRootDirectory());
    systemPath.append(reqUri.getPath());
    
    
    std::ifstream contentFs;
    contentFs.open(systemPath.c_str(), std::ifstream::in | std::ifstream::binary);
    if (!contentFs.is_open()) {
        return httpReq->returnNotFound();
    }
    size_t fileSize = (size_t)contentFs.seekg(0, std::ios::end).tellg();
    contentFs.seekg(0, std::ios::beg);
    bool isBinary = false;
    while (contentFs.good()) {
        unsigned char c = contentFs.get();
        if (contentFs.good()) {
            if (c == 0) {
                isBinary = true;
                break;
            }
        }
    }
    contentFs.close();
    
	uHTTP::HTTPResponse httpRes;
	httpRes.setStatusCode(uHTTP::HTTP::OK_REQUEST);
	httpRes.setContentType(isBinary ? "application/octet-stream" : "text/plain");
	httpRes.setContentLength(fileSize);

    if (verboseMode) {
        std::cout << "< " << httpRes.getFirstLine() << std::endl;
        for (uHTTP::HTTPHeaderList::iterator header = httpRes.getHeaders().begin(); header != httpRes.getHeaders().end(); header++) {
            std::cout << "< " << (*header)->getName() << " : " << (*header)->getValue() << std::endl;
        }
    }
    
	httpReq->post(&httpRes, true);

    if (httpReq->isHeadRequest()) {
      return uHTTP::HTTP::OK_REQUEST;
    }
    
    uHTTP::HTTPSocket *httpSocket = httpReq->getSocket();
    
    contentFs.open(systemPath.c_str(), std::ifstream::in | std::ifstream::binary);
    if (contentFs.is_open()) {
        while (contentFs.good()) {
            unsigned char c = contentFs.get();
            if (contentFs.good()) {
                httpSocket->post(c);
                if (isVerbose())
                    std::cout << c;
            }
        }
    }
    contentFs.close();

    return uHTTP::HTTP::OK_REQUEST;
}