Ejemplo n.º 1
0
rc_t CC Usage (const Args * args)
{
    const char * progname = UsageDefaultName;
    const char * fullpath = UsageDefaultName;
    char const *const file_crypt = de[0] == 'd'
                                   ? "file to decrypt"
                                   : "file to encrypt";
    char const *const dir_crypt  = de[0] == 'd'
                                   ? "directory to decrypt"
                                   : "directory to encrypt";
    const char * const pline[] = {
        file_crypt, NULL,
        "name of resulting file", NULL,
        "directory of resulting file", NULL,
        dir_crypt, NULL
    };

    rc_t rc, orc;

    if (args == NULL)
        rc = RC (rcApp, rcArgv, rcAccessing, rcSelf, rcNull);
    else
        rc = ArgsProgram (args, &fullpath, &progname);

    orc = UsageSummary (progname);
    if (rc == 0)
        rc = orc;

    KOutMsg ("Parameters:\n");
    HelpParamLine ("source-file"          , pline);
    HelpParamLine ("destination-file"     , pline + 2);
    HelpParamLine ("destination-directory", pline + 4);
    HelpParamLine ("directory"            , pline + 6);
    KOutMsg ("\nOptions:\n");
    HelpOptionLine (ALIAS_FORCE, OPTION_FORCE, NULL, ForceUsage);
    CryptOptionLines ();
    HelpOptionsStandard ();

    /* forcing editor alignment */
    /*   12345678901234567890123456789012345678901234567890123456789012345678901234567890*/
    KOutMsg (
        "\n"
        "Details:\n"
        "  All %scryptions are non-destructive until successful. No files are deleted or\n"
        "  replaced until the %scryptions are complete.\n"
        "\n", de, de);

    KOutMsg (
        "  The extension '.ncbi_enc' will be %s when a file is %scrypted.\n"
        "\n", Decrypting ? "removed" : "added", de);

    if (Decrypting) KOutMsg (
            "  NCBI Archive files that contain NCBI database objects will not be decrypted\n"
            "  unless the %s option is used. As these objects can be used without\n"
            "  decryption it is recommended they remain encrypted.\n"
            "\n", OPTION_SRA);
    else KOutMsg (
            "  NCBI Archive files that contain NCBI database objects will not have the\n"
            "  .ncbi_enc extension added.\n\n");


    KOutMsg (
        "  If the only parameter is a file name then it will be replaced by a file that\n"
        "  is %scrypted with a possible changed extension.\n"
        "  \n", de);

    KOutMsg (
        "  If the only parameter is a directory, all files in that directory including\n"
        "  all files in subdirectories will be replaced with a possible change\n"
        "  in the extension.\n"
        "\n");

    KOutMsg (
        "  If there are two parameters  a copy is made but the copy will be %scrypted.\n"
        "  If the second parameter is a directory the new file might have a different\n"
        "  extension. If it is not a directory, the extension will be as given in the\n"
        "  the parameter.\n"
        "\n", de);

    KOutMsg (
        "  Missing directories in the destination path will be created.\n"
        "\n");

    KOutMsg (
        "  Already existing destination files will cause the program to end with\n"
        "  an error and will be left unchanged unless the --%s option is used to\n"
        "  force the files to be overwritten.\n"
        "\n", OPTION_FORCE);

    KOutMsg (
        "Encryption key (file password):\n"
        "  The encryption key or file password is handled by configuration. If not yet\n"
        "  set, this program will fail.\n\n"
        "  You can set the encryption key by running:\n\n"
        "    perl configuration-assistant.perl\n"
        "\n");

    HelpVersion (fullpath, KAppVersion());

    return rc;
}
Ejemplo n.º 2
0
/*  ----------------------------------------------------------------------
 * KMain
 *
 * Figure out what is on the command line
 */
