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
Joel Muaka Nsilulu
ISI-TP1-droits
Commits
0780f169
Commit
0780f169
authored
3 years ago
by
Joel Muaka Nsilulu
Browse files
Options
Downloads
Patches
Plain Diff
q9
parent
9b4c5c30
Branches
master
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
question8/check_pass.c
+2
-3
2 additions, 3 deletions
question8/check_pass.c
question9/pwg.c
+80
-0
80 additions, 0 deletions
question9/pwg.c
rendu.md
+1
-1
1 addition, 1 deletion
rendu.md
with
83 additions
and
4 deletions
question8/check_pass.c
+
2
−
3
View file @
0780f169
...
...
@@ -9,7 +9,6 @@ int check_pass(char *filename, uid_t user_id, char *password)
{
FILE
*
f
;
char
*
line
=
NULL
;
char
delim
[]
=
":"
;
char
*
pwd
;
char
*
uid
;
size_t
len
=
0
;
...
...
@@ -18,8 +17,8 @@ int check_pass(char *filename, uid_t user_id, char *password)
{
while
(
getline
(
&
line
,
&
len
,
f
)
!=
-
1
)
{
uid
=
strtok
(
line
,
delim
);
pwd
=
strtok
(
NULL
,
delim
);
uid
=
strtok
(
line
,
":"
);
pwd
=
strtok
(
NULL
,
":"
);
if
(
atoi
(
uid
)
==
user_id
)
{
fclose
(
f
);
...
...
This diff is collapsed.
Click to expand it.
question9/pwg.c
0 → 100644
+
80
−
0
View file @
0780f169
#include
<stdio.h>
#include
<stdlib.h>
#include
<string.h>
#include
<unistd.h>
#include
<pwd.h>
#define SIZE 32
int
main
(
int
argc
,
char
*
argv
[])
{
FILE
*
fsrc
,
*
fdst
;
char
*
lsrc
=
NULL
;
char
*
ldst
=
NULL
;
char
*
pwd
;
char
*
uid
;
char
not_found
=
1
;
size_t
len
=
0
;
ssize_t
size
;
char
new_pwd
[
SIZE
];
char
old_pwd
[
SIZE
];
uid_t
user_id
=
getuid
();
if
((
fsrc
=
fopen
(
"/home/admin/passwd"
,
"r"
))
!=
NULL
)
{
while
(
not_found
&&
(
size
=
getline
(
&
lsrc
,
&
len
,
fsrc
))
!=
-
1
)
{
uid
=
strtok
(
lsrc
,
":"
);
pwd
=
strtok
(
NULL
,
":"
);
if
(
atoi
(
uid
)
==
user_id
)
not_found
=
0
;
}
fclose
(
fsrc
);
}
if
(
size
!=
-
1
)
{
printf
(
"Enter password: "
);
fgets
(
old_pwd
,
SIZE
,
stdin
);
printf
(
"%s
\n
"
,
old_pwd
);
if
(
strcmp
(
pwd
,
crypt
(
old_pwd
,
"salt"
)))
{
fprintf
(
stderr
,
"Bad password
\n
"
);
free
(
lsrc
);
return
EXIT_FAILURE
;
}
printf
(
"Enter the new password: "
);
}
else
{
printf
(
"Enter password: "
);
}
fgets
(
new_pwd
,
SIZE
,
stdin
);
printf
(
"%s
\n
"
,
new_pwd
);
if
((
fsrc
=
fopen
(
"/home/admin/passwd"
,
"r"
))
!=
NULL
&&
(
fdst
=
fopen
(
"/home/admin/passwd.tmp"
,
"a"
))
!=
NULL
)
{
while
(
getline
(
&
ldst
,
&
len
,
fsrc
)
!=
-
1
)
{
char
*
a
=
strtok
(
ldst
,
":"
);
char
*
b
=
strtok
(
NULL
,
":"
);
if
(
atoi
(
a
)
!=
user_id
)
fprintf
(
fdst
,
"%s:%s:
\n
"
,
a
,
b
);
}
fprintf
(
fdst
,
"%d:%s:
\n
"
,
user_id
,
crypt
(
new_pwd
,
"salt"
));
free
(
ldst
);
fclose
(
fsrc
);
fclose
(
fdst
);
}
printf
(
"
\n
"
);
remove
(
"/home/admin/passwd"
);
rename
(
"/home/admin/passwd.tmp"
,
"/home/admin/passwd"
);
return
EXIT_SUCCESS
;
}
This diff is collapsed.
Click to expand it.
rendu.md
+
1
−
1
View file @
0780f169
...
...
@@ -73,7 +73,7 @@ Pour cette question, on peut se servir de la précédente pour créer les utilis
## Question 9
Le programme et les scripts dans le repertoire
*question9
*
.
Pour cette question, on ajoute aux données de la question précédente le fichier
**pwg.c**
qqui est une amélioration du fichier
**rmg.c*
*
.
## Question 10
...
...
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