Changeset - eeea6dcb5927
[Not reviewed]
default
0 1 0
ethanzonca - 16 years ago 2009-07-31 19:18:08

ssh_keygen() now uses execio()
1 file changed with 23 insertions and 6 deletions:
0 comments (0 inline, 0 general)
src/server/slavefuncs.c
Show inline comments
 
@@ -34,10 +34,6 @@
 
/** Generates a SSH key with ssh-keygen */
 
int ssh_keygen(){
 
	// distren.id_rsa and distren.id_rsa.pub are now generated in SYSCONFDIR (etc)
 
	char *command = "ssh-keygen"; // @TODO: append .exe if win32?
 
	char *path_to_command = "/usr/bin/ssh-keygen";
 
	int ret;
 
	char *cmd[] = { command, "-q", "-f", SYSCONFDIR "/distren.id_rsa", "-N", "", (char *)0 }; // TODO: Give me the correct args!
 

	
 
	// Checks to see if the keys are already present.
 
	int status;
 
@@ -47,8 +43,29 @@ int ssh_keygen(){
 
		fprintf(stderr, "Please delete etc/distren.id_rsa and etc/distren.id_rsa.pub to register.");
 
	}
 

	
 
	ret = execv(path_to_command, cmd); // This path will be absolute for testing, should be relative to install on production
 
	if(ret == -1){
 
/* start execio code */
 
	char *command = "ssh-keygen"; // @TODO: append .exe if win32?
 
	int ret;
 
	char *cmd[] = { command, "-q", "-f", SYSCONFDIR "/distren.id_rsa", "-N", "", (char *)NULL }; // TODO: Give me the correct args!
 

	
 
	char buf[10];
 
	struct execio *testrem;
 
	size_t readlen;
 
	fprintf(stderr, "Opening stream:\n", execio_open(&testrem, "ssh", cmd)); // This path will be absolute for testing, should be relative to install on production
 
	buf[9] = '\0'; // null-terminating the array...
 
	while(!execio_read(testrem, buf, 9, &readlen))
 
	    {
 
	      if(readlen > 9) {
 
		fprintf(stderr, "Something is terribly wrong!\n");
 
	      }
 
	      buf[readlen] = '\0';
 
	      fprintf(stderr, "read \"%s\"\n", buf);
 
	    }
 
	execio_close(testrem);
 
/* end execio code */
 

	
 
	// Supposedly execio returns 1 if it has bad args.
 
	if(ret == 1){
 
		fprintf(stderr, "Generating your key failed. Ensure that ssh-keygen is present!\n"); // Use different executor that searches the path? there is one...
 
		return 0;
 
	}
0 comments (0 inline, 0 general)