LOGIN_TIMES(3)
π LOGIN_TIMES(3) β like, the whole login-time-parsing situation bestie
okay so this page is all about parse_lt, in_lt, in_ltm, in_ltms and in_lts β they're the little functions that parse and check your login time periods β¨
πΈ LIBRARY
System Utilities Library (libutil, link it with -lutil) π«Ά
π SYNOPSIS
#include <sys/types.h>
#include <time.h>
#include <login_cap.h>
login_time_t
parse_lt(const char *str);
int
in_lt(const login_time_t *lt, time_t *ends);
int
in_ltm(const login_time_t *lt, struct tm *t, time_t *ends);
int
in_ltms(const login_time_t *lt, struct tm *t, time_t *ends);
int
in_lts(const login_time_t *lt, time_t *ends);
β¨ DESCRIPTION β¨
so this whole little squad of functions is for parsing and checking login and session times against a predefined list of allowed login times, exactly the way they're used in login.conf(5). very much the "who's allowed to log in and when" of it all π
the format for allowed and disallowed session times β those live in the times.allow and times.deny capability fields inside a login class β is a prefix that says which day(s) you mean (one or more 2- or 3-character day codes), then a start and end time in 24-hour format, separated by a hyphen. day codes can be concatenated together to pick specific days, or you can use the special mnemonics:
AnyandAllβ literally any/all days of the weekWkβ any day of the week except Saturdays and SundaysWdβ any weekend day
like, for example, this time period:
MoThFrSa1400-2200
reads as Monday, Thursday through Saturday, between 2pm and 10pm π
Wd0600-1800
means Saturday and Sunday, from 6am through 6pm, and
Any0400-1600
means any day of the week, between 4am and 4pm. slay.
β heads up bestie: all time periods reference system local time. no cap.
π¦ the struct, aka the main character
the parse_lt() function converts the ASCII representation of a time period into a structure of type login_time_t. it's defined like this:
typedef struct login_time
{
u_short lt_start; /* Start time */
u_short lt_end; /* End time */
u_char lt_dow; /* Days of week */
} login_time_t;
so lt_start and lt_end hold the number of minutes past midnight at which the described period begins and ends. and lt_dow is a bit field β one bit for each day of the week, plus one bit that's just vibing unused. there's a whole series of LTM_* macros you can use to test bits individually or in combination.
if no bits are set in that field β i.e. it holds the value LTM_NONE β then the entire period is assumed invalid. that's the convention used to mark the termination of an array of login_time_t values. and if parse_lt() hands you back a login_time_t whose lt_dow equals LTM_NONE, that means a parsing error happened π
π§ the checking functions
the rest of the functions let you test a given time_t or struct tm value against a specific time period, or against a whole array of time periods. iconic.
in_ltm() figures out whether the time described by the struct tm you passed as the second parameter falls inside the period described by the first parameter. you get a boolean back β basically yes or no, does it fall within the period. and if it does fall in the period, and the third parameter isn't NULL, you get the time at which the period ends, relative to the time you passed in. π
in_ltms() is the same deal as in_ltm(), except the first parameter has to be a pointer to an array of login_time_t objects β up to LC_MAXTIMES (that's 64 bestie) elements long, and terminated by an element whose lt_dow field is set to LTM_NONE.
and in_lt() and in_lts() are equivalent to in_ltm() and in_ltms() respectively, just with the second argument set to the current time as returned by localtime(3). convenient fr fr π«Ά
π₯ RETURN VALUES π₯
parse_lt()gives you back a filled-in structure of typelogin_time_tcontaining the parsed time period. if a parsing error happens, thelt_dowfield gets set toLTM_NONE(i.e.,0). πin_ltm()returns non-zero if the given time falls within the period described by thelogin_time_tpassed as the first parameter.in_ltms()returns the index of the first time period it finds where the given time falls β or-1if none of them apply π
π SEE ALSO π
getcap(3), login_cap(3), login_class(3), login.conf(5), termcap(5)
π HISTORY π
parse_lt(), in_lt(), in_ltm(), in_ltms() and in_lts() first appeared in FreeBSD 2.1.5. vintage β¨
mwah π that's the whole page bestie β brought to you by the Debian crew, dated May 10, 2020, from the LOGIN_TIMES(3) manual. go forth and schedule your logins responsibly π
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- Copyright (c) 1995 David Nugent <davidn@blaze.net.au>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms