1 .\" Copyright (c) 1995 David Nugent <davidn@blaze.net.au>
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, is permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice immediately at the beginning of the file, without modification,
9 .\" this list of conditions, and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\" notice, this list of conditions and the following disclaimer in the
12 .\" documentation and/or other materials provided with the distribution.
13 .\" 3. This work was done expressly for inclusion into FreeBSD. Other use
14 .\" is permitted provided this notation is included.
15 .\" 4. Absolutely no warranty of function or purpose is made by the author
17 .\" 5. Modifications may be freely made to this file providing the above
18 .\" conditions are met.
29 .Nd functions for parsing and checking login time periods
37 .Fn parse_lt "const char *str"
39 .Fn in_ltm "const login_time_t *lt" "struct tm *t" "time_t *ends"
41 .Fn in_ltms "const login_time_t *lt" "struct tm *t" "time_t *ends"
43 This set of functions may be used for parsing and checking login and
44 session times against a predefined list of allowed login times as
48 The format of allowed and disallowed session times specified in the
52 capability fields in a login class are comprised of a prefix which
53 specifies one or more 2- or 3-character day codes, followed by
54 a start and end time in 24 hour format separated by a hyphen.
55 Day codes may be concatenated together to select specific days, or
56 the special mnemonics "Any" and "All" (for any/all days of the week),
57 "Wk" for any day of the week (excluding Saturdays and Sundays) and
58 "Wd" for any weekend day may be used.
60 For example, the following time period:
62 is interpreted as Monday, Thursday through Saturday between the hours
65 means Saturday and Sunday, between the hours of 6am through 6pm, and
67 means any day of the week, between 4am and 4pm.
69 Note that all time periods reference system local time.
73 function converts the ASCII representation of a time period into
78 typedef struct login_time
80 u_short lt_start; /* Start time */
81 u_short lt_end; /* End time */
82 u_char lt_dow; /* Days of week */
90 fields contain the number of minutes past midnight at which the
91 described period begins and ends.
94 field is a bit field, containing one bit for each day of the week
98 macros may be used for testing bits individually and in combination.
99 If no bits are set in this field - i.e., it contains the value
101 - then the entire period is assumed invalid.
102 This is used as a convention to mark the termination of an array
103 of login_time_t values.
112 then a parsing error was encountered.
114 The remaining functions provide the ability to test a given time_t or
115 struct tm value against a specific time period or array of time
119 function determines whether the given time described by the struct tm
120 passed as the second parameter falls within the period described
121 by the first parameter.
122 A boolean value is returned, indicating whether or not the time
123 specified falls within the period.
124 If the time does fall within the time period, and the third
125 parameter to the function is not NULL, the time at which the
126 period ends relative to the time passed is returned.
130 function is similar to
132 except that the first parameter must be a pointer to an array
133 of login_time_t objects, which is up to LC_MAXTIMES (64)
134 elements in length, and terminated by an element with its
141 function returns a filled in structure of type login_time_t containing the
143 If a parsing error occurs, the lt_dow field is set to
149 function returns non-zero if the given time falls within the period described
150 by the login_time_t passed as the first parameter.
154 function returns the index of the first time period found in which the given
155 time falls, or -1 if none of them apply.