Re: Emparse

Dave Minogue ( minogue@cyberbeach.net )
Tue, 30 Dec 1997 15:25:05 -0500

This is a multi-part message in MIME format.
--------------E50D1EA03E7E5792291E8E55
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Sure..here it is...its not very generic so some changes might have to be
made to it..
and a little bit of it is done quite crudely..such as the password change
routine..

--------------E50D1EA03E7E5792291E8E55
Content-Type: text/plain; charset=us-ascii; name="Parse.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="Parse.c"

/*Dave Minogue - Cyber Beach Communications - 97/12/30 */
/*comments/suggestions to minogue@cyberbeach.net */
/*Required /var/tmp dir...and extends file created in /home/admin/ */
/*This program works fine here, if it doesn't work for you don't whine, just ask
/*I'll see what I can do. */
/*Creates/Deletes/Changes Passwords - keep unix in synch with emerald system */
/*Coded for Emerald 2.2.32. I have this setup in my cron, to run every 15 minutes.*/
#include <string.h>
#include <stdlib.h>
#include <stdio.h>

void Drop(char *, int);
void main(void)
{
FILE *infile, *outfile;
char LineIn[512], Command[5], Username[20], Password[20], First[40], Last[40],Junk[20];
char CommandLine[256];

infile=fopen("/home/admin/share/extends", "r");
if(infile)
{
while(fgets(LineIn, 512, infile)!=NULL)
{
sscanf(LineIn, "%s", Command);
// Haven't figured out what use EXT is yet in unix
// if you know what its for let me know
if(strcmp(Command, "EXT")!=0)
{
//Adds New Users
if(strcmp(Command, "ADD")==0)
{
Drop(LineIn,4);
sscanf(LineIn, "%s %s %s %s %s",Username,Junk,Password,First,Last);
sprintf(CommandLine, "adduser -batch %s users \"%s %s\" %s -group users -s",Username,First,Last,Password);
system(CommandLine);

}
//Removes users
if(strcmp(Command, "DEL")==0)
{
Drop(LineIn,4);
sscanf(LineIn,"%s",Username);
printf("%s\n", Username);
outfile=fopen("/var/tmp/yes.txt", "w");
fprintf(outfile, "y\ny\n");
fclose(outfile);
sprintf(CommandLine, "rmuser %s < /var/tmp/yes.txt", Username);
system(CommandLine);
system("rm /var/tmp/yes.txt");
}
//Crudy way of changing users passwords.
if(strcmp(Command, "PWD")==0)
{
Drop(LineIn,4);
sscanf(LineIn,"%s %s",Username, Password);
outfile=fopen("/var/tmp/script.exp", "w");
fprintf(outfile, "spawn passwd %s\nexpect password:\n",Username);
fprintf(outfile, "send \"%s\\n\"\nexpect password:\n", Password);
fprintf(outfile, "send \"%s\\n\"\nexpect password:\n", Password);
fprintf(outfile, "send \"%s\\n\"\nexpect password:\n", Password);
fclose(outfile);
sprintf(CommandLine,"expect /var/tmp/script.exp\n",Username,Password);
system(CommandLine);
system("rm /var/tmp/script.exp");
}
}
}
fclose(infile);
}
else
printf("Error opening file.\n");
system("rm /home/admin/share/extends");
}
void Drop(char InText[512], int Cut)
{
char a[512];
int i;
for(i=0;i<strlen(InText)-Cut;i++)
a[i]=InText[i+Cut];
strcpy(InText, a);
}

--------------E50D1EA03E7E5792291E8E55--