/* ---------------------------------------------------------------------- */ static rc_t open_xml_then_run() { rc_t rc; rc = VFSManagerMakePath (options.vfsmgr, &options.xmlpath, "%s", options.xmlstr); if (rc) PLOGERR (klogInt, (klogInt, rc, "failed to create path for '$(P)'", "P=%s", options.xmlstr)); else { rc = VFSManagerOpenFileRead (options.vfsmgr, &options.xml, options.xmlpath); if (rc) LOGERR (klogErr, rc, "Failed to open output directoryCopycat XML file"); else { rc = open_root_then_run (); } VPathRelease (options.xmlpath); } return rc; }
static rc_t tokenize_file_and_progname_into_argv( const char * filename, const char * progname, int * argc, char *** argv ) { rc_t rc2, rc = 0; VFSManager *vfs_mgr; ( *argv ) = NULL; ( *argc ) = 0; rc = VFSManagerMake ( &vfs_mgr ); if ( rc != 0 ) LOGERR( klogInt, rc, "VFSManagerMake() failed" ); else { VPath * vfs_path; rc = VFSManagerMakePath ( vfs_mgr, &vfs_path, "%s", filename ); if ( rc != 0 ) LOGERR( klogInt, rc, "VPathMake() failed" ); else { struct KFile const *my_file; rc = VFSManagerOpenFileRead ( vfs_mgr, &my_file, vfs_path ); if ( rc != 0 ) LOGERR( klogInt, rc, "VFSManagerOpenFileRead() failed" ); else { tokenzr *t; uint64_t pos = 0; char buffer[ 4096 + 1 ]; size_t num_read; rc = make_tokenzr( &t, argc, argv ); if ( rc != 0 ) LOGERR( klogInt, rc, "make_tokenzr() failed" ); else { if ( progname != NULL ) rc = add_string_to_argv( t, progname, string_size( progname ) ); if ( rc == 0 ) { do { rc = KFileRead ( my_file, pos, buffer, ( sizeof buffer ) - 1, &num_read ); if ( rc != 0 ) LOGERR( klogInt, rc, "KFileRead() failed" ); else if ( num_read > 0 ) { buffer[ num_read ] = 0; rc = tokenize_buffer( t, buffer, num_read ); if ( rc != 0 ) LOGERR( klogInt, rc, "tokenize_buffer() failed" ); pos += num_read; } } while ( rc == 0 && num_read > 0 ); } if ( rc == 0 && t->used > 0 ) { rc = add_token_to_argv( t ); if ( rc != 0 ) LOGERR( klogInt, rc, "add_token_to_argv() failed" ); } free_tokenzr( t ); } rc2 = KFileRelease ( my_file ); if ( rc2 != 0 ) LOGERR( klogInt, rc2, "KFileRelease() failed" ); } rc2 = VPathRelease ( vfs_path ); if ( rc2 != 0 ) LOGERR( klogInt, rc2, "VPathRelease() failed" ); } rc2 = VFSManagerRelease ( vfs_mgr ); if ( rc2 != 0 ) LOGERR( klogInt, rc2, "VFSManagerRelease() failed" ); } return rc; }
/* return configured password as ASCIZ * opertates on vfs/kfs/kfg objects, not kdb objects */ static rc_t KDBOpenFileGetPassword (char * pw, size_t pwz) { VFSManager * mgr; rc_t rc; assert (pw); assert (pwz); pw[0] = '\0'; rc = VFSManagerMake (&mgr); if (rc) ; /* failure to make VFS manager: pass along rc */ else { size_t pwfz; char pwf [4096 + 1]; rc = VFSManagerGetConfigPWFile (mgr, pwf, sizeof (pwf) - 1, &pwfz); if (rc) /* failure to get password file path: tweak rc */ rc = RC (rcDB, rcMgr, rcOpening, rcEncryptionKey, rcNotFound); else { VPath * pwp; pwf [pwfz] = '\0'; /* force to ASCIZ */ #if 0 rc = VPathMakeSysPath (&pwp, pwf); #else rc = VFSManagerMakePath (mgr, &pwp, pwf); #endif if (rc) ; /* failure to construct a path from the string */ else { const KFile * pwf; rc = VFSManagerOpenFileRead (mgr, &pwf, pwp); if (rc) /* failure to open password file */ rc = RC (rcDB, rcMgr, rcOpening, rcEncryptionKey, rcNotOpen); else { size_t z; char pwb [4098]; /* arbitrarily using 4096 as maximum allowed length */ /* at this point we are only getting the password from a * file but in the future if we can get it from a pipe of * some sort we can't count on the ReadAll to really know * if we hit end of file and not just a pause in the * streaming. VFS/KFS 2 will have to fix this somehow */ rc = KFileReadAll (pwf, 0, pwb, sizeof pwb, &z); if (rc) ; /* failure to read password file: pass along rc */ else { /* trim off EOL if present */ char * pc; pwb[z] = '\0'; /* force ASCIZ */ pc = string_chr (pwb, z, '\r'); if (pc) { *pc = '\0'; z = 1 + pc - pwb; } pc = string_chr (pwb, z, '\n'); if (pc) { *pc = '\0'; z = 1 + pc - pwb; } if (z == 0) rc = RC (rcDB, rcMgr, rcOpening, rcEncryptionKey, rcTooShort); else if (pwz < z) /* pwz came in as 4096 */ rc = RC (rcDB, rcMgr, rcOpening, rcEncryptionKey, rcTooLong); else { memmove (pw, pwb, z+1); } } KFileRelease (pwf); } VPathRelease (pwp); } } VFSManagerRelease (mgr); } return rc; }
static rc_t nenctool (const char * srcstr, const char * dststr, bool force) { VFSManager * mgr; rc_t rc; rc = VFSManagerMake (&mgr); if (rc) LOGERR (klogInt, rc, "failed to create file system manager"); else { VPath * srcpath; rc = VFSManagerMakePath (mgr, &srcpath, "%s", srcstr); if (rc) PLOGERR (klogErr, (klogErr, rc, "Failed to parse source path '$(path)'", "path=%s", srcstr)); else { VPath * dstpath; rc = VFSManagerMakePath (mgr, &dstpath, "%s", dststr); if (rc) PLOGERR (klogErr, (klogErr, rc, "Failed to parse destination path '$(path)'", "path=%s", dststr)); else { const KFile * srcfile; rc = VFSManagerOpenFileRead (mgr, &srcfile, srcpath); if (rc) PLOGERR (klogErr, (klogErr, rc, "Failed to open source path '$(path)'", "path=%s", srcstr)); else { KFile * dstfile; rc = VFSManagerCreateFile (mgr, &dstfile, false, 0666, kcmParents | (force ? kcmInit : kcmCreate), dstpath); if (rc) PLOGERR (klogErr, (klogErr, rc, "failed to open destination path '$(path)'", "path=%s", dststr)); else { rc = copy_file (srcstr, dststr, srcfile, dstfile); if (rc) { PLOGERR (klogErr, (klogErr, rc, "failed to copy '$(S)' to '$(D)'", "S=%s,D=%s", srcstr, dststr)); VFSManagerRemove (mgr, true, dstpath); } KFileRelease (dstfile); } KFileRelease (srcfile); } VPathRelease (dstpath); } VPathRelease (srcpath); } VFSManagerRelease (mgr); } return rc; }