Print this page
*** NO COMMENTS ***

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/ypcmd/revnetgroup/getgroup.c
          +++ new/usr/src/cmd/ypcmd/revnetgroup/getgroup.c
↓ open down ↓ 15 lines elided ↑ open up ↑
  16   16   * If applicable, add the following below this CDDL HEADER, with the
  17   17   * fields enclosed by brackets "[]" replaced with your own identifying
  18   18   * information: Portions Copyright [yyyy] [name of copyright owner]
  19   19   *
  20   20   * CDDL HEADER END
  21   21   */
  22   22  
  23   23  /*
  24   24   * Copyright (c) 1996, by Sun Microsystems, Inc.
  25   25   * All rights reserved.
       26 + *
       27 + * Copyright 2012 Nexenta Systems, Inc.  All rights reserved.
  26   28   */
  27      -                                                            
  28      -#ident  "%Z%%M% %I%     %E% SMI"        /* SMI4.1 1.5 */
  29   29  
       30 +#include <stdlib.h>
  30   31  #include <stdio.h>
  31   32  #include <ctype.h>
  32   33  #include <string.h>
  33   34  #include "table.h"
  34   35  #include "util.h"
  35   36  #include "getgroup.h"
  36   37  
  37      -#define MAXGROUPLEN 1024
  38      -
  39   38  /*
  40   39   * Stolen mostly, from getnetgrent.c
  41   40   *
  42   41   * my_getgroup() performs the same function as _getgroup(), but operates
  43   42   * on /etc/netgroup directly, rather than doing yp lookups.
  44   43   *
  45   44   * /etc/netgroup must first loaded into a hash table so the matching
  46   45   * function can look up lines quickly.
  47   46   */
  48   47  
  49   48  
  50   49  /* To check for cycles in netgroups */
  51   50  struct list {
  52   51          char *name;
  53   52          struct list *nxt;
  54   53  };
  55   54  
  56      -
  57      -extern stringtable ngtable; /* stored info from /etc/netgroup */
  58      -
  59      -static struct grouplist *grouplist; /* stores a list of users in a group */
  60      -
  61   55  static char *any();
  62   56  static char *match();
  63   57  static char *fill();
  64      -static void freegrouplist();
  65      -static void doit();
  66   58  
  67   59  
  68      -
  69      -static void
  70      -freegrouplist()
       60 +void
       61 +freegrouplist(revhandle_t *hdl)
  71   62  {
  72      -        struct grouplist *gl;
       63 +        struct grouplist *gl, *next;
  73   64  
  74      -        for (gl = grouplist; gl != NULL; gl = gl->gl_nxt) {
       65 +        for (gl = hdl->grouplist; gl != NULL; gl = next) {
       66 +                next = gl->gl_nxt;
       67 +
  75   68                  FREE(gl->gl_name);
  76   69                  FREE(gl->gl_domain);
  77   70                  FREE(gl->gl_machine);
  78   71                  FREE(gl);
  79   72          }
  80      -        grouplist = NULL;
       73 +        hdl->grouplist = NULL;
  81   74  }
  82   75  
  83   76  
  84   77  
  85      -
  86      -struct grouplist *
  87      -my_getgroup(group)
  88      -        char *group;
  89      -{
  90      -        freegrouplist();
  91      -        doit(group, (struct list *) NULL);
  92      -        return (grouplist);
  93      -}
  94      -
  95      -
  96      -
  97      -
  98      -
  99   78  /*
 100   79   * recursive function to find the members of netgroup "group". "list" is
 101   80   * the path followed through the netgroups so far, to check for cycles.
 102   81   */
 103      -static void
 104      -doit(group, list)
 105      -        char *group;
 106      -        struct list *list;
       82 +void
       83 +doit(char *group, struct list *list, revhandle_t *hdl)
 107   84  {
 108   85          register char *p, *q;
 109   86          register struct list *ls;
 110   87          struct list tmplist;
 111   88          char *val;
 112   89          struct grouplist *gpls;
 113   90  
 114   91  
 115   92          /*
 116   93           * check for non-existing groups
 117   94           */
 118      -        if ((val = match(group)) == NULL) {
       95 +        if ((val = match(group, hdl)) == NULL) {
 119   96                  return;
 120   97          }
 121   98  
 122   99  
 123  100          /*
 124  101           * check for cycles
 125  102           */
 126  103          for (ls = list; ls != NULL; ls = ls->nxt) {
 127  104                  if (strcmp(ls->name, group) == 0) {
 128  105                          (void) fprintf(stderr,
 129      -                                "Cycle detected in /etc/netgroup: %s.\n",
 130      -                                group);
      106 +                            "Cycle detected in /etc/netgroup: %s.\n",
      107 +                            group);
 131  108                          return;
 132  109                  }
 133  110          }
 134  111  
 135  112  
 136  113          ls = &tmplist;
 137  114          ls->name = group;
 138  115          ls->nxt = list;
 139  116          list = ls;
 140  117  
↓ open down ↓ 9 lines elided ↑ open up ↑
 150  127  
 151  128                          if (!(p = fill(p, &gpls->gl_machine, ',')))  {
 152  129                                  goto syntax_error;
 153  130                          }
 154  131                          if (!(p = fill(p, &gpls->gl_name, ','))) {
 155  132                                  goto syntax_error;
 156  133                          }
 157  134                          if (!(p = fill(p, &gpls->gl_domain, ')'))) {
 158  135                                  goto syntax_error;
 159  136                          }
 160      -                        gpls->gl_nxt = grouplist;
 161      -                        grouplist = gpls;
      137 +                        gpls->gl_nxt = hdl->grouplist;
      138 +                        hdl->grouplist = gpls;
 162  139                  } else {
 163  140                          q = any(p, " \t\n#");
 164  141                          if (q && *q == '#')
 165  142                                  break;
 166  143                          *q = EOS;
 167      -                        doit(p, list);
      144 +                        doit(p, list, hdl);
 168  145                          *q = ' ';
 169  146                  }
 170  147                  p = any(p, " \t");
 171  148          }
 172  149          return;
 173  150  
 174  151  syntax_error:
 175  152          (void) fprintf(stderr, "syntax error in /etc/netgroup\n");
 176  153          (void) fprintf(stderr, "--- %s %s\n", group, val);
 177  154  }
↓ open down ↓ 57 lines elided ↑ open up ↑
 235  212          }
 236  213          return (NULL);
 237  214  }
 238  215  
 239  216  
 240  217  
 241  218  /*
 242  219   * The equivalent of yp_match. Returns the match, or NULL if there is none.
 243  220   */
 244  221  static char *
 245      -match(group)
 246      -        char *group;
      222 +match(char *group, revhandle_t *hdl)
 247  223  {
 248      -        return (lookup(ngtable, group));
      224 +        return (lookup(hdl->ngtable, group));
 249  225  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX