Esempio n. 1
0
 /* Access
 *  get access to object
 *
 *  "access" [ OUT ] - return parameter for Unix access mode
 *
 *  "path" [ IN ] - NUL terminated string in directory-native
 *  character set denoting target object
 */
 inline rc_t Access ( uint32_t *access,
    const char *path, ... ) const throw ()
 {
    va_list args;
    va_start ( args, path );
    rc_t rc = KDirectoryVAccess ( this, access, path, args );
    va_end ( args );
    return rc;
 }
Esempio n. 2
0
/* Writable
 *  examines a directory structure for any "lock" files
 */
rc_t KDBWritable ( const KDirectory *dir, const char *path )
{
    uint32_t access;
    rc_t rc;

    /* protect us from bad parameters */
    if (dir == NULL)
        return RC (rcDB, rcPath, rcAccessing, rcDirectory, rcNull);
    if (path == NULL)
        return RC (rcDB, rcPath, rcAccessing, rcPath, rcNull);

    /* we have to be able to check the access if it is to be writable */
    rc = KDirectoryVAccess ( dir, & access, path, NULL );
    if ( rc == 0 )
    {
        /* if there is a lock (or deprecated sealed) file in this directory */
        switch ( KDirectoryPathType ( dir, "%s/lock", path ) )
        {
        case kptFile:
        case kptFile | kptAlias:
            rc = RC ( rcDB, rcPath, rcAccessing, rcLock, rcLocked );
            break;
        case kptNotFound:
            /* much simpler handling for the sealed file */
            switch ( KDirectoryPathType ( dir, "%s/sealed", path ) )
            {
            case kptFile:
            case kptFile | kptAlias:
                rc = RC ( rcDB, rcPath, rcAccessing, rcLock, rcLocked );
                break;
            case kptNotFound:
                /* check if there are no write permissions */
                if ( ( access & 0222 ) == 0 )
                    rc = RC ( rcDB, rcPath, rcAccessing, rcPath, rcReadonly );
                /* else rc is still 0 from VAccess */
            }
            break;
        case kptBadPath:
            /* likely to be a non-driectory or something */
            rc = RC ( rcDB, rcPath, rcAccessing, rcPath, rcInvalid);
            break;
        default:
            /* an illegal type of object named "lock" is in this directory
             * which will block the ability to lock it
             */
            rc = RC ( rcDB, rcPath, rcAccessing, rcPath, rcIncorrect );
        }
    }
    return rc;
}
Esempio n. 3
0
static
rc_t CC extract_action (const KDirectory * dir, const char * path, void * _adata)
{
    rc_t            rc;
    extract_adata * adata;
    KPathType     type;
    char            link	[2 * 4096]; /* we'll truncate? */
    uint32_t	    access;
    rc = 0;
    adata = _adata;

    STSMSG (1, ("extract_action: %s\n", path));

    type = KDirectoryPathType (dir, path);

    if (type & kptAlias)
    {
        rc = KDirectoryVResolveAlias (dir, false, link, sizeof (link),
                                      path, NULL);
        if (rc == 0)
        {
            rc = KDirectoryVAccess (dir, &access, path, NULL);
            if (rc == 0)
            {
                rc = KDirectoryCreateAlias (adata->dir, access, kcmCreate|kcmParents,
                                            link, path);
            }
        }
    }
    else
    {
        switch (type & ~kptAlias)
        {
        case kptNotFound:
            rc = RC (rcExe, rcDirectory, rcAccessing, rcPath, rcNotFound);

            KOutMsg ("%s: %s type kptNotFouns %R\n", __func__, path, rc);

            break;
        case kptBadPath:
            rc = RC (rcExe, rcDirectory, rcAccessing, rcPath, rcInvalid);
            break;
        case kptFile:
            rc = KDirectoryVAccess (dir, &access, path, NULL);
            if (rc == 0)
            {
                const KFile * fin;
                KFile * fout;
                rc = KDirectoryVCreateFile (adata->dir, &fout, false, access,
                                            kcmCreate|kcmParents,
                                            path, NULL);
                if (rc == 0)
                {
                    rc = KDirectoryVOpenFileRead (dir, &fin, path, NULL);
                    if (rc == 0)
                    {
#if USE_SKEY_MD5_FIX
                        /* KLUDGE!!!! */
                        size_t pathz, skey_md5z;
                        static const char skey_md5[] = "skey.md5";

                        pathz = string_size (path);
                        skey_md5z = string_size(skey_md5);
                        if ( pathz >= skey_md5z && strcmp ( & path [ pathz - skey_md5z ], skey_md5 ) == 0 )
                            rc = copy_file_skey_md5_kludge (fin, fout);
                        else
#endif
                            rc = copy_file (fin, fout);
                        KFileRelease (fin);
                    }
                    KFileRelease (fout);
                }
            }
            break;
        case kptDir:
            rc = KDirectoryVAccess (dir, &access, path, NULL);
            if (rc == 0)
            {
                rc = KDirectoryCreateDir (adata->dir, 0700, 
                                          kcmCreate|kcmParents,
                                          path, NULL);
                if (rc == 0)
                {
                    rc = step_through_dir (dir, path, adata->filter, adata->fdata,
                                           extract_action, adata);
                    if (rc == 0)
                        rc = KDirectoryVSetAccess (adata->dir, false, access, 0777, path, NULL);
                }



            }
            break;
        case kptCharDev:
        case kptBlockDev:
        case kptFIFO:
            /* shouldn't get here */
            return 0;
        }
    }

    return rc;
}
Esempio n. 4
0
 inline rc_t Access ( uint32_t *access, const char *path, 
    va_list args ) const throw ()
 { return KDirectoryVAccess ( this, access, path, args ); }