示例#1
0
int main(int argc, char *argv[])
{
    int rc;
    char ip_str[20]           = "127.0.0.1";
    char username[64]         = "root";
    char commandline[BUFSIZ]  = "uname";
    char pwdfile[BUFSIZ]      = "password.txt";
    char pass[BUFSIZ];
    LIBSSH2_SESSION *session = NULL;
    LIBSSH2_CHANNEL *channel = NULL;
    
    if (argc > 1) strncpy(ip_str, argv[1], 19);
    if (argc > 2) strncpy(username,argv[2], 63);
    if (argc > 3) strncpy(commandline,argv[3], BUFSIZ -1);
    if (argc > 4) strncpy(pwdfile,argv[4], BUFSIZ -1);
    
    if ((rc=libssh2_init(0)) != 0)
    {
        fprintf (stderr, "init error (%d) (%s)\n", rc, strerror(errno));
        return 1;
    }

    decode_password(pass, pwdfile, ip_str, username);
    int sock = conn(ip_str, SSH_PORT);
    logon(username, pass, &session, sock);

    if(str_start(commandline, "file=") == 1) exec_shell_script(commandline+5, session, &channel, sock);
    else rc = exec_one_cmd(commandline, session, &channel, sock);
    
    shutdown:
    clear(session, channel, sock);
    
    return 0;
}
示例#2
0
文件: account.c 项目: ayttm/ayttm
void write_account_list()
{
	FILE *fp;
	char buff2[1024];
	LList *l1;

	snprintf(buff2, 1024, "%saccounts", config_dir);
	if (!(fp = fdopen(creat(buff2, S_IRWXU), "w"))) {
		ay_do_error(_("Account creation problem"),
			_("Cannot open account file !"));
		return;
	}
	fprintf(fp, "# Ayttm's Local Account file\n"
		"# Edit only if you know what you're doing\n"
		"# Passwords are obfuscated, not encrypted\n" "\n");

	for (l1 = accounts; l1; l1 = l1->next) {
		eb_local_account *ela = l1->data;

		/*
		 * This is the deal, what a protocol stores as account data is 
		 * protocol specific, so you just query for the values you need to write
		 * cool stuff :-)
		 */

		LList *config = RUN_SERVICE(ela)->write_local_config(ela);
		char *pwd = value_pair_get_value(config, "PASSWORD");
		int enc_type =
			1 + (int)(rand() / (RAND_MAX + 1.0) * (MAX_ENC - 1));
		char e[2];
		snprintf(e, sizeof(e), "%d", enc_type);
		config = value_pair_add(config, "enc_type", e);
		config = value_pair_add(config, "password_encoded",
			decode_password(pwd, enc_type));
		config = value_pair_remove(config, "PASSWORD");
		free(pwd);
		fprintf(fp, "<ACCOUNT %s>\n",
			eb_services[ela->service_id].name);
		value_pair_print_values(config, fp, 1);
		fprintf(fp, "</ACCOUNT>\n");
		value_pair_free(config);
	}

	fclose(fp);
}