Changeset - 94aafba083ee
[Not reviewed]
default
0 2 0
ethanzonca - 17 years ago 2009-03-15 19:38:50

Added system changelog and some user creation code
2 files changed with 26 insertions and 50 deletions:
0 comments (0 inline, 0 general)
src/client/distren.c
Show inline comments
 
/*
 
  Copyright 2008 Nathan Phillip Brink, Ethan Zonca, Matt Orlando
 

	
 
  This file is a part of DistRen.
 

	
 
  DistRen is free software: you can redistribute it and/or modify
 
  it under the terms of the GNU Affero General Public License as published by
 
  the Free Software Foundation, either version 3 of the License, or
 
  (at your option) any later version.
 

	
 
  DistRen is distributed in the hope that it will be useful,
 
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  GNU Affero General Public License for more details.
 

	
 
  You should have received a copy of the GNU Affero General Public License
 
  along with DistRen.  If not, see <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#include <stdio.h> /* sprintf, printf */
 
#include <stdlib.h> /* malloc, free */
 
#include "options.h"
 
#include "execio.h"
 
#include <libxml/tree.h> /* Happy fun XML time */
 
#include <libxml/xmlwriter.h>
 

	
 

	
 

	
 
int main(int argc, char *argv[])
 
{
 

	
 

	
 
/* Mneh variable goodness */
 
int isusername;
 
char *host = "protofusion.org";
 
char *username = "guest";
 
char *nameemail;
 
/* */
 

	
 

	
 
	/* XML Testing, segfaults, so reverted to default. */
 
	/*
 
		xmlDocPtr doc;
 
		xmlNodePtr cur;
 

	
 
		doc = xmlParseFile(docname);
 

	
 
		if (doc == NULL ) {
 
			fprintf(stderr,"The document was not parsed correctly \n");
 
			return;
 
		}
 

	
 
		cur = xmlDocGetRootElement(doc);
 
/* put some code here to parse for a username, set username=0 if no username in the xml file or if no xml file exists. if no file, drop a warning */
 

	
 
		if (cur == NULL) {
 
			fprintf(stderr,"I cannot parse an empty document \n");
 
			xmlFreeDoc(doc);
 
			return;
 
		}
 

	
 
		if (xmlStrcmp(cur->name, (const xmlChar *) "story")) {
 
			fprintf(stderr,"The document you want me to parse is of the wrong type");
 
			xmlFreeDoc(doc);
 
			return;
 
		}
 

	
 
	*/
 

	
 

	
 
if(isusername = 0){
 

	
 
  char buf[10];
 
  struct execio *testrem;
 
  char *execargv[] =
 
    {
 
      "ssh",
 
      "protofusion.org",
 
      host,
 
      "sh",
 
      "-c",
 
      "\"echo hello from ${HOSTNAME}\"",
 
      "\"useradd -M -c",
 
      nameemail,
 
      "-d /home/distren --gid 537",
 
      username,
 
      "\"",
 
      (char *)NULL
 
    };
 

	
 
  size_t readlen;
 

	
 

	
 
  fprintf(stderr, "testing execio (It shouldn't work) :-)\n");
 
  fprintf(stderr, "execio madness is occuring!");
 
  fprintf(stderr, "execio_open returns %d\n", execio_open(&testrem, "ssh", execargv));
 

	
 
  buf[9] = '\0';
 
  while(!execio_read(testrem, buf, 9, &readlen))
 
    {
 
      if(readlen > 9)
 
	{
 
	  fprintf(stderr, "execio_read doesn't set readlen correctly or read() is messed up\n");
 
	  return 1;
 
	}
 
      buf[readlen] = '\0';
 
      fprintf(stderr, "read \"%s\"\n", buf);
 
    }
 

	
 
  return 0;
 
}
 

	
 
  return 0;
 
};
 

	
 
/* this function should probably not exist. asprintf should be used instead of sprintf */
 
size_t intstrlen(size_t theint)
 
else
 
{
 
  size_t len = 0; /* if the number is single digit, this will be incremented */
 
  do
 
    {
 
      theint /= 10;
 
      len ++;
 
    }
 
  while(theint > 0);
 

	
 
  return len;
 
/* put code here to ssh to zserver2 w/ execio as the user from the xml file */
 
}
 

	
 

	
 
};
 

	
 

	
 

	
 

	
 

	
src/common/execio.h
Show inline comments
 
/*
 
  Copyright 2008 Nathan Phillip Brink, Ethan Zonca
 

	
 
  This file is a part of DistRen.
 

	
 
  DistRen is free software: you can redistribute it and/or modify
 
  it under the terms of the GNU Affero General Public License as published by
 
  the Free Software Foundation, either version 3 of the License, or
 
  (at your option) any later version.
 

	
 
  DistRen is distributed in the hope that it will be useful,
 
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  GNU Affero General Public License for more details.
 

	
 
  You should have received a copy of the GNU Affero General Public License
 
  along with DistRen.  If not, see <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#ifndef _DISTREN_EXECIO_H
 
#define _DISTREN_EXECIO_H
 

	
 
/*
 
  This file tries to abstract away getting a socket/fd that talks to a spawned program
 
 */
 

	
 
#include <unistd.h>
 

	
 
enum execio_state
 
  {
 
    EXECIO_STATE_ERROR,
 
    EXECIO_STATE_EOF
 
  };
 
  
 

	
 
struct execio
 
{
 
  int pipe_write;
 
  int pipe_read;
 

	
 
  enum execio_state state;
 
  
 
  pid_t child;
 
};
 

	
 
/*
 
  runs progname with the arguments in argv. argv must be null terminated!!!!!!!!!
 

	
 
  returns nonzsero return on error 
 
  returns nonzero return on error
 
*/
 
int execio_open(struct execio **rem, const char *progname, char *const argv[]);
 

	
 
/* 
 
   doesn't block, 
 
   returns 0 on success, 1 on failure
 
*/
 
int execio_read(struct execio *eio, void *buf, size_t len, size_t *bytesread);
 
int execio_write(struct execio *eio, void *buf, size_t len, size_t *bytesread);
 

	
 
enum execio_state execio_state(struct execio *eio);
 

	
 
/* nonzero return on error */
 
int execio_close(struct execio *eio);
 

	
 
#endif
 

	
0 comments (0 inline, 0 general)