Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
ISI-TP1-droits
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Esteban Collard
ISI-TP1-droits
Commits
6dfe12dd
Commit
6dfe12dd
authored
4 years ago
by
Esteban Collard
Browse files
Options
Downloads
Patches
Plain Diff
fin q8
parent
07247802
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
question8/Makefile
+11
-0
11 additions, 0 deletions
question8/Makefile
question8/check_pass.c
+39
-0
39 additions, 0 deletions
question8/check_pass.c
question8/check_pass.h
+6
-0
6 additions, 0 deletions
question8/check_pass.h
question8/rmg.c
+34
-0
34 additions, 0 deletions
question8/rmg.c
with
90 additions
and
0 deletions
question8/Makefile
0 → 100644
+
11
−
0
View file @
6dfe12dd
all
:
rmg
rmg
:
check_pass.o
gcc
-o
$@
$^
check_pass.o
:
check_pass.c
gcc
-c
-o
$@
$^
clean
:
rm
-rf
*
.o
rm
-rf
rmg
This diff is collapsed.
Click to expand it.
question8/check_pass.c
0 → 100644
+
39
−
0
View file @
6dfe12dd
#include
"check_pass.h"
int
verification_motDePasse
(
int
identifiant
,
char
*
pwd
){
FILE
*
fp
;
char
*
line
=
NULL
;
size_t
len
=
0
;
ssize_t
read
;
char
*
idRead
=
NULL
;
char
*
pwdRead
=
NULL
;
fp
=
fopen
(
"/home/admin/passwd"
,
"r"
);
if
(
fp
==
NULL
){
printf
(
"Erreur fichier mot de passe
\n
"
);
exit
(
EXIT_FAILURE
);
}
while
((
read
=
getline
(
&
line
,
&
len
,
fp
))
!=
-
1
)
{
idRead
=
strtok
(
line
,
":"
);
if
(
atoi
(
idRead
)
==
identifiant
){
pwdRead
=
strtok
(
NULL
,
":"
);
pwdRead
=
strtok
(
pwdRead
,
"
\n
"
);
fclose
(
fp
);
return
strcmp
(
pwdRead
,
pwd
);
}
}
}
int
getIdentifiant
(
char
*
file
)
{
struct
stat
stats
;
if
(
stat
(
file
,
&
stats
)
==
0
)
{
return
stats
.
st_gid
;
}
else
{
perror
(
"impossible de recuperer les identifiants du fichier"
);
exit
(
EXIT_FAILURE
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
question8/check_pass.h
0 → 100644
+
6
−
0
View file @
6dfe12dd
#include
<stdlib.h>
#include
<stdio.h>
#include
<sys/stat.h>
int
verification_motDePasse
(
int
identifiant
,
char
*
pwd
);
int
getIdentifiant
(
char
*
file
);
\ No newline at end of file
This diff is collapsed.
Click to expand it.
question8/rmg.c
0 → 100644
+
34
−
0
View file @
6dfe12dd
#include
<stdlib.h>
#include
<stdio.h>
#include
"check_pass.h"
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
argc
<
3
){
printf
(
"parametre non valide
\n
"
);
printf
(
"exemple utilisation
\n
"
);
printf
(
"rmg file password
\n
"
);
}
else
{
uid_t
uid
=
getuid
();
gid_t
gid
=
getuid
();
// Verification id
if
(
getIdentifiant
(
argv
[
1
])
!=
uid
){
printf
(
"id non valide
\n
"
);
exit
(
EXIT_FAILURE
);
}
//verification mdp
if
(
verification_motDePasse
(
gid
,
argv
[
2
])){
if
(
remove
(
argv
[
1
])
==
0
){
printf
(
"Fichier supprimer
\n
"
);
}
else
{
printf
(
"Impossible de supprimer le fichier
\n
"
);
}
}
else
{
printf
(
"Mot de passe non valide
\n
"
);
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment