Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
pike
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
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pikelang
pike
Commits
9f466967
Commit
9f466967
authored
Apr 20, 1998
by
Henrik (Grubba) Grubbström
Browse files
Options
Downloads
Patches
Plain Diff
f_get_all_users() and f_get_all_groups() now don't need to copy all the data.
Rev: src/modules/system/passwords.c:1.13
parent
b968359d
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/modules/system/passwords.c
+25
-129
25 additions, 129 deletions
src/modules/system/passwords.c
with
25 additions
and
129 deletions
src/modules/system/passwords.c
+
25
−
129
View file @
9f466967
/*
/*
* $Id: passwords.c,v 1.1
2
1998/04/
19 15:02:44 marcus
Exp $
* $Id: passwords.c,v 1.1
3
1998/04/
20 12:33:21 grubba
Exp $
*
*
* Password handling for Pike.
* Password handling for Pike.
*
*
...
@@ -22,7 +22,7 @@
...
@@ -22,7 +22,7 @@
#include
"global.h"
#include
"global.h"
RCSID
(
"$Id: passwords.c,v 1.1
2
1998/04/
19 15:02:44 marcus
Exp $"
);
RCSID
(
"$Id: passwords.c,v 1.1
3
1998/04/
20 12:33:21 grubba
Exp $"
);
#include
"module_support.h"
#include
"module_support.h"
#include
"interpret.h"
#include
"interpret.h"
...
@@ -282,22 +282,19 @@ void f_getpwent(INT32 args)
...
@@ -282,22 +282,19 @@ void f_getpwent(INT32 args)
mt_unlock
(
&
password_protection_mutex
);
mt_unlock
(
&
password_protection_mutex
);
}
}
/* This is used to save the pwents during THREADS_ALLOW(). */
struct
pike_pwent
{
struct
pike_pwent
*
next
;
struct
passwd
pw
;
};
void
f_get_all_users
(
INT32
args
)
void
f_get_all_users
(
INT32
args
)
{
{
struct
pike_pwent
*
ppwents
=
NULL
;
int
nels
=
0
;
struct
array
*
a
;
struct
array
*
a
;
pop_n_elems
(
args
);
pop_n_elems
(
args
);
a
=
low_allocate_array
(
0
,
10
);
/* NOTE: We need THREADS_ALLOW()/THREADS_DISALLOW() here
* to avoid deadlocks.
*/
THREADS_ALLOW
();
THREADS_ALLOW
();
mt_lock
(
&
password_protection_mutex
);
mt_lock
(
&
password_protection_mutex
);
THREADS_DISALLOW
();
setpwent
();
setpwent
();
while
(
1
)
while
(
1
)
...
@@ -305,55 +302,19 @@ void f_get_all_users(INT32 args)
...
@@ -305,55 +302,19 @@ void f_get_all_users(INT32 args)
struct
passwd
*
pw
;
struct
passwd
*
pw
;
struct
pike_pwent
*
nppwent
;
struct
pike_pwent
*
nppwent
;
THREADS_ALLOW
();
pw
=
getpwent
();
pw
=
getpwent
();
if
(
!
pw
)
break
;
nppwent
=
malloc
(
sizeof
(
struct
pike_pwent
)
+
strlen
(
pw
->
pw_name
)
+
strlen
(
pw
->
pw_passwd
)
+
strlen
(
pw
->
pw_gecos
)
+
strlen
(
pw
->
pw_dir
)
+
strlen
(
pw
->
pw_shell
)
+
10
);
if
(
!
nppwent
)
{
/* FIXME: Out of memory... */
break
;
}
/* If pw changes here we lose... */
/* Copy pw to nppwent. */
nppwent
->
pw
.
pw_uid
=
pw
->
pw_uid
;
nppwent
->
pw
.
pw_gid
=
pw
->
pw_gid
;
nppwent
->
pw
.
pw_name
=
(
char
*
)(
nppwent
+
1
);
nppwent
->
pw
.
pw_passwd
=
nppwent
->
pw
.
pw_name
+
strlen
(
pw
->
pw_name
)
+
1
;
nppwent
->
pw
.
pw_gecos
=
nppwent
->
pw
.
pw_passwd
+
strlen
(
pw
->
pw_passwd
)
+
1
;
nppwent
->
pw
.
pw_dir
=
nppwent
->
pw
.
pw_gecos
+
strlen
(
pw
->
pw_gecos
)
+
1
;
nppwent
->
pw
.
pw_shell
=
nppwent
->
pw
.
pw_dir
+
strlen
(
pw
->
pw_dir
)
+
1
;
strcpy
(
nppwent
->
pw
.
pw_name
,
pw
->
pw_name
);
strcpy
(
nppwent
->
pw
.
pw_passwd
,
pw
->
pw_passwd
);
strcpy
(
nppwent
->
pw
.
pw_gecos
,
pw
->
pw_gecos
);
strcpy
(
nppwent
->
pw
.
pw_dir
,
pw
->
pw_dir
);
strcpy
(
nppwent
->
pw
.
pw_shell
,
pw
->
pw_shell
);
/* Link it in */
nppwent
->
next
=
ppwents
;
ppwents
=
nppwent
;
nels
++
;
}
endpwent
();
mt_unlock
(
&
password_protection_mutex
);
THREADS_DISALLOW
();
THREADS_DISALLOW
();
a
=
low_allocate_array
(
0
,
nels
);
if
(
!
pw
)
break
;
while
(
ppwents
)
{
struct
pike_pwent
*
oppwent
=
ppwents
;
push_pwent
(
&
(
ppwents
->
pw
)
);
push_pwent
(
pw
);
a
=
append_array
(
a
,
sp
-
1
);
a
=
append_array
(
a
,
sp
-
1
);
pop_stack
();
pop_stack
();
ppwents
=
ppwents
->
next
;
free
(
oppwent
);
}
}
endpwent
();
mt_unlock
(
&
password_protection_mutex
);
push_array
(
a
);
push_array
(
a
);
}
}
...
@@ -407,104 +368,39 @@ void f_getgrent(INT32 args)
...
@@ -407,104 +368,39 @@ void f_getgrent(INT32 args)
mt_unlock
(
&
password_protection_mutex
);
mt_unlock
(
&
password_protection_mutex
);
}
}
/* This is used to save the grents during THREADS_ALLOW(). */
struct
pike_grent
{
struct
pike_grent
*
next
;
struct
group
gr
;
};
void
f_get_all_groups
(
INT32
args
)
void
f_get_all_groups
(
INT32
args
)
{
{
struct
pike_grent
*
pgrents
=
NULL
;
int
nels
=
0
;
struct
array
*
a
;
struct
array
*
a
;
pop_n_elems
(
args
);
pop_n_elems
(
args
);
a
=
low_allocate_array
(
0
,
10
);
/* NOTE: We need THREADS_ALLOW()/THREADS_DISALLOW() here
* to avoid deadlocks.
*/
THREADS_ALLOW
();
THREADS_ALLOW
();
mt_lock
(
&
password_protection_mutex
);
mt_lock
(
&
password_protection_mutex
);
THREADS_DISALLOW
();
setgrent
();
setgrent
();
while
(
1
)
while
(
1
)
{
{
struct
group
*
gr
;
struct
group
*
gr
;
struct
pike_grent
*
npgrent
;
char
**
members
;
THREADS_ALLOW
();
gr
=
getgrent
();
gr
=
getgrent
();
if
(
!
gr
)
break
;
npgrent
=
malloc
(
sizeof
(
struct
pike_grent
)
+
strlen
(
gr
->
gr_name
)
+
strlen
(
gr
->
gr_passwd
)
+
5
);
if
(
!
npgrent
)
{
/* Out of memory... */
break
;
}
/* If gr changes here we lose... */
if
(
gr
->
gr_mem
)
{
int
n_mem
=
0
;
int
memlen
=
0
;
char
*
textspace
=
NULL
;
while
(
gr
->
gr_mem
[
n_mem
])
{
memlen
+=
strlen
(
gr
->
gr_mem
[
n_mem
++
])
+
1
;
}
n_mem
+=
2
;
/* One NULL and one for buffer. */
npgrent
->
gr
.
gr_mem
=
malloc
(
n_mem
*
sizeof
(
char
*
)
+
memlen
);
if
(
!
npgrent
->
gr
.
gr_mem
)
{
/* Out of memory... */
free
(
npgrent
);
break
;
}
textspace
=
(
char
*
)(
npgrent
->
gr
.
gr_mem
+
n_mem
-
1
)
+
1
;
n_mem
=
0
;
while
(
gr
->
gr_mem
[
n_mem
])
{
strcpy
(
textspace
,
gr
->
gr_mem
[
n_mem
]);
npgrent
->
gr
.
gr_mem
[
n_mem
]
=
textspace
;
textspace
+=
strlen
(
textspace
)
+
1
;
n_mem
++
;
}
npgrent
->
gr
.
gr_mem
[
n_mem
]
=
NULL
;
}
npgrent
->
gr
.
gr_gid
=
gr
->
gr_gid
;
npgrent
->
gr
.
gr_name
=
(
char
*
)(
npgrent
+
1
)
+
1
;
npgrent
->
gr
.
gr_passwd
=
npgrent
->
gr
.
gr_name
+
strlen
(
gr
->
gr_name
)
+
1
;
strcpy
(
npgrent
->
gr
.
gr_name
,
gr
->
gr_name
);
strcpy
(
npgrent
->
gr
.
gr_passwd
,
gr
->
gr_passwd
);
npgrent
->
next
=
pgrents
;
pgrents
=
npgrent
;
nels
++
;
}
endgrent
();
mt_unlock
(
&
password_protection_mutex
);
THREADS_DISALLOW
();
THREADS_DISALLOW
();
a
=
low_allocate_array
(
0
,
nels
);
if
(
!
gr
)
break
;
while
(
pgrents
)
{
struct
pike_grent
*
opgrent
=
pgrents
;
push_grent
(
&
(
pgrents
->
gr
)
);
push_grent
(
gr
);
a
=
append_array
(
a
,
sp
-
1
);
a
=
append_array
(
a
,
sp
-
1
);
pop_stack
();
pop_stack
();
pgrents
=
pgrents
->
next
;
if
(
opgrent
->
gr
.
gr_mem
)
{
free
(
opgrent
->
gr
.
gr_mem
);
}
free
(
opgrent
);
}
}
endgrent
();
mt_unlock
(
&
password_protection_mutex
);
push_array
(
a
);
push_array
(
a
);
}
}
...
...
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