Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-1-5]: src/lib/libutil Pullup 1.6-1.9 [itojun]:



details:   https://anonhg.NetBSD.org/src/rev/f768c51e2c4a
branches:  netbsd-1-5
changeset: 489892:f768c51e2c4a
user:      tv <tv%NetBSD.org@localhost>
date:      Wed Oct 18 03:44:59 2000 +0000

description:
Pullup 1.6-1.9 [itojun]:
/etc/login.conf is optional, so don't return NULL even if
there's none found.  addresses part of PR 11150.  sync with openbsd.

[releng: plus some cosmetic changes making 1.6-1.8 necessary]

diffstat:

 lib/libutil/login_cap.c |  171 +++++++++++++++++++----------------------------
 1 files changed, 70 insertions(+), 101 deletions(-)

diffs (truncated from 378 to 300 lines):

diff -r c4ea376cf320 -r f768c51e2c4a lib/libutil/login_cap.c
--- a/lib/libutil/login_cap.c   Wed Oct 18 03:41:36 2000 +0000
+++ b/lib/libutil/login_cap.c   Wed Oct 18 03:44:59 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: login_cap.c,v 1.5 2000/02/10 20:52:54 mjl Exp $ */
+/*     $NetBSD: login_cap.c,v 1.5.4.1 2000/10/18 03:44:59 tv Exp $     */
 
 /*-
  * Copyright (c) 1995,1997 Berkeley Software Design, Inc. All rights reserved.
@@ -33,6 +33,11 @@
  *
  *     BSDI login_cap.c,v 2.13 1998/02/07 03:17:05 prb Exp
  */
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: login_cap.c,v 1.5.4.1 2000/10/18 03:44:59 tv Exp $");
+#endif /* LIBC_SCCS and not lint */
  
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -52,27 +57,29 @@
 #include <string.h>
 #include <syslog.h>
 #include <unistd.h>
-
+#include <util.h>
 
-static char *classfiles[] = { _PATH_LOGIN_CONF, 0 };
-static void setuserpath __P((login_cap_t *, char *));
-static u_quad_t multiply __P((u_quad_t, u_quad_t));
-static u_quad_t strtolimit __P((char *, char **, int));
-static u_quad_t strtosize __P((char *, char **, int));
-static int gsetrl __P((login_cap_t *, int, char *, int type));
-static int setuserenv __P((login_cap_t *));
-static int isinfinite __P((const char *));
+static void    setuserpath(login_cap_t *, char *);
+static u_quad_t        multiply(u_quad_t, u_quad_t);
+static u_quad_t        strtolimit(char *, char **, int);
+static u_quad_t        strtosize(char *, char **, int);
+static int     gsetrl(login_cap_t *, int, char *, int type);
+static int     setuserenv(login_cap_t *);
+static int     isinfinite(const char *);
 
 login_cap_t *
