Search This Blog

Friday, January 30, 2009

Taking input as password from script, passing to C code, returning to script

SCRIPT



#!/bin/sh



stty -echo;

read -p "Enter Password - " pass

echo -e

stty echo;

echo -e "#######################################"

echo -e "############# User Licence ############"



./defUser $pass

if [ $? -eq 5 ] ; then

echo -e "########################################"

echo -e "####### Licence Not Generated ##########"

exit

fi



sleep 2

echo -e "#######################################"

echo -e "######### Licence Generated ###########"

echo -e "Restart PBX"







while [ 1 ]

do

read -p "Restart now [y/n] " rst

case $rst in

y|Y) service sipxpbx stop; service sipxpbx start; exit;;

n|N) echo -e "Restart Once to Make changes effective." ;exit ;;

*) echo -e "Wrong Input!!! Please enter [y/n]";



esac

done



bash



###############################

C CODE

##############################



#include

#include



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

{

int usr, inc=0, i=0, j, k;

FILE *file;

char str[10],ch='\0';



/*

char pass[10];

printf("Enter password:-");

while (pass == "\n")

{

pass[inc]=getch();

printf("*");

inc++;

}

printf ("Password is ", pass);

*/

if ( argc != 2 ) /* argc should be 2 for correct execution */

{

/* We print argv[0] assuming it is the program name */

printf( "Wrong Password!!!\n" );

return 0;

}

if (strcmp(argv[1],"coral") == 0 )/*** Fix your password here ***/

{

printf("Enter the Number of Users :- ");

//scanf("%d", &usr);

while(ch!='\n')

{

ch=getc(stdin);

if(ch!='\n')

str[i]=ch;

i++;

}

for(j=0;j
if(!(isdigit(str[j])) )/** Cheching every char. for number **/

{

printf("%c Not a number!!!\n", str[j]);

return 5;

}

file = fopen("/etc/sipxpbx/users","w"); /* apend file (add text to a file or create a file if it does not exist.*/

for(k=0;k
{

fprintf(file,"%c", str[k]); /*writes*/

}

fclose(file); /*done!*/

printf("Defining Coral-PBX for Users :- ");

for(k=0;k
printf("%c", str[k]);

printf("\n");

//getchar(); /* pause and wait for key */

return 0;

}

else

{

printf("Wrong Password!!!\n");

return 5;

}



}

No comments:

Post a Comment