Index: releng/4.3/lib/libutil/login.conf.5 =================================================================== --- releng/4.3/lib/libutil/login.conf.5 (revision 83739) +++ releng/4.3/lib/libutil/login.conf.5 (revision 83740) @@ -1,380 +1,382 @@ .\" Copyright (c) 1996 David Nugent .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, is permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice immediately at the beginning of the file, without modification, .\" this list of conditions, and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. This work was done expressly for inclusion into FreeBSD. Other use .\" is permitted provided this notation is included. .\" 4. Absolutely no warranty of function or purpose is made by the author .\" David Nugent. .\" 5. Modifications may be freely made to this file providing the above .\" conditions are met. .\" .\" $FreeBSD$ .\" .Dd November 22, 1996 .Dt LOGIN.CONF 5 .Os FreeBSD .Sh NAME .Nm login.conf .Nd login class capability database .Sh SYNOPSIS .Pa /etc/login.conf , .Pa ~/.login_conf .Sh DESCRIPTION .Nm contains various attributes and capabilities of login classes. A login class (an optional annotation against each record in the user account database, .Pa /etc/master.passwd ) determines session accounting, resource limits and user environment settings. It is used by various programs in the system to set up a user's login environment and to enforce policy, accounting and administrative restrictions. It also provides the means by which users are able to be authenticated to the system and the types of authentication available. .Pp A special record "default" in the system user class capability database .Pa /etc/login.conf is used automatically for any non-root user without a valid login class in .Pa /etc/master.passwd . A user with a uid of 0 without a valid login class will use the record "root" if it exists, or "default" if not. .Pp In .Fx , users may individually create a file called .Pa .login_conf in their home directory using the same format, consisting of a single entry with a record id of "me". If present, this file is used by .Xr login 1 to set user-defined environment settings which override those specified in the system login capabilities database. Only a subset of login capabilities may be overridden, typically those which do not involve authentication, resource limits and accounting. +NOTE: this feature is compile-time disabled by default due to potential +security risks. .Pp Records in a class capabilities database consist of a number of colon-separated fields. The first entry for each record gives one or more names that a record is to be known by, each separated by a '|' character. The first name is the most common abbreviation. The last name given should be a long name that is more descriptive of the capability entry, and all others are synonyms. All names but the last should be in lower case and contain no blanks; the last name may contain upper case characters and blanks for readability. .Pp See .Xr getcap 3 for a more in-depth description of the format of a capability database. .Sh CAPABILITIES Fields within each record in the database follow the .Xr getcap 3 conventions for boolean, type string .Ql \&= and type numeric .Ql \&# , although type numeric is depreciated in favour of the string format and either form is accepted for a numeric datum. Values fall into the following categories: .Bl -tag -width "program" .It file Path name to a data file .It program Path name to an executable file .It list A list of values (or pairs of values) separated by commas or spaces .It path A space or comma separated list of path names, following the usual csh conventions (leading tilde with and without username being expanded to home directories etc.) .It number A numeric value, either decimal (default), hexadecimal (with leading 0x), or octal (with a leading 0). With a numeric type, only one numeric value is allowed. Numeric types may also be specified in string format (ie. the capability tag being delimited from the value by '=' instead of '#'). Whichever method is used, then all records in the database must use the same method to allow values to be correctly overridden in interpolated records. .It size A number which expresses a size. The default interpretation of a value is the number of bytes, but a suffix may specify alternate units: .Bl -tag -offset indent -compact -width xxxx .It b explicitly selects 512-byte blocks .It k selects kilobytes (1024 bytes) .It m specifies a multiplier of 1 megabyte (1048576 bytes), .It g specifies units of gigabytes, and .It t represents terabytes. .El A size value is a numeric quantity and case of the suffix is not significant. Concatenated values are added together. .It time A period of time, by default in seconds. A prefix may specify a different unit: .Bl -tag -offset indent -compact -width xxxx .It y indicates the number of 365 day years, .It w indicates the number of weeks, .It d the number of days, .It h the number of hours, .It m the number of minutes, and .It s the number of seconds. .El Concatenated values are added together. For example, 2 hours and 40 minutes may be written either as 9600s, 160m or 2h40m. .El .Pp The usual convention to interpolate capability entries using the special .Em tc=value notation may be used. .Pp .Sh RESOURCE LIMITS .Bl -column coredumpsize indent indent .It Sy "Name Type Notes Description .It "cputime time CPU usage limit. .It "filesize size Maximum file size limit. .It "datasize size Maximum data size limit. .It "stacksize size Maximum stack size limit. .It "coredumpsize size Maximum coredump size limit. .It "memoryuse size Maximum of core memory use size limit. .It "memorylocked size Maximum locked in core memory size limit. .It "maxproc number Maximum number of processes. .It "openfiles number Maximum number of open files per process. .It "sbsize size Maximum permitted socketbuffer size. .El .Pp These resource limit entries actually specify both the maximum and current limits (see .Xr getrlimit 2 ) . The current (soft) limit is the one normally used, although the user is permitted to increase the current limit to the maximum (hard) limit. The maximum and current limits may be specified individually by appending a -max or -cur to the capability name. .Pp .Sh ENVIRONMENT .Bl -column ignorenologin indent xbinxxusrxbin .It Sy "Name Type Notes Description .It "charset string Set $MM_CHARSET environment variable to the specified value. .It "hushlogin bool false Same as having a ~/.hushlogin file. .It "ignorenologin bool false Login not prevented by nologin. .It "lang string Set $LANG environment variable to the specified value. .It "manpath path Default search path for manpages. .It "nologin file If the file exists it will be displayed and the login session will be terminated. .It "path path /bin /usr/bin Default search path. .It "priority number Initial priority (nice) level. .It "requirehome bool false Require a valid home directory to login. .It "setenv list A comma-separated list of environment variables and values to which they are to be set. .It "shell prog Session shell to execute rather than the shell specified in the passwd file. The SHELL environment variable will contain the shell specified in the password file. .It "term string Default terminal type if not able to determine from other means. .It "timezone string Default value of $TZ environment variable. .It "umask number 022 Initial umask. Should always have a leading 0 to ensure octal interpretation. .It "welcome file /etc/motd File containing welcome message. .El .Pp .Sh AUTHENTICATION .Bl -column minpasswordlen indent indent .It Sy "Name Type Notes Description .It "minpasswordlen number 6 The minimum length a local password may be. .It "passwd_format string md5 The encryption format that new or changed passwords will use. Valid values include "md5" and "des". NIS clients using a .No non- Ns Fx NIS server should probably use "des". .\" .It "approve program Program to approve login. .It "mixpasswordcase bool true Whether .Xr passwd 1 will warn the user if an all lower case password is entered. .It "copyright file File containing additional copyright information .\".It "widepasswords bool false Use the wide password format. The wide password .\" format allows up to 128 significant characters in the password. .It "host.allow list List of remote host wildcards from which users in the class may access. .It "host.deny list List of remote host wildcards from which users in the class may not access. .It "times.allow list List of time periods during which logins are allowed. .It "times.deny list List of time periods during which logins are disallowed. .It "ttys.allow list List of ttys and ttygroups which users in the class may use for access. .It "ttys.deny list List of ttys and ttygroups which users in the class may not use for access. .El .Pp These fields are intended to be used by .Xr passwd 1 and other programs in the login authentication system. .Pp Capabilities that set environment variables are scanned for both .Ql \&~ and .Ql \&$ characters, which are substituted for a user's home directory and name respectively. To pass these characters literally into the environment variable, escape the character by preceding it with a backslash '\\'. .Pp The .Em host.allow and .Em host.deny entries are comma separated lists used for checking remote access to the system, and consist of a list of hostnames and/or IP addresses against which remote network logins are checked. Items in these lists may contain wildcards in the form used by shell programs for wildcard matching (See .Xr fnmatch 3 for details on the implementation). The check on hosts is made against both the remote system's Internet address and hostname (if available). If both lists are empty or not specified, then logins from any remote host are allowed. If host.allow contains one or more hosts, then only remote systems matching any of the items in that list are allowed to log in. If host.deny contains one or more hosts, then a login from any matching hosts will be disallowed. .Pp The .Em times.allow and .Em times.deny entries consist of a comma-separated list of time periods during which the users in a class are allowed to be logged in. These are expressed as one or more day codes followed by a start and end times expressed in 24 hour format, separated by a hyphen or dash. For example, MoThSa0200-1300 translates to Monday, Thursday and Saturday between the hours of 2 am and 1 p.m.. If both of these time lists are empty, users in the class are allowed access at any time. If .Em times.allow is specified, then logins are only allowed during the periods given. If .Em times.deny is specified, then logins are denied during the periods given, regardless of whether one of the periods specified in .Em times.allow applies. .Pp Note that .Xr login 1 enforces only that the actual login falls within periods allowed by these entries. Further enforcement over the life of a session requires a separate daemon to monitor transitions from an allowed period to a non-allowed one. .Pp The .Em ttys.allow and .Em ttys.deny entries contain a comma-separated list of tty devices (without the /dev/ prefix) that a user in a class may use to access the system, and/or a list of ttygroups (See .Xr getttyent 3 and .Xr ttys 5 for information on ttygroups). If neither entry exists, then the choice of login device used by the user is unrestricted. If only .Em ttys.allow is specified, then the user is restricted only to ttys in the given group or device list. If only .Em ttys.deny is specified, then the user is prevented from using the specified devices or devices in the group. If both lists are given and are non-empty, the user is restricted to those devices allowed by ttys.allow that are not available by ttys.deny. .Sh ACCOUNTING LIMITS .Bl -column host.accounted indent indent .It Sy "Name Type Notes Description .It "accounted bool false Enable session time accounting for all users in this class. .It "autodelete time Time after expiry when account is auto-deleted. .It "bootfull bool false Enable 'boot only if ttygroup is full' strategy when terminating sessions. .It "daytime time Maximum login time per day. .It "expireperiod time Time for expiry allocation. .It "graceexpire time Grace days for expired account. .It "gracetime time Additional grace login time allowed. .It "host.accounted list List of remote host wildcards from which login sessions will be accounted. .It "host.exempt list List of remote host wildcards from which login session accounting is exempted. .It "idletime time Maximum idle time before logout. .It "monthtime time Maximum login time per month. .It "passwordtime time Used by .Xr passwd 1 to set next password expiry date. .It "refreshtime time New time allowed on account refresh. .It "refreshperiod str How often account time is refreshed. .It "sessiontime time Maximum login time per session. .It "sessionlimit number Maximum number of concurrent login sessions on ttys in any group. .It "ttys.accounted list List of ttys and ttygroups for which login accounting is active. .It "ttys.exempt list List of ttys and ttygroups for which login accounting is exempt. .It "warnexpire time Advance notice for pending account expiry. .It "warnpassword time Advance notice for pending password expiry. .It "warntime time Advance notice for pending out-of-time. .It "weektime time Maximum login time per week. .El .Pp These fields are used by the time accounting system, which regulates, controls and records user login access. .Pp The .Em ttys.accounted and .Em ttys.exempt fields operate in a similar manner to .Em ttys.allow and .Em ttys.deny as explained above. Similarly with the .Em host.accounted and .Em host.exempt lists. .Sh SEE ALSO .Xr cap_mkdb 1 , .Xr login 1 , .Xr getcap 3 , .Xr getttyent 3 , .Xr login_cap 3 , .Xr login_class 3 , .Xr passwd 5 , .Xr ttys 5 Index: releng/4.3/lib/libutil/login_cap.c =================================================================== --- releng/4.3/lib/libutil/login_cap.c (revision 83739) +++ releng/4.3/lib/libutil/login_cap.c (revision 83740) @@ -1,800 +1,807 @@ /*- * Copyright (c) 1996 by * Sean Eric Fagan * David Nugent * All rights reserved. * * Portions copyright (c) 1995,1997 * Berkeley Software Design, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, is permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice immediately at the beginning of the file, without modification, * this list of conditions, and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. This work was done expressly for inclusion into FreeBSD. Other use * is permitted provided this notation is included. * 4. Absolutely no warranty of function or purpose is made by the authors. * 5. Modifications may be freely made to this file providing the above * conditions are met. * * Low-level routines relating to the user capabilities database * * $FreeBSD$ */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* * allocstr() * Manage a single static pointer for handling a local char* buffer, * resizing as necessary to contain the string. * * allocarray() * Manage a static array for handling a group of strings, resizing * when necessary. */ static int lc_object_count = 0; static size_t internal_stringsz = 0; static char * internal_string = NULL; static size_t internal_arraysz = 0; static char ** internal_array = NULL; static char * allocstr(char *str) { char *p; size_t sz = strlen(str) + 1; /* realloc() only if necessary */ if (sz <= internal_stringsz) p = strcpy(internal_string, str); else if ((p = realloc(internal_string, sz)) != NULL) { internal_stringsz = sz; internal_string = strcpy(p, str); } return p; } static char ** allocarray(size_t sz) { char **p; if (sz <= internal_arraysz) p = internal_array; else if ((p = realloc(internal_array, sz * sizeof(char*))) != NULL) { internal_arraysz = sz; internal_array = p; } return p; } /* * arrayize() * Turn a simple string separated by any of * the set of into an array. The last element * of the array will be NULL, as is proper. * Free using freearraystr() */ static char ** arrayize(char *str, const char *chars, int *size) { int i; char *ptr; char **res = NULL; /* count the sub-strings */ for (i = 0, ptr = str; *ptr; i++) { int count = strcspn(ptr, chars); ptr += count; if (*ptr) ++ptr; } /* alloc the array */ if ((ptr = allocstr(str)) != NULL) { if ((res = allocarray(++i)) == NULL) free(str); else { /* now split the string */ i = 0; while (*ptr) { int count = strcspn(ptr, chars); res[i++] = ptr; ptr += count; if (*ptr) *ptr++ = '\0'; } res[i] = NULL; } } if (size) *size = i; return res; } /* * login_close() * Frees up all resources relating to a login class * */ void login_close(login_cap_t * lc) { if (lc) { free(lc->lc_style); free(lc->lc_class); free(lc->lc_cap); free(lc); if (--lc_object_count == 0) { free(internal_string); free(internal_array); internal_array = NULL; internal_arraysz = 0; internal_string = NULL; internal_stringsz = 0; cgetclose(); } } } /* * login_getclassbyname() get the login class by its name. * If the name given is NULL or empty, the default class * LOGIN_DEFCLASS (ie. "default") is fetched. If the * 'dir' argument contains a non-NULL non-empty string, * then the file _FILE_LOGIN_CONF is picked up from that * directory instead of the system login database. * Return a filled-out login_cap_t structure, including * class name, and the capability record buffer. */ login_cap_t * login_getclassbyname(char const *name, const struct passwd *pwd) { login_cap_t *lc; if ((lc = malloc(sizeof(login_cap_t))) != NULL) { int r, i = 0; uid_t euid = 0; gid_t egid = 0; const char *msg = NULL; const char *dir = (pwd == NULL) ? NULL : pwd->pw_dir; char userpath[MAXPATHLEN]; static char *login_dbarray[] = { NULL, NULL, NULL }; - /* Switch to user mode before checking/reading its ~/.login_conf */ - /* - some NFSes have root read access disabled. */ +#ifndef _FILE_LOGIN_CONF_WORKS + dir = NULL; +#endif + /* + * Switch to user mode before checking/reading its ~/.login_conf + * - some NFSes have root read access disabled. + * + * XXX: This fails to configure additional groups. + */ if (dir) { euid = geteuid(); egid = getegid(); (void)setegid(pwd->pw_gid); (void)seteuid(pwd->pw_uid); } if (dir && snprintf(userpath, MAXPATHLEN, "%s/%s", dir, _FILE_LOGIN_CONF) < MAXPATHLEN) { login_dbarray[i] = userpath; if (_secure_path(userpath, pwd->pw_uid, pwd->pw_gid) != -1) i++; /* only use 'secure' data */ } if (_secure_path(_PATH_LOGIN_CONF, 0, 0) != -1) login_dbarray[i++] = _PATH_LOGIN_CONF; login_dbarray[i] = NULL; memset(lc, 0, sizeof(login_cap_t)); lc->lc_cap = lc->lc_class = lc->lc_style = NULL; if (name == NULL || *name == '\0') name = LOGIN_DEFCLASS; switch (cgetent(&lc->lc_cap, login_dbarray, (char*)name)) { case -1: /* Failed, entry does not exist */ if (strcmp(name, LOGIN_MECLASS) == 0) break; /* Don't retry default on 'me' */ if (i == 0) r = -1; else if ((r = open(login_dbarray[0], O_RDONLY)) >= 0) close(r); /* * If there's at least one login class database, * and we aren't searching for a default class * then complain about a non-existent class. */ if (r >= 0 || strcmp(name, LOGIN_DEFCLASS) != 0) syslog(LOG_ERR, "login_getclass: unknown class '%s'", name); /* fall-back to default class */ name = LOGIN_DEFCLASS; msg = "%s: no default/fallback class '%s'"; if (cgetent(&lc->lc_cap, login_dbarray, (char*)name) != 0 && r >= 0) break; /* Fallthru - just return system defaults */ case 0: /* success! */ if ((lc->lc_class = strdup(name)) != NULL) { if (dir) { (void)seteuid(euid); (void)setegid(egid); } ++lc_object_count; return lc; } msg = "%s: strdup: %m"; break; case -2: msg = "%s: retrieving class information: %m"; break; case -3: msg = "%s: 'tc=' reference loop '%s'"; break; case 1: msg = "couldn't resolve 'tc=' reference in '%s'"; break; default: msg = "%s: unexpected cgetent() error '%s': %m"; break; } if (dir) { (void)seteuid(euid); (void)setegid(egid); } if (msg != NULL) syslog(LOG_ERR, msg, "login_getclass", name); free(lc); } return NULL; } /* * login_getclass() * Get the login class for the system (only) login class database. * Return a filled-out login_cap_t structure, including * class name, and the capability record buffer. */ login_cap_t * login_getclass(const char *cls) { return login_getclassbyname(cls, NULL); } /* * login_getclass() * Get the login class for a given password entry from * the system (only) login class database. * If the password entry's class field is not set, or * the class specified does not exist, then use the * default of LOGIN_DEFCLASS (ie. "default"). * Return a filled-out login_cap_t structure, including * class name, and the capability record buffer. */ login_cap_t * login_getpwclass(const struct passwd *pwd) { const char *cls = NULL; if (pwd != NULL) { cls = pwd->pw_class; if (cls == NULL || *cls == '\0') cls = (pwd->pw_uid == 0) ? LOGIN_DEFROOTCLASS : LOGIN_DEFCLASS; } return login_getclassbyname(cls, pwd); } /* * login_getuserclass() * Get the login class for a given password entry, allowing user * overrides via ~/.login_conf. */ login_cap_t * login_getuserclass(const struct passwd *pwd) { return login_getclassbyname(LOGIN_MECLASS, pwd); } /* * login_getcapstr() * Given a login_cap entry, and a capability name, return the * value defined for that capability, a defualt if not found, or * an error string on error. */ char * login_getcapstr(login_cap_t *lc, const char *cap, char *def, char *error) { char *res; int ret; if (lc == NULL || cap == NULL || lc->lc_cap == NULL || *cap == '\0') return def; if ((ret = cgetstr(lc->lc_cap, (char *)cap, &res)) == -1) return def; return (ret >= 0) ? res : error; } /* * login_getcaplist() * Given a login_cap entry, and a capability name, return the * value defined for that capability split into an array of * strings. */ char ** login_getcaplist(login_cap_t *lc, const char *cap, const char *chars) { char *lstring; if (chars == NULL) chars = ", \t"; if ((lstring = login_getcapstr(lc, (char*)cap, NULL, NULL)) != NULL) return arrayize(lstring, chars, NULL); return NULL; } /* * login_getpath() * From the login_cap_t , get the capability which is * formatted as either a space or comma delimited list of paths * and append them all into a string and separate by semicolons. * If there is an error of any kind, return . */ char * login_getpath(login_cap_t *lc, const char *cap, char * error) { char *str; if ((str = login_getcapstr(lc, (char*)cap, NULL, NULL)) == NULL) str = error; else { char *ptr = str; while (*ptr) { int count = strcspn(ptr, ", \t"); ptr += count; if (*ptr) *ptr++ = ':'; } } return str; } static int isinfinite(const char *s) { static const char *infs[] = { "infinity", "inf", "unlimited", "unlimit", "-1", NULL }; const char **i = &infs[0]; while (*i != NULL) { if (strcasecmp(s, *i) == 0) return 1; ++i; } return 0; } static u_quad_t rmultiply(u_quad_t n1, u_quad_t n2) { u_quad_t m, r; int b1, b2; static int bpw = 0; /* Handle simple cases */ if (n1 == 0 || n2 == 0) return 0; if (n1 == 1) return n2; if (n2 == 1) return n1; /* * sizeof() returns number of bytes needed for storage. * This may be different from the actual number of useful bits. */ if (!bpw) { bpw = sizeof(u_quad_t) * 8; while (((u_quad_t)1 << (bpw-1)) == 0) --bpw; } /* * First check the magnitude of each number. If the sum of the * magnatude is way to high, reject the number. (If this test * is not done then the first multiply below may overflow.) */ for (b1 = bpw; (((u_quad_t)1 << (b1-1)) & n1) == 0; --b1) ; for (b2 = bpw; (((u_quad_t)1 << (b2-1)) & n2) == 0; --b2) ; if (b1 + b2 - 2 > bpw) { errno = ERANGE; return (UQUAD_MAX); } /* * Decompose the multiplication to be: * h1 = n1 & ~1 * h2 = n2 & ~1 * l1 = n1 & 1 * l2 = n2 & 1 * (h1 + l1) * (h2 + l2) * (h1 * h2) + (h1 * l2) + (l1 * h2) + (l1 * l2) * * Since h1 && h2 do not have the low bit set, we can then say: * * (h1>>1 * h2>>1 * 4) + ... * * So if (h1>>1 * h2>>1) > (1<<(bpw - 2)) then the result will * overflow. * * Finally, if MAX - ((h1 * l2) + (l1 * h2) + (l1 * l2)) < (h1*h2) * then adding in residual amout will cause an overflow. */ m = (n1 >> 1) * (n2 >> 1); if (m >= ((u_quad_t)1 << (bpw-2))) { errno = ERANGE; return (UQUAD_MAX); } m *= 4; r = (n1 & n2 & 1) + (n2 & 1) * (n1 & ~(u_quad_t)1) + (n1 & 1) * (n2 & ~(u_quad_t)1); if ((u_quad_t)(m + r) < m) { errno = ERANGE; return (UQUAD_MAX); } m += r; return (m); } /* * login_getcaptime() * From the login_cap_t , get the capability , which is * formatted as a time (e.g., "=10h3m2s"). If is not * present in , return ; if there is an error of some kind, * return . */ rlim_t login_getcaptime(login_cap_t *lc, const char *cap, rlim_t def, rlim_t error) { char *res, *ep, *oval; int r; rlim_t tot; errno = 0; if (lc == NULL || lc->lc_cap == NULL) return def; /* * Look for in lc_cap. * If it's not there (-1), return . * If there's an error, return . */ if ((r = cgetstr(lc->lc_cap, (char *)cap, &res)) == -1) return def; else if (r < 0) { errno = ERANGE; return error; } /* "inf" and "infinity" are special cases */ if (isinfinite(res)) return RLIM_INFINITY; /* * Now go through the string, turning something like 1h2m3s into * an integral value. Whee. */ errno = 0; tot = 0; oval = res; while (*res) { rlim_t tim = strtoq(res, &ep, 0); rlim_t mult = 1; if (ep == NULL || ep == res || errno != 0) { invalid: syslog(LOG_WARNING, "login_getcaptime: class '%s' bad value %s=%s", lc->lc_class, cap, oval); errno = ERANGE; return error; } /* Look for suffixes */ switch (*ep++) { case 0: ep--; break; /* end of string */ case 's': case 'S': /* seconds */ break; case 'm': case 'M': /* minutes */ mult = 60; break; case 'h': case 'H': /* hours */ mult = 60L * 60L; break; case 'd': case 'D': /* days */ mult = 60L * 60L * 24L; break; case 'w': case 'W': /* weeks */ mult = 60L * 60L * 24L * 7L; break; case 'y': case 'Y': /* 365-day years */ mult = 60L * 60L * 24L * 365L; break; default: goto invalid; } res = ep; tot += rmultiply(tim, mult); if (errno) goto invalid; } return tot; } /* * login_getcapnum() * From the login_cap_t , extract the numerical value . * If it is not present, return for a default, and return * if there is an error. * Like login_getcaptime(), only it only converts to a number, not * to a time; "infinity" and "inf" are 'special.' */ rlim_t login_getcapnum(login_cap_t *lc, const char *cap, rlim_t def, rlim_t error) { char *ep, *res; int r; rlim_t val; if (lc == NULL || lc->lc_cap == NULL) return def; /* * For BSDI compatibility, try for the tag= first */ if ((r = cgetstr(lc->lc_cap, (char *)cap, &res)) == -1) { long lval; /* string capability not present, so try for tag# as numeric */ if ((r = cgetnum(lc->lc_cap, (char *)cap, &lval)) == -1) return def; /* Not there, so return default */ else if (r >= 0) return (rlim_t)lval; } if (r < 0) { errno = ERANGE; return error; } if (isinfinite(res)) return RLIM_INFINITY; errno = 0; val = strtoq(res, &ep, 0); if (ep == NULL || ep == res || errno != 0) { syslog(LOG_WARNING, "login_getcapnum: class '%s' bad value %s=%s", lc->lc_class, cap, res); errno = ERANGE; return error; } return val; } /* * login_getcapsize() * From the login_cap_t , extract the capability , which is * formatted as a size (e.g., "=10M"); it can also be "infinity". * If not present, return , or if there is an error of * some sort. */ rlim_t login_getcapsize(login_cap_t *lc, const char *cap, rlim_t def, rlim_t error) { char *ep, *res, *oval; int r; rlim_t tot; if (lc == NULL || lc->lc_cap == NULL) return def; if ((r = cgetstr(lc->lc_cap, (char *)cap, &res)) == -1) return def; else if (r < 0) { errno = ERANGE; return error; } if (isinfinite(res)) return RLIM_INFINITY; errno = 0; tot = 0; oval = res; while (*res) { rlim_t siz = strtoq(res, &ep, 0); rlim_t mult = 1; if (ep == NULL || ep == res || errno != 0) { invalid: syslog(LOG_WARNING, "login_getcapsize: class '%s' bad value %s=%s", lc->lc_class, cap, oval); errno = ERANGE; return error; } switch (*ep++) { case 0: /* end of string */ ep--; break; case 'b': case 'B': /* 512-byte blocks */ mult = 512; break; case 'k': case 'K': /* 1024-byte Kilobytes */ mult = 1024; break; case 'm': case 'M': /* 1024-k kbytes */ mult = 1024 * 1024; break; case 'g': case 'G': /* 1Gbyte */ mult = 1024 * 1024 * 1024; break; case 't': case 'T': /* 1TBte */ mult = 1024LL * 1024LL * 1024LL * 1024LL; break; default: goto invalid; } res = ep; tot += rmultiply(siz, mult); if (errno) goto invalid; } return tot; } /* * login_getcapbool() * From the login_cap_t , check for the existance of the capability * of . Return if ->lc_cap is NULL, otherwise return * the whether or not exists there. */ int login_getcapbool(login_cap_t *lc, const char *cap, int def) { if (lc == NULL || lc->lc_cap == NULL) return def; return (cgetcap(lc->lc_cap, (char *)cap, ':') != NULL); } /* * login_getstyle() * Given a login_cap entry , and optionally a type of auth , * and optionally a style