Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
OpenLDAP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Oren Tirosh
OpenLDAP
Commits
939ca770
Commit
939ca770
authored
21 years ago
by
Howard Chu
Browse files
Options
Downloads
Patches
Plain Diff
Avoid mktime/gmtime in parse_time(), just compute time_t ourselves.
parent
49da68a2
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
servers/slapd/overlays/ppolicy.c
+48
-33
48 additions, 33 deletions
servers/slapd/overlays/ppolicy.c
with
48 additions
and
33 deletions
servers/slapd/overlays/ppolicy.c
+
48
−
33
View file @
939ca770
...
...
@@ -191,11 +191,54 @@ static struct schema_info pwd_UsSchema[] = {
static
ldap_pvt_thread_mutex_t
chk_syntax_mutex
;
static
time_t
ppolicy_timegm
(
struct
tm
*
t
)
{
static
int
moffset
[
12
]
=
{
0
,
31
,
59
,
90
,
120
,
151
,
181
,
212
,
243
,
273
,
304
,
334
};
time_t
ret
;
/* t->tm_year is years since 1900 */
/* calculate days from years since 1970 (epoch) */
ret
=
t
->
tm_year
-
70
;
ret
*=
365L
;
/* count leap days in preceding years */
ret
+=
((
t
->
tm_year
-
69
)
>>
2
);
/* calculate days from months */
ret
+=
moffset
[
t
->
tm_mon
];
/* add in this year's leap day, if any */
if
(((
t
->
tm_year
&
3
)
==
0
)
&&
(
t
->
tm_mon
>
1
))
{
ret
++
;
}
/* add in days in this month */
ret
+=
(
t
->
tm_mday
-
1
);
/* convert to hours */
ret
*=
24L
;
ret
+=
t
->
tm_hour
;
/* convert to minutes */
ret
*=
60L
;
ret
+=
t
->
tm_min
;
/* convert to seconds */
ret
*=
60L
;
ret
+=
t
->
tm_sec
;
/* return the result */
return
ret
;
}
static
time_t
parse_time
(
char
*
atm
)
{
struct
tm
tml
,
tmg
;
time_t
t
;
struct
tm
tm
;
if
(
!
atm
)
return
(
time_t
)
-
1
;
...
...
@@ -206,38 +249,10 @@ parse_time( char *atm )
*/
if
(
strcmp
(
atm
,
"00000101000000Z"
)
==
0
)
return
(
time_t
)
0
;
/*
* else parse the time and return it's time_t value. This will be -1 if the
* text isn't a valid time string.
*/
strptime
(
atm
,
"%Y%m%d%H%M%SZ"
,
&
tml
);
tml
.
tm_isdst
=
-
1
;
t
=
mktime
(
&
tml
);
if
(
t
==
(
time_t
)
-
1
)
return
t
;
/* mktime() assumes localtime. Compute the offset to GMT.
* else parse the time and return it's time_t value.
*/
ldap_pvt_thread_mutex_lock
(
&
gmtime_mutex
);
tmg
=
*
gmtime
(
&
t
);
ldap_pvt_thread_mutex_unlock
(
&
gmtime_mutex
);
tmg
.
tm_mday
-=
tml
.
tm_mday
;
tmg
.
tm_hour
-=
tml
.
tm_hour
;
if
(
tmg
.
tm_mday
)
{
/* The difference should only be +/- 1 day, but may
* fall outside this range at the beginning/end of a month
*/
if
(
tmg
.
tm_mday
>
1
)
tmg
.
tm_mday
=
-
1
;
else
if
(
tmg
.
tm_mday
<
-
1
)
tmg
.
tm_mday
=
1
;
tmg
.
tm_hour
+=
tmg
.
tm_mday
>
0
?
24
:
-
24
;
}
if
(
tmg
.
tm_hour
)
t
-=
tmg
.
tm_hour
*
3600
;
tmg
.
tm_min
-=
tml
.
tm_min
;
if
(
tmg
.
tm_min
)
t
-=
tmg
.
tm_min
*
60
;
tmg
.
tm_sec
-=
tml
.
tm_sec
;
if
(
tmg
.
tm_sec
)
t
-=
tmg
.
tm_sec
;
return
t
;
strptime
(
atm
,
"%Y%m%d%H%M%SZ"
,
&
tm
);
return
ppolicy_timegm
(
&
tm
);
}
static
int
...
...
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