-login_getclass(class)
-       char *class;
+login_getclass(char *class)
 {
+       char *classfiles[2];
        login_cap_t *lc;
        int res;
 
-       for (res = 0; classfiles[res]; ++res)
-               if (secure_path(classfiles[res]) < 0)
-                       return (0);
+       if (secure_path(_PATH_LOGIN_CONF) == 0) {
+               classfiles[0] = _PATH_LOGIN_CONF;
+               classfiles[1] = NULL;
+       } else {
+               classfiles[0] = NULL;
+       }
 
        if ((lc = malloc(sizeof(login_cap_t))) == NULL) {
                syslog(LOG_ERR, "%s:%d malloc: %m", __FILE__, __LINE__);
@@ -91,7 +98,15 @@
                return (0);
        }
 
-       if ((res = cgetent(&lc->lc_cap, classfiles, lc->lc_class)) != 0 ) {
+       /*
+        * Not having a login.conf file is not an error condition.
+        * The individual routines deal reasonably with missing
+        * capabilities and use default values.
+        */
+       if (classfiles[0] == NULL)
+               return(lc);
+
+       if ((res = cgetent(&lc->lc_cap, classfiles, lc->lc_class)) != 0) {
                lc->lc_cap = 0;
                switch (res) {
                case 1: 
@@ -127,18 +142,13 @@
 }
 
 login_cap_t *
-login_getpwclass(pwd)
-       const struct passwd *pwd;
+login_getpwclass(const struct passwd *pwd)
 {
        return login_getclass(pwd ? pwd->pw_class : NULL);
 }
 
 char *
-login_getcapstr(lc, cap, def, e)
-       login_cap_t *lc;
-       char *cap;
-       char *def;
-       char *e;
+login_getcapstr(login_cap_t *lc, char *cap, char *def, char *e)
 {
        char *res;
        int status;
@@ -165,11 +175,7 @@
 }
 
 quad_t
-login_getcaptime(lc, cap, def, e)
-       login_cap_t *lc;
-       char *cap;
-       quad_t def;
-       quad_t e;
+login_getcaptime(login_cap_t *lc, char *cap, quad_t def, quad_t e)
 {
        char *ep;
        char *res, *sres;
@@ -245,11 +251,7 @@
 }
 
 quad_t
-login_getcapnum(lc, cap, def, e)
-       login_cap_t *lc;
-       char *cap;
-       quad_t def;
-       quad_t e;
+login_getcapnum(login_cap_t *lc, char *cap, quad_t def, quad_t e)
 {
        char *ep;
        char *res;
@@ -293,11 +295,7 @@
 }
 
 quad_t
-login_getcapsize(lc, cap, def, e)
-       login_cap_t *lc;
-       char *cap;
-       quad_t def;
-       quad_t e;
+login_getcapsize(login_cap_t *lc, char *cap, quad_t def, quad_t e)
 {
        char *ep;
        char *res;
@@ -339,10 +337,7 @@
 }
 
 int
-login_getcapbool(lc, cap, def)
-       login_cap_t *lc;
-       char *cap;
-       u_int def;
+login_getcapbool(login_cap_t *lc, char *cap, u_int def)
 {
        if (!lc || !lc->lc_cap)
                return (def);
@@ -351,8 +346,7 @@
 }
 
 void
-login_close(lc)
-       login_cap_t *lc;
+login_close(login_cap_t *lc)
 {
        if (lc) {
                if (lc->lc_class)
@@ -365,33 +359,29 @@
        }
 }
 
-#define        CTIME   1
-#define        CSIZE   2
-#define        CNUMB   3
+#define        R_CTIME 1
+#define        R_CSIZE 2
+#define        R_CNUMB 3
 
 static struct {
        int     what;
        int     type;
        char *  name;
 } r_list[] = {
-       { RLIMIT_CPU,           CTIME, "cputime", },
-       { RLIMIT_FSIZE,         CSIZE, "filesize", },
-       { RLIMIT_DATA,          CSIZE, "datasize", },
-       { RLIMIT_STACK,         CSIZE, "stacksize", },
-       { RLIMIT_RSS,           CSIZE, "memoryuse", },
-       { RLIMIT_MEMLOCK,       CSIZE, "memorylocked", },
-       { RLIMIT_NPROC,         CNUMB, "maxproc", },
-       { RLIMIT_NOFILE,        CNUMB, "openfiles", },
-       { RLIMIT_CORE,          CSIZE, "coredumpsize", },
+       { RLIMIT_CPU,           R_CTIME, "cputime", },
+       { RLIMIT_FSIZE,         R_CSIZE, "filesize", },
+       { RLIMIT_DATA,          R_CSIZE, "datasize", },
+       { RLIMIT_STACK,         R_CSIZE, "stacksize", },
+       { RLIMIT_RSS,           R_CSIZE, "memoryuse", },
+       { RLIMIT_MEMLOCK,       R_CSIZE, "memorylocked", },
+       { RLIMIT_NPROC,         R_CNUMB, "maxproc", },
+       { RLIMIT_NOFILE,        R_CNUMB, "openfiles", },
+       { RLIMIT_CORE,          R_CSIZE, "coredumpsize", },
        { -1, 0, 0 }
 };
 
 static int
-gsetrl(lc, what, name, type)
-       login_cap_t *lc;
-       int what;
-       char *name;
-       int type;
+gsetrl(login_cap_t *lc, int what, char *name, int type)
 {
        struct rlimit rl;
        struct rlimit r;
@@ -410,19 +400,19 @@
 #define        RMAX    r.rlim_max
 
        switch (type) {
-       case CTIME:
+       case R_CTIME:
                RCUR = login_getcaptime(lc, name, RCUR, RCUR);
                RMAX = login_getcaptime(lc, name, RMAX, RMAX);
                rl.rlim_cur = login_getcaptime(lc, name_cur, RCUR, RCUR);
                rl.rlim_max = login_getcaptime(lc, name_max, RMAX, RMAX);
                break;
-       case CSIZE:
+       case R_CSIZE:
                RCUR = login_getcapsize(lc, name, RCUR, RCUR);
                RMAX = login_getcapsize(lc, name, RMAX, RMAX);
                rl.rlim_cur = login_getcapsize(lc, name_cur, RCUR, RCUR);
                rl.rlim_max = login_getcapsize(lc, name_max, RMAX, RMAX);
                break;
-       case CNUMB:
+       case R_CNUMB:
                RCUR = login_getcapnum(lc, name, RCUR, RCUR);
                RMAX = login_getcapnum(lc, name, RMAX, RMAX);
                rl.rlim_cur = login_getcapnum(lc, name_cur, RCUR, RCUR);
@@ -443,8 +433,7 @@
 }
 
 static int
-setuserenv(lc)
-       login_cap_t *lc;
+setuserenv(login_cap_t *lc)
 {
        char *stop = ", \t";
        int i, count;
@@ -452,7 +441,7 @@
        char **res;
        char *str = login_getcapstr(lc, "setenv", NULL, NULL);
                  
-       if(str == NULL || *str == '\0')
+       if (str == NULL || *str == '\0')
                return 0;
        
        /* count the sub-strings */
@@ -460,13 +449,13 @@
                ptr += strcspn(ptr, stop);
                if (*ptr)
                        ptr++;
-               }
+       }
 
        /* allocate ptr array and string */
        count = i;
-       res = malloc( count * sizeof(char *) + strlen(str) + 1 );
+       res = malloc(count * sizeof(char *) + strlen(str) + 1);
 
-       if(!res)
+       if (!res)
                return -1;
        
        ptr = (char *)res + count * sizeof(char *);
@@ -478,13 +467,13 @@
                ptr += strcspn(ptr, stop);
                if (*ptr)
                        *ptr++ = '\0';
-               }
+       }
        
        res[i] = NULL;
 
        for (i = 0; i < count && res[i]; i++) {
                if (*res[i] != '\0') {
-                       if ((ptr = strchr(res[i], '=')))
+                       if ((ptr = strchr(res[i], '=')) != NULL)
                                *ptr++ = '\0';
                        else 
                                ptr = "";
@@ -496,11 +485,8 @@
        return 0;
 }
 
-
 int
-setclasscontext(class, flags)
-       char *class;
-       u_int flags;
+setclasscontext(char *class, u_int flags)
 {
        int ret;
        login_cap_t *lc;
@@ -515,11 +501,7 @@



Home | Main Index | Thread Index | Old Index