login_cap.c (a2f733abcff64628b7771a47089628b7327a88bd) login_cap.c (90e914cd5ac1c8ecbf1ea88e9a65e7fa866c17a9)
1/*-
2 * Copyright (c) 1996 by
3 * Sean Eric Fagan <sef@kithrup.com>
4 * David Nugent <davidn@blaze.net.au>
5 * All rights reserved.
6 *
7 * Portions copyright (c) 1995,1997
8 * Berkeley Software Design, Inc.

--- 746 unchanged lines hidden (view full) ---

755 lc->lc_class, cap, res);
756 errno = ERANGE;
757 return error;
758 }
759
760 return val;
761}
762
1/*-
2 * Copyright (c) 1996 by
3 * Sean Eric Fagan <sef@kithrup.com>
4 * David Nugent <davidn@blaze.net.au>
5 * All rights reserved.
6 *
7 * Portions copyright (c) 1995,1997
8 * Berkeley Software Design, Inc.

--- 746 unchanged lines hidden (view full) ---

755 lc->lc_class, cap, res);
756 errno = ERANGE;
757 return error;
758 }
759
760 return val;
761}
762
763/*
764 * Extract a string capability expected to hold a specific value from a list.
765 *
766 * 'values' must be a NULL-terminated array of strings listing the possible
767 * values.
768 *
769 * A non-negative return code indicates success, and is the index of the value
770 * in 'values' the capability is set to.
771 *
772 * Negative return codes indicate an error:
773 * -4: 'lc' or 'cap' insufficiently initialized or not valid.
774 * -3: System error (allocation failure).
775 * -2: Capability not found or not a string.
776 * -1: Capability has a string value, but not one listed in 'values'.
777 */
778int
779login_getcapenum(login_cap_t *lc, const char *cap, const char * const *values)
780{
781 int ret, i;
782 char *cand;
783 const char * const *val;
763
784
785 if (lc == NULL || lc->lc_cap == NULL || cap == NULL || *cap == '\0')
786 return (-4);
764
787
788 ret = cgetstr(lc->lc_cap, cap, &cand);
789
790 if (ret == -1)
791 /* Cap not found. */
792 return (-2);
793 else if (ret < 0)
794 /* System error (normally, allocation failure). */
795 return (-3);
796
797 ret = -1;
798
799 for (i = 0, val = values; *val != NULL; val++)
800 if (strcmp(cand, *val) == 0) {
801 ret = i;
802 break;
803 }
804
805 free(cand);
806 return (ret);
807}
808
809
810
765/*
766 * login_getcapsize()
767 * From the login_cap_t <lc>, extract the capability <cap>, which is
768 * formatted as a size (e.g., "<cap>=10M"); it can also be "infinity".
769 * If not present, return <def>, or <error> if there is an error of
770 * some sort.
771 */
772

--- 141 unchanged lines hidden ---
811/*
812 * login_getcapsize()
813 * From the login_cap_t <lc>, extract the capability <cap>, which is
814 * formatted as a size (e.g., "<cap>=10M"); it can also be "infinity".
815 * If not present, return <def>, or <error> if there is an error of
816 * some sort.
817 */
818

--- 141 unchanged lines hidden ---