rc_t KMain ( int argc, char *argv [] )
{
    Args * args;
    rc_t rc;

    rc = ArgsMakeAndHandle (&args, argc, argv, 1, Options, sizeof Options / sizeof (OptDef));
    if (rc == 0)
    {
        /* use do {} while; for easy outs */
        do
        {
            const char * pc;
            uint32_t pcount;

            rc = ArgsProgram (args, &full_path, &program_name);
            if (rc)
            {
                PLOGERR (klogFatal,
                         (klogFatal, rc,  "failed to set name to $'(N)'",
                          "N=%s", program_name));
                break;
            }

            rc = ArgsOptionCount (args, OPTION_FORCE, &pcount);
            if (rc)
            {
                LOGERR (klogFatal, rc, "failed to check force option");
                break;
            }
            if (pcount)
            {
                options.force = true;
                options.cm = kcmParents | kcmInit;
            }
            else
            {
                options.force = true;
                options.cm = kcmParents | kcmCreate;
            }

            rc = ArgsOptionCount (args, OPTION_XML, &pcount);
            if (rc)
            {
                LOGERR (klogFatal, rc, "failed to check XML option");
                break;
            }
            if (pcount)
            {
                rc = ArgsOptionValue (args, OPTION_XML, 0, (const void **)&options.xmlstr);
                if (rc)
                {
                    LOGERR (klogFatal, rc, "failed to get XML value");
                    break;
                }
            }
            else
            {
                rc = RC (rcExe, rcArgv, rcParsing, rcParam, rcNull);
                LOGERR (klogFatal, rc, "missing required copycat-xml option");
                MiniUsage(args);
                break;
            }

            rc = ArgsOptionCount (args, OPTION_DIR, &pcount);
            if (rc)
            {
                LOGERR (klogFatal, rc, "failed to check directory option");
                break;
            }
            if (pcount)
            {
                rc = ArgsOptionValue (args, OPTION_DIR, 0, (const void **)&options.dirstr);
                if (rc)
                {
                    LOGERR (klogFatal, rc, "failed to get directory value");
                    break;
                }
            }
            else
            {
                options.dirstr = ".";
            }


            rc = ArgsParamCount (args, &pcount);
            if (rc)
            {
                LOGERR (klogFatal, rc, "failed to count parameters");
                break;
            }
            if (pcount == 0)
            {
                rc = RC ( rcExe, rcArgv, rcReading, rcParam, rcInsufficient );
                LOGERR (klogFatal, rc, "Missing archive parameter");
                MiniUsage (args);
                break;
            }

            {
                uint32_t block;

                block = 1;
                if (pcount > 2)
                    block = pcount - 1;

                VectorInit (&options.pathstr, 0, block);
            }

            rc = ArgsParamValue (args, 0, (const void **)&options.arcstr);
            if (rc)
                LOGERR (klogFatal, rc, "failed to retrieve archive parameter");
            else
            {
                if (pcount == 1)
                {
                    rc = VectorAppend (&options.pathstr, NULL, ".");
                    if (rc)
                        LOGERR (klogFatal, rc, "failed to set default path parameter");
                }
                else
                {
                    uint32_t ix;

                    for (ix = 1; ix < pcount; ++ix)
                    {
                        rc = ArgsParamValue (args, ix, (const void **)&pc);
                        if (rc)
                        {
                            PLOGERR (klogFatal, 
                                     (klogFatal, rc, "unable to extract path parameter '$(K)",
                                      "K=%u", ix));
                            break;
                        }
                        rc = VectorAppend (&options.pathstr, NULL, pc);
                        if (rc)
                        {
                            PLOGERR (klogFatal, 
                                     (klogFatal, rc, "failed to add path '$(P)' to list",
                                      "P=%s", pc));
                            break;
                        }
                    }
                }
            }
            if (rc == 0)
                open_mgr_then_run();

            VectorWhack (&options.pathstr, NULL, NULL);

        } while (0);
        ArgsWhack (args);
    }                
    return rc;
}
Ejemplo n.º 3
0
rc_t CC Usage (const Args * args)
{
    static const char archive[] = "archive";
    const char * progname = UsageDefaultName;
    const char * fullpath = UsageDefaultName;
    rc_t rc;

    if (args == NULL)
        rc = RC (rcApp, rcArgv, rcAccessing, rcSelf, rcNull);
    else
        rc = ArgsProgram (args, &fullpath, &progname);
    if (rc)
        progname = fullpath = UsageDefaultName;

    UsageSummary (progname);

    OUTMSG (("Archive Command:\n"
	     "  All of these options require the next token on the command line to be\n"
	     "  the name of the archive\n\n"));

    KOutMsg ("Options:\n");

    HelpOptionLine (ALIAS_CREATE, OPTION_CREATE, archive, create_usage);
    HelpOptionLine (ALIAS_EXTRACT, OPTION_EXTRACT, archive, extract_usage);
    HelpOptionLine (ALIAS_TEST, OPTION_TEST, archive, test_usage);
    OUTMSG (("\n"
             "Archive:\n"
             "  Path to a file that will/does hold the archive of other files.\n"
             "  This can be a full or relative path.\n"
             "\n"
             "Directory:\n"
	     "  Required for create or extract command, ignored for test command.\n"
             "  This can be a full or relative path.\n"
             "\n"
             "Filters:\n"
	     "  When present these act as include filters.\n"
	     "  Any file name will be included in the extracted files, created archive\n"
	     "  or test operation listing\n"
	     "  Any directory will be included as well as its contents\n"
             "\n"
             "Options:\n"));
    HelpOptionLine (ALIAS_DIRECTORY, OPTION_DIRECTORY, "Directory", directory_usage);
    HelpOptionLine (ALIAS_FORCE, OPTION_FORCE, NULL, force_usage);
    HelpOptionLine (ALIAS_ALIGN, OPTION_ALIGN, "alignment", align_usage);
    HelpOptionLine (ALIAS_LONGLIST, OPTION_LONGLIST, NULL, longlist_usage);

    HelpOptionsStandard ();

    OUTMSG (("\n"
             "Use examples:"
             "\n"
             "  To create an archive named 'example.sra' that contains the same\n"
             "  contents as a subdirectory 'example' of the current directory\n"
             "\n"
             "  $ %s --%s example.sra --%s example\n",
             progname, OPTION_CREATE, OPTION_DIRECTORY));

    OUTMSG (("\n"
             "  To replace an existing archive named 'example.sra' with another that contains\n"
             "  the same contents as a subdirectory 'example' of the current directory\n"
             "\n"
             "  $ %s -%s -%s example.sra -%s example\n",
             progname, ALIAS_FORCE, ALIAS_CREATE, ALIAS_DIRECTORY));

    OUTMSG (("\n"
             "  To examine in detail the contents of an archive named 'example.sra'\n"
             "\n"
             "  $ %s --%s --%s example.sra\n",
             progname, OPTION_LONGLIST, OPTION_TEST));

    OUTMSG (("\n"
             "  To extract the files from an archive named 'example.sra' into\n"
             "  a subdirectory 'example' of the current directory.\n"
             "  NOTE: all extracted files will be read only.\n"
             "\n"
             "  $ %s --%s example.sra --%s example\n",
             progname, OPTION_EXTRACT, OPTION_DIRECTORY));


    HelpVersion (fullpath, KAppVersion());

    return rc;
}
Ejemplo n.º 4
0
rc_t CC Usage (const Args * args)
{
    const char * progname = UsageDefaultName;
    const char * fullpath = UsageDefaultName;
    rc_t rc;

    if (args == NULL)
        rc = RC (rcApp, rcArgv, rcAccessing, rcSelf, rcNull);
    else
        rc = ArgsProgram (args, &fullpath, &progname);

    UsageSummary (progname);

    KOutMsg ("Parameters:\n");

    HelpParamLine ("source-file-path", first_usage);
    HelpParamLine ("destination-file-path", second_usage);

    KOutMsg ("\nOptions:\n");

    HelpOptionLine (ALIAS_FORCE, OPTION_FORCE, NULL, force_usage);

    HelpOptionsStandard ();

    OUTMSG (("\n"
             "ncbi-file uri syntax:\n"
             "  'ncbi-file' uris are based on a combination of the standard\n"
             "  'file' and 'http' syntax familiar to browser users.\n"
             "  Enclosing questions marks are probably necessary.\n"
             "\n"
             "  URI syntax is 'scheme:'hierarchical-part'?'query'#'fragment'\n"
             "  scheme:\n"
             "    ncbi-file\n"
             "  hierarchical-part:\n"
             "    this is the same as for scheme file and can be the native form or\n"));
    OUTMSG (("    the ncbi 'posix' format that matches most flavors of Unix.\n"
             "    Environment variables and short hands such as '~' are not interpreted.\n"
             "  query:\n"
             "    Zero or two symbols separated by the '&'.  The whole query can be omitted.\n"
             "      enc or encrypt\n"
             "      pwfile='path to a file containing a password'\n"
             "      pwfd='file descriptor where the password can be read'\n"
             "    If the encrypt is present exactly one of the other two must be present.\n"
             "  fragment:\n"
             "    No fragment is permitted.\n"));
    OUTMSG (("\n"
             "password contents:\n"
             "  The file or file descriptor containing the password is read enough to satisfy\n"
             "  the following restriction.  The password is terminated by the end of file,\n"
             "  a carriage return or a line feed.  The length must be no more than 4096 bytes.\n"
             "  The password file should have limited read access to protect it.\n"));


    OUTMSG (("\n"
             "Use examples:"
             "\n"
             "  To encrypt a create a file named 'example' with a password from a file\n"
             "  named 'password-file' to a file named 'example.nenc' all in the current\n"
             "  directory:\n"
             "\n"
             "  $ %s example \"ncbi-file:example.nenc?encrypt&pwfile=password-file\"\n",
             progname));
    OUTMSG (("\n"
             "  To decrypt a file named 'example.nenc' with a password from a file\n"
             "  named 'password-file' to a file named 'example' in directories implied\n"
             "  in the command:\n"
             "\n"
             "  $ %s \"ncbi-file:/home/user/downloads/example.nenc?encrypt&pwfile=/home/user/password-file\" example\n",
             progname));
    OUTMSG (("\n"
             "  To change the encryption of a file from one password to another:\n"
             "\n"
             "  $ %s \"ncbi-file:/home/user/downloads/example.nenc?encrypt&pwfile=old-password-file\" \\\n"
             "         \"ncbi-file:example.nenc?encrypt&pwfile=/home/user/new-password-file\"\n",
             progname));

    HelpVersion (fullpath, KAppVersion());

    return rc;
}