Esempio n. 1
0
static int extend_partition(const char *dev_path)
{
	system_command("e2fsck -fy %s", dev_path);
	system_command("resize2fs -pf %s", dev_path);

	return 0;
}
Esempio n. 2
0
void WriteCronJobs(RDArsrc *mainrsrc,char *new_one)
{
	char temp[512],tempx[1024];
	int selected=0,x=0;
	FILE *fp=NULL;

	FINDRSCGETINT(mainrsrc,"CRONTABS",&selected);
	memset(tempx,0,1024);
	sprintf(tempx,"%s/%s.cron",CURRENTDIRECTORY,USERLOGIN);
	unlink(tempx);
	sprintf(temp,"sudo -u rdacron crontab %s",tempx);
	fp=fopen(tempx,"w");
	if(fp!=NULL)
	{
		for(x=0;x<CRON->numlibs;++x)
		{
			if(RDAstrcmp(CRON->libs[x],"No Crontab's Defined")) 
				fprintf(fp,"%s\n",CRON->libs[x]);
		}
		if(!isEMPTY(new_one))
		{
			fprintf(fp,"%s\n",(new_one!=NULL ? new_one:""));
		}
		fclose(fp);
		system_command(temp);
		unlink(tempx);
	}
	getcurrentcrons();
	if(selected>=CRON->numlibs) selected=0;
	FINDRSCLISTAPPlib(mainrsrc,"CRONTABS",selected,CRON);
	updatersrc(mainrsrc,"CRONTABS");
}
Esempio n. 3
0
static void deletecron(RDArsrc *r)
{
	int x=0,selected=0;
	APPlib *a=NULL;

	FINDRSCGETINT(r,"CRONTABS",&selected);
#ifndef XXXX
	system_command("crontab -r");
#endif /* Not XXXX */
#ifdef XXXX
	a=APPlibNEW();
	addAPPlib(a,"-r");
	Execute2Program("crontab",a);
	if(a!=NULL) freeapplib(a);
#endif /* XXXX */
	if(CRON->numlibs>1)
	{
		a=APPlibNEW();
		for(x=0;x<CRON->numlibs;++x)
		{
			if(x!=(selected))
			{
				addAPPlib(a,CRON->libs[x]);
			}
		}
		if(CRON!=NULL) freeapplib(CRON);
		CRON=APPlibNEW();
		for(x=0;x<a->numlibs;++x) addAPPlib(CRON,a->libs[x]);
		freeapplib(a);
	} else {
		if(CRON!=NULL) freeapplib(CRON);
		CRON=APPlibNEW();
	}
	WriteCronJobs(r,NULL);
}
Esempio n. 4
0
int main(int argc, char **argv)
{
	int i;
	for (i = 1; i < argc; i++)
	{
		system_command (argv[i]);
		printf ("\n");
	}		

	return 0;
}
Esempio n. 5
0
static int upgrade_modem(const char *resource)
{
	int ret;
	char update_wizard[1024];
	pid_t pid;
	pthread_t usb_thread;

	text_path_cat(update_wizard, sizeof(update_wizard), resource, UPDATE_WIZARD_NAME);

	ret = chmod(update_wizard, 0777);
	if (ret < 0)
	{
		print_error("chmod \"%s\"", update_wizard);
		return ret;
	}

	pid = fork();
	if (pid < 0)
	{
		print_error("fork");
		return pid;
	}

	if (pid == 0)
	{
		if (file_test("/bin/sh", "x") == 0)
		{
			ret = system_command("%s %s | tee %s", update_wizard, resource, SWAN_CONSOLE_DEVICE);

			exit(ret);
		}
		else
		{
			ret = execl(update_wizard, update_wizard, resource, NULL);
			if (ret < 0)
			{
				error_msg("execl");
			}

			exit(-1);
		}
	}

	pthread_create(&usb_thread, NULL, set_usb_power_handle, NULL);

	waitpid(pid, &ret, 0);
	if (!WIFEXITED(ret) || WEXITSTATUS(ret) != 0)
	{
		error_msg("upgrade modem failed");
		return -1;
	}

	return 0;
}
Esempio n. 6
0
std::string write_ledger_as_pdf(Ledger const& ledger, fs::path const& filepath)
{
    throw_if_interdicted(ledger);

    fs::path print_dir(configurable_settings::instance().print_directory());

    fs::path real_filepath(orthodox_filename(filepath.leaf()));
    LMI_ASSERT(fs::portable_name(real_filepath.string()));

    if(contains(global_settings::instance().pyx(), "xml"))
        {
        fs::path xml_file = unique_filepath(print_dir / real_filepath, ".xml");

        fs::ofstream ofs(xml_file, ios_out_trunc_binary());
        ledger.write(ofs);
        ofs.close();
        if(!ofs.good())
            {
            fatal_error()
                << "Unable to write output file '"
                << xml_file
                << "'."
                << LMI_FLUSH
                ;
            }
        }

    fs::path xml_fo_file = unique_filepath(print_dir / real_filepath, ".fo.xml");

    fs::ofstream ofs(xml_fo_file, ios_out_trunc_binary());
    ledger.write_xsl_fo(ofs);
    ofs.close();
    if(!ofs.good())
        {
        fatal_error()
            << "Unable to write output file '"
            << xml_fo_file
            << "'."
            << LMI_FLUSH
            ;
        }

    fs::path pdf_out_file = unique_filepath(print_dir / real_filepath, ".pdf");

    std::ostringstream oss;
    oss
        << configurable_settings::instance().xsl_fo_command()
        << " -fo "  << '"' << xml_fo_file  << '"'
        << " -pdf " << '"' << pdf_out_file << '"'
        ;
    system_command(oss.str());
    return pdf_out_file.string();
}
Esempio n. 7
0
static int mksdcard(const char *sd_device)
{
	int ret;

	umount_device(sd_device, MNT_DETACH);

	ret = system_command("sfdisk %s -uM << EOF\n64,,L\nEOF", sd_device);
	if (ret < 0) {
		pr_err_info("system_command");
		return ret;
	}

	sleep(1);

	ret = system_command("mkfs.vfat %s1 -n sdcard", sd_device);
	if (ret < 0) {
		pr_err_info("system_command");
		return ret;
	}

	pr_green_info("mksdcard Success");

	return 0;
}
Esempio n. 8
0
int test_main(int, char*[])
{
    std::ofstream os("eraseme", ios_out_trunc_binary());
    os << "abc\n";
    os.close();

    system_command("grep --quiet abc eraseme");

    BOOST_TEST_THROW
        (system_command("grep --quiet xyz eraseme")
        ,std::runtime_error
        ,"Exit code 1 from command 'grep --quiet xyz eraseme'."
        );

    BOOST_TEST_THROW
        (system_command("xyzzy")
        ,std::runtime_error
        ,"Exit code 12345 from command 'xyzzy'."
        );

    std::remove("eraseme");

    return 0;
}
Esempio n. 9
0
/*-------------------------------------------------------------------*/
int CallHercCmd ( CMDFUNC_ARGS_PROTO )
{
    CMDTAB* pCmdTab;
    size_t  cmdlen, matchlen;
    int     rc = HERRINVCMD;             /* Default to invalid command   */

    /* Let 'cscript' command run immediately in any context */
    if (argc >= 1 && strcasecmp( argv[0], "cscript" ) == 0)
        return cscript_cmd( CMDFUNC_ARGS );

    HERC_CMD_ENTRY();

    /* [ENTER] key by itself: either start the CPU or ignore
       it altogether when instruction stepping is not active. */
    if (0
            || !argc            /* (no args)    */
            || !argv[0]         /* (no cmd)     */
            || !cmdline         /* (no cmdline) */
            || !cmdline[0]      /* (empty cmd)  */
            || !argv[0][0]      /* (empty cmd)  */
       )
    {
        if (sysblk.inststep)
            rc = start_cmd( 0, NULL, NULL );
        else
            rc = 0;         /* ignore [ENTER] */

        HERC_CMD_EXIT();
        return rc;
    }

    /* (sanity check) */
    ASSERT( argc && cmdline && *cmdline && argv[0] && argv[0][0] );

#if defined( OPTION_DYNAMIC_LOAD )
    /* If a system command hook exists, let it try processing it first. */
    /* Only if it rejects it, will we then try processing it ourselves. */
    if(system_command)
        if((rc = system_command( CMDFUNC_ARGS )) != HERRINVCMD)
        {
            HERC_CMD_EXIT();
            return rc;
        }
#endif /* defined( OPTION_DYNAMIC_LOAD ) */

    /* Check for comment command. We need to test for this separately
       rather than scanning our COMAMND table since the first token
       of the "command" might not be a single '#' or '*'. That is to
       say, the first token might be "#comment" or "*comment" (with
       no blanks following the '#' or '*'), which would thus not match
       either of our "comment_cmd" COMMAND table entries. Note that
       this also means the COMMAND table entries for '*' and '#' are
       redundant since they will never be used (since we're processing
       comments here and not via our table search), but that's okay. */
    if (0
            || argv[0][0] == '#'       /* (comment command?) */
            || argv[0][0] == '*'       /* (comment command?) */
       )
    {
        /* PROGRAMMING NOTE: we ALWAYS call the "comment_cmd" function
           for comments even though today it does nothing. We might decide
           to do additional processing for comments in the future (such
           as simply counting them for example), so we should ALWAYS call
           our comment_cmd function here instead of just returning. */
        rc = comment_cmd( CMDFUNC_ARGS );
        HERC_CMD_EXIT();
        return rc;
    }

    /* Route standard formatted commands from our COMMAND routing table */

    /* PROGRAMMING NOTE: since our table is now sorted, the below could
       be converted to a more efficient binary search algorithm instead */

    for (pCmdTab = cmdtab; pCmdTab->statement; pCmdTab++)
    {
        if (1
                && pCmdTab->function
                && (pCmdTab->type & sysblk.sysgroup)
                /* Commands issues through DIAG8 must NOT be part of the SYSNDIAG8 group */
                && (!(sysblk.diag8cmd & DIAG8CMD_RUNNING) || !(pCmdTab->type & SYSNDIAG8))
           )
        {
            cmdlen = pCmdTab->mincmdlen ? pCmdTab->mincmdlen : strlen( pCmdTab->statement );
            matchlen = MAX( strlen(argv[0]), cmdlen );

            if (!strncasecmp( argv[0], pCmdTab->statement, matchlen ))
            {
                char cmd[256]; /* (copy of command name) */

                /* Make full-length copy of the true command's name */
                strlcpy( cmd, pCmdTab->statement, sizeof(cmd) );
                argv[0] = cmd; /* (since theirs may be abbreviated) */

                /* Run command in background? (last argument == '&') */
                if (strcmp(argv[argc-1],"&") == 0)
                {
                    BGCMD *bgcmd;
                    TID tid;
                    int i,len;

                    /* Calculate length of the command-line (all arguments
                       except the last one), including intervening blanks. */
                    for (len=0, i=0; i < argc-1; i++ )
                        len += (int) strlen( (char*) argv[i] ) + 1;

                    /* Build parameter to pass to background thread */
                    bgcmd = (BGCMD*) malloc( sizeof(BGCMD) + len );
                    bgcmd->func = pCmdTab->function;

                    /* Build private copy of cmdline for bgcmd_thread */
                    strlcpy( bgcmd->cmdline, argv[0], len );
                    for (i=1; i < argc-1; i++)
                    {
                        strlcat( bgcmd->cmdline,  " ",    len );
                        strlcat( bgcmd->cmdline, argv[i], len );
                    }

                    /* Process command asynchronously in the background */
                    rc = create_thread( &tid, DETACHED, bgcmd_thread, bgcmd, "bgcmd_thread" );
                }
                else /* (not a background command) */
                {
                    /* Does last argument start with two ampersands? */
                    if (strncmp( argv[argc-1], "&&", 2 ) == 0)
                        /* Yes, skip past the first one */
                        argv[argc-1]++; /* ("&&&" ==> "&&", "&&" ==> "&", etc) */

                    /* Process the Hercules command */
                    rc = pCmdTab->function( CMDFUNC_ARGS );
                }
                break;
            }
            /* end strncasecmp( table entry match ) */
        }
        /* end if ( valid table entry ) */
    }
    /* end for ( search table ) */

    /* If we didn't find an exact match in our table, check if
       this is maybe a special non-standard formatted command. */
    if (rc == HERRINVCMD && (sysblk.sysgroup & SYSCMDNOPER))
    {
        /* shadow file commands: add/remove/compress/display/check */
        if (0
                || !strncasecmp( cmdline, "sf+", 3 )
                || !strncasecmp( cmdline, "sf-", 3 )
                || !strncasecmp( cmdline, "sfc", 3 )
                || !strncasecmp( cmdline, "sfd", 3 )
                || !strncasecmp( cmdline, "sfk", 3 )
           )
            rc = ShadowFile_cmd( CMDFUNC_ARGS );
        else
            /* "x+" and "x-" commands: turn switch on or off */
            if (0
                    || '+' == cmdline[1]
                    || '-' == cmdline[1]
               )
                rc = OnOffCommand( CMDFUNC_ARGS );
    }

    HERC_CMD_EXIT();
    return rc;
}
Esempio n. 10
0
int try_main(int argc, char* argv[])
{
    int c;
    int option_index = 0;
    // Long options are meta-options not directly supported by the borland
    // librarian. TRICKY !! They are aliased to unlikely octal values.
    static Option long_options[] =
      {
        {"help",         NO_ARG,   0, 001, 0, "display this help and exit"},
        {"license",      NO_ARG,   0, 002, 0, "display license and exit"},
        {"accept",       NO_ARG,   0, 003, 0, "accept license (-l to display)"},
        {"program",      REQD_ARG, 0, 004, 0, "librarian's filepath"},
        {"r",            REQD_ARG, 0, 'r', 0, "see inline documentation"},
        {"s",            REQD_ARG, 0, 's', 0, "see inline documentation"},
        {"u",            REQD_ARG, 0, 'u', 0, "see inline documentation"},
        {"v",            REQD_ARG, 0, 'v', 0, "see inline documentation"},
        {0,              NO_ARG,   0,   0, 0, ""}
      };

    bool license_accepted = false;
    bool show_license     = false;
    bool show_help        = false;

    std::string program;

    std::string library_filename;

    std::string ar_options;

    GetOpt getopt_long
        (argc
        ,argv
        ,""
        ,long_options
        ,&option_index
        ,true
        );
    getopt_long.opterr = false;
    while(EOF != (c = getopt_long()))
        {
        switch(c)
            {
            case 001:
                {
                show_help = true;
                }
                break;

            case 002:
                {
                show_license = true;
                }
                break;

            case 003:
                {
                license_accepted = true;
                }
                break;

            case 004:
                {
                program = getopt_long.optarg;
                }
                break;

            case 'r':
            case 's':
            case 'u':
            case 'v':
                {
                // Do nothing.
                }
                break;

            case '?':
                {
                // Forward any unrecognized options to the tool.
                int offset = getopt_long.optind - 1;
                if(0 < offset)
                    {
                    std::string s = getopt_long.nargv[offset];
                    std::cerr << "Unknown option'" << s << "'.\n";
                    }
                else
                    {
                    std::cerr << "Internal error\n";
                    }
                }
                break;

            default:
                std::cerr << "getopt returned character code 0" << c << '\n';
            }
        }

    if((c = getopt_long.optind) < argc)
        {
        library_filename = std::string(argv[c++]);
        while(c < argc)
            {
            // Forward any unrecognized arguments to the tool.
            ar_options += " +" + std::string(argv[c++]);
            }
        }

    if(!license_accepted)
        {
        std::cerr << license_notices_as_text() << "\n\n";
        }

    if(show_license)
        {
        std::cerr << license_as_text() << "\n\n";
        return EXIT_SUCCESS;
        }

    if(show_help)
        {
        std::cout
            << "This program's emulation of gnu 'ar' is very limited.\n"
            << "Read the inline documentation in file '" __FILE__ "'.\n"
            ;
        getopt_long.usage();
        return EXIT_SUCCESS;
        }

    if("" == program)
        {
        std::cerr << "Must specify --program=(librarian name)\n";
        return EXIT_FAILURE;
        }

    std::remove(library_filename.c_str());

    // The borland librarian allows up to 2^16 'pages', each of a
    // size specified on the command line. The version supplied with
    // their 5.02 compiler fails if the specified page size is not
    // sufficient. The version supplied with their 5.5.1 compiler
    // seems to adjust the page size automatically. It might be nice
    // to perform such an automatic adjustment here for the older
    // version, but we aren't very interested in breathing new life
    // into old tools that were badly designed in the first place.
    std::string command_line =
          program
        + " "
        + "/P1024"
        + " "
        + library_filename
        + " "
        + ar_options
        ;
    try
        {
        system_command(command_line);
        }
    catch(...)
        {
        report_exception();
        std::cerr
            << "Command failed."
            << "\ncommand line: " << command_line
            << '\n'
            << "\nprogram: "      << program
            << "\nlibrary: "      << library_filename
            << "\noptions: "      << ar_options
            << '\n'
            ;
        }
    return 0;
}
Esempio n. 11
0
std::string Authenticity::Assay
    (calendar_date const& candidate
    ,fs::path const&      data_path
    )
{
    // The cached date is valid unless it's the peremptorily-invalid
    // default value of JDN zero.
    if
        (  calendar_date(jdn_t(0)) != Instance().CachedDate_
        && candidate               == Instance().CachedDate_
        )
        {
        return "cached";
        }

    ResetCache();

    std::ostringstream oss;

    // Read the passkey and valid-date-range files each time
    // because they might change while the program is running.
    // They'll be validated against validated md5sums a fraction
    // of a second later, to guard against fraudulent manipulation.

    // Read saved passkey from file.
    std::string passkey;
    {
    fs::path passkey_path(data_path / "passkey");
    fs::ifstream is(passkey_path);
    if(!is)
        {
        oss
            << "Unable to read passkey file '"
            << passkey_path
            << "'. Try reinstalling."
            ;
        return oss.str();
        }

    is >> passkey;
    if(!is.eof())
        {
        oss
            << "Error reading passkey file '"
            << passkey_path
            << "'. Try reinstalling."
            ;
        return oss.str();
        }

    if(passkey.size() != chars_per_formatted_hex_byte * md5len)
        {
        oss
            << "Length of passkey '"
            << passkey
            << "' is "
            << passkey.size()
            << " but should be "
            << chars_per_formatted_hex_byte * md5len
            << ". Try reinstalling."
            ;
        return oss.str();
        }
    }

    // Read valid date range [begin, end) from file.
    calendar_date begin(last_yyyy_date ());
    calendar_date end  (gregorian_epoch());
    {
    fs::path expiry_path(data_path / "expiry");
    fs::ifstream is(expiry_path);
    if(!is)
        {
        oss
            << "Unable to read expiry file '"
            << expiry_path
            << "'. Try reinstalling."
            ;
        return oss.str();
        }

    is >> begin >> end;
    if(!is || !is.eof())
        {
        oss
            << "Error reading expiry file '"
            << expiry_path
            << "'. Try reinstalling."
            ;
        return oss.str();
        }
    }

    // Make sure candidate date is within valid range.
    if(candidate < begin)
        {
        oss
            << "Current date "
            << candidate.str()
            << " is invalid: this system cannot be used before "
            << begin.str()
            << ". Contact the home office."
            ;
        return oss.str();
        }
    if(end <= candidate)
        {
        oss
            << "Current date "
            << candidate.str()
            << " is invalid: this system cannot be used after "
            << (-1 + end).str()
            << ". Contact the home office."
            ;
        return oss.str();
        }

    // Validate all data files.
    fs::path original_path(fs::current_path());
    if(0 != chdir(data_path.string().c_str()))
        {
        oss
            << "Unable to change directory to '"
            << data_path
            << "'. Try reinstalling."
            ;
        return oss.str();
        }
    try
        {
        system_command("md5sum --check --status " + std::string(md5sum_file()));
        }
    catch(...)
        {
        report_exception();
        oss
            << "At least one required file is missing, altered, or invalid."
            << " Try reinstalling."
            ;
        return oss.str();
        }
    if(0 != chdir(original_path.string().c_str()))
        {
        oss
            << "Unable to restore directory to '"
            << original_path
            << "'. Try reinstalling."
            ;
        return oss.str();
        }

    // The passkey must match the md5 sum of the md5 sum of the file
    // of md5 sums of secured files.

    char c_passkey[md5len];
    unsigned char u_passkey[md5len];
    std::FILE* md5sums_file = std::fopen
        ((data_path / md5sum_file()).string().c_str()
        ,"rb"
        );
    md5_stream(md5sums_file, u_passkey);
    std::fclose(md5sums_file);
    std::memcpy(c_passkey, u_passkey, md5len);
    md5_buffer(c_passkey, md5len, u_passkey);
    std::memcpy(c_passkey, u_passkey, md5len);
    md5_buffer(c_passkey, md5len, u_passkey);
    std::string expected = md5_hex_string
        (std::vector<unsigned char>(u_passkey, u_passkey + md5len)
        );
    if(passkey != expected)
        {
        oss
            << "Passkey is incorrect for this version."
            << " Contact the home office."
            ;
        return oss.str();
        }
    // Cache the validated date.
    Instance().CachedDate_ = candidate;
    return "validated";
}