forked from Abhishek4848/delgroup
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TO MIMIC THE DELGROUP COMMAND IN LINUX
INSTRUCTIONS ARE IN README. PLEASE DO REFER.
- Loading branch information
Showing
8 changed files
with
274 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
*********************************************************************************************************** | ||
C PROGRAM TO MIMIC DELGROUP COMMAND IN LINUX USING C PROGRAM | ||
INSTRUCTIONS | ||
************************************************************************************************************ | ||
THIS PROGRAM DELETES A GROUP NAME FROM "group" and "gshadow" file. | ||
1)Primarily all files related to this program should be in the same folder(like .c,.h,makefiles etc). | ||
2)Whatever be the system,defining a path in terminal is necessary.Specify the path in terminal. | ||
3)To compile the makefile use "mingw32-make -f makefile.mak". | ||
4)After compilation,enter "a groupname",where groupname is the name to be deleted from those files. | ||
5)Also in the terminal only the other group names except deleted group will be displayed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include<stdio.h> | ||
#include<string.h> | ||
#include<stdlib.h> | ||
#include "server.h" | ||
int main(int argc,char *argv[]) | ||
{ | ||
if(argc==2) | ||
delgroupGname(argv[1]); | ||
else | ||
printf("Please Enter the correct input"); | ||
return 0; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
daemon:x:1: | ||
bin:x:2: | ||
sys:x:3: | ||
adm:x:4:syslog,anandms | ||
tty:x:5: | ||
disk:x:6: | ||
lp:x:7: | ||
mail:x:8: | ||
news:x:9: | ||
uucp:x:10: | ||
man:x:12: | ||
proxy:x:13: | ||
kmem:x:15: | ||
dialout:x:20: | ||
fax:x:21: | ||
voice:x:22: | ||
cdrom:x:24:anandms | ||
floppy:x:25: | ||
tape:x:26: | ||
sudo:x:27:anandms | ||
audio:x:29:pulse | ||
dip:x:30:anandms | ||
www-data:x:33: | ||
backup:x:34: | ||
operator:x:37: | ||
list:x:38: | ||
irc:x:39: | ||
src:x:40: | ||
gnats:x:41: | ||
shadow:x:42: | ||
utmp:x:43: | ||
video:x:44: | ||
sasl:x:45: | ||
plugdev:x:46:anandms | ||
staff:x:50: | ||
games:x:60: | ||
users:x:100: | ||
nogroup:x:65534: | ||
systemd-journal:x:101: | ||
systemd-timesync:x:102: | ||
systemd-network:x:103: | ||
systemd-resolve:x:104: | ||
systemd-bus-proxy:x:105: | ||
input:x:106: | ||
crontab:x:107: | ||
syslog:x:108: | ||
netdev:x:109: | ||
messagebus:x:110: | ||
uuidd:x:111: | ||
ssl-cert:x:112: | ||
lpadmin:x:113:anandms | ||
lightdm:x:114: | ||
nopasswdlogin:x:115: | ||
ssh:x:116: | ||
whoopsie:x:117: | ||
mlocate:x:118: | ||
avahi-autoipd:x:119: | ||
avahi:x:120: | ||
bluetooth:x:121: | ||
scanner:x:122:saned | ||
colord:x:123: | ||
pulse:x:124: | ||
pulse-access:x:125: | ||
rtkit:x:126: | ||
saned:x:127: | ||
anandms:x:1000: | ||
sambashare:x:128:anandms | ||
msanand:x:1001: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
daemon:*:: | ||
bin:*:: | ||
sys:*:: | ||
adm:*::syslog,anandms | ||
tty:*:: | ||
disk:*:: | ||
lp:*:: | ||
mail:*:: | ||
news:*:: | ||
uucp:*:: | ||
man:*:: | ||
proxy:*:: | ||
kmem:*:: | ||
dialout:*:: | ||
fax:*:: | ||
voice:*:: | ||
cdrom:*::anandms | ||
floppy:*:: | ||
tape:*:: | ||
sudo:*::anandms | ||
audio:*::pulse | ||
dip:*::anandms | ||
www-data:*:: | ||
backup:*:: | ||
operator:*:: | ||
list:*:: | ||
irc:*:: | ||
src:*:: | ||
gnats:*:: | ||
shadow:*:: | ||
utmp:*:: | ||
video:*:: | ||
sasl:*:: | ||
plugdev:*::anandms | ||
staff:*:: | ||
games:*:: | ||
users:*:: | ||
nogroup:*:: | ||
systemd-journal:!:: | ||
systemd-timesync:!:: | ||
systemd-network:!:: | ||
systemd-resolve:!:: | ||
systemd-bus-proxy:!:: | ||
input:!:: | ||
crontab:!:: | ||
syslog:!:: | ||
netdev:!:: | ||
messagebus:!:: | ||
uuidd:!:: | ||
ssl-cert:!:: | ||
lpadmin:!::anandms | ||
lightdm:!:: | ||
nopasswdlogin:!:: | ||
ssh:!:: | ||
whoopsie:!:: | ||
mlocate:!:: | ||
avahi-autoipd:!:: | ||
avahi:!:: | ||
bluetooth:!:: | ||
scanner:!::saned | ||
colord:!:: | ||
pulse:!:: | ||
pulse-access:!:: | ||
rtkit:!:: | ||
saned:!:: | ||
anandms:!:: | ||
sambashare:!::anandms | ||
msanand:!:: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
delgroup.exe:server1.o client.o | ||
gcc server1.c client.c | ||
server1.o:server1.c | ||
gcc -c server1.c | ||
client.o:client.c server.h | ||
gcc -c client.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
void delgroupGname(char deletinggroup[]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#include<stdio.h> | ||
#include<stdlib.h> | ||
#include<string.h> | ||
#include "server.h" | ||
#define buffsize 1000 | ||
void delgroupGname(char deletinggroup[])//a function which deletes a group name present in group and gshadow files | ||
{ | ||
char PFILE[]="C:/Users/PAVAN KUMAR M S/Desktop/C_MiniProject/PROJECT"; | ||
char str[buffsize];//str=variable to store the informations in the files | ||
char group[]="group.txt"; /*declaration of the files*/ | ||
char gshadow[]="gshadow.txt"; | ||
char newgroup[]="newgroup.txt";//PFILE = C:/Users/PAVAN KUMAR M S/C_MiniProject/PROJECT/(in my computer) | ||
char newgshadow[]="newgshadow.txt"; | ||
FILE *fp; | ||
FILE *fp1;//file pointer declarations which helps in the reading writing of files | ||
FILE *fp2; | ||
FILE *fp3; | ||
fp=fopen(group,"r");//used ton open the file | ||
int l1=1; | ||
while((fgets(str,buffsize,fp))!=NULL)//reads the file till it encounters null reads line by line | ||
{ | ||
int a=strcmp(strtok(str,":"),deletinggroup);//to cut the string using specific point and adds /0 to it | ||
if(!a) | ||
{ | ||
break; | ||
} | ||
else | ||
{ | ||
l1++; | ||
} | ||
} | ||
fclose(fp); | ||
fp1=fopen(gshadow,"r"); | ||
int l2=1; | ||
while((fgets(str,buffsize,fp))!=NULL) | ||
{ | ||
int a=strcmp(strtok(str,":"),deletinggroup);//a=used to store the output which is used for the cutting of lines | ||
if(!a) | ||
{ | ||
break; | ||
} | ||
else | ||
{ | ||
l2++; | ||
} | ||
} | ||
fclose(fp1); | ||
fp=fopen(group,"r"); | ||
fp2=fopen(newgroup,"w"); | ||
char ch = fgetc(fp); | ||
int temp=1;//temp=used to increment,when lines are jumped | ||
while(ch!=EOF)//here writing of the file occurs to get the new file without the group name you want to delete | ||
{ | ||
if(ch=='\n')//ch=reads every character of file | ||
{ | ||
temp++; | ||
} | ||
if(temp!=l1) | ||
{ | ||
putc(ch,fp2); | ||
} | ||
ch=fgetc(fp); | ||
} | ||
fclose(fp);//used to close the file | ||
fclose(fp2); | ||
fp1=fopen(gshadow,"r"); | ||
fp3=fopen(newgshadow,"w"); | ||
char ch2 = fgetc(fp1); | ||
int temp1=1; | ||
while(ch2!=EOF) | ||
{ | ||
if(ch2=='\n') | ||
{ | ||
temp1++; | ||
} | ||
if(temp1!=l1) | ||
{ | ||
putc(ch2,fp3); | ||
} | ||
ch2=fgetc(fp1); | ||
} | ||
fclose(fp1); | ||
fclose(fp3); | ||
remove(group);//removing the file | ||
rename(newgroup,group);//renaming the file | ||
printf("*********************************new group file********************************\n"); | ||
fp=fopen(group,"r"); | ||
char ch4=fgetc(fp); //printing the contents of file if necessary | ||
while(ch4!=EOF) | ||
{ | ||
printf("%c",ch4); | ||
ch4=fgetc(fp); | ||
} | ||
printf("\n"); | ||
printf("********************************************************************************\n"); | ||
printf("\n\n\n\n"); | ||
remove(gshadow); | ||
rename(newgshadow,gshadow); | ||
printf("**********************************new gshadow file***************************\n"); | ||
fp1=fopen(gshadow,"r"); | ||
char ch3=fgetc(fp1); | ||
while(ch3!=EOF) | ||
{ | ||
printf("%c",ch3); | ||
ch3=fgetc(fp1); | ||
} | ||
printf("\n"); | ||
printf("********************************************************************************\n"); | ||
} |