Back to index

glibc  2.9
nis_print_group_entry.c
Go to the documentation of this file.
00001 /* Copyright (c) 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003    Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <alloca.h>
00021 #include <string.h>
00022 #include <libintl.h>
00023 #include <rpcsvc/nis.h>
00024 
00025 void
00026 nis_print_group_entry (const_nis_name group)
00027 {
00028   if (group != NULL && group[0] != '\0')
00029     {
00030       size_t grouplen = strlen (group);
00031       char buf[grouplen + 50];
00032       char leafbuf[grouplen + 3];
00033       char domainbuf[grouplen + 3];
00034       nis_result *res;
00035       char *cp, *cp2;
00036       u_int i;
00037 
00038       cp = stpcpy (buf, nis_leaf_of_r (group, leafbuf, sizeof (leafbuf) - 1));
00039       cp = stpcpy (cp, ".groups_dir");
00040       cp2 = nis_domain_of_r (group, domainbuf, sizeof (domainbuf) - 1);
00041       if (cp2 != NULL && cp2[0] != '\0')
00042        {
00043          *cp++ = '.';
00044          stpcpy (cp, cp2);
00045        }
00046       res = nis_lookup (buf, FOLLOW_LINKS | EXPAND_NAME);
00047 
00048       if (res == NULL)
00049        return;
00050 
00051       if (NIS_RES_STATUS (res) != NIS_SUCCESS
00052          || NIS_RES_NUMOBJ (res) != 1
00053          || __type_of (NIS_RES_OBJECT (res)) != NIS_GROUP_OBJ)
00054        {
00055          nis_freeresult (res);
00056          return;
00057        }
00058 
00059       char *mem_exp[NIS_RES_NUMOBJ (res)];
00060       char *mem_imp[NIS_RES_NUMOBJ (res)];
00061       char *mem_rec[NIS_RES_NUMOBJ (res)];
00062       char *nomem_exp[NIS_RES_NUMOBJ (res)];
00063       char *nomem_imp[NIS_RES_NUMOBJ (res)];
00064       char *nomem_rec[NIS_RES_NUMOBJ (res)];
00065       unsigned long mem_exp_cnt = 0, mem_imp_cnt = 0, mem_rec_cnt = 0;
00066       unsigned long nomem_exp_cnt = 0, nomem_imp_cnt = 0, nomem_rec_cnt = 0;
00067 
00068       for (i = 0;
00069           i < NIS_RES_OBJECT (res)->GR_data.gr_members.gr_members_len; ++i)
00070        {
00071          char *grmem =
00072            NIS_RES_OBJECT (res)->GR_data.gr_members.gr_members_val[i];
00073          int neg = grmem[0] == '-';
00074 
00075          switch (grmem[neg])
00076            {
00077            case '*':
00078              if (neg)
00079               {
00080                 nomem_imp[nomem_imp_cnt] = grmem;
00081                 ++nomem_imp_cnt;
00082               }
00083              else
00084               {
00085                 mem_imp[mem_imp_cnt] = grmem;
00086                 ++mem_imp_cnt;
00087               }
00088              break;
00089            case '@':
00090              if (neg)
00091               {
00092                 nomem_rec[nomem_rec_cnt] = grmem;
00093                 ++nomem_rec_cnt;
00094               }
00095              else
00096               {
00097                 mem_rec[mem_rec_cnt] = grmem;
00098                 ++mem_rec_cnt;
00099               }
00100              break;
00101            default:
00102              if (neg)
00103               {
00104                 nomem_exp[nomem_exp_cnt] = grmem;
00105                 ++nomem_exp_cnt;
00106               }
00107              else
00108               {
00109                 mem_exp[mem_exp_cnt] = grmem;
00110                 ++mem_exp_cnt;
00111               }
00112              break;
00113            }
00114        }
00115       {
00116        char buf[strlen (NIS_RES_OBJECT (res)->zo_domain) + 10];
00117        printf (_("Group entry for \"%s.%s\" group:\n"),
00118               NIS_RES_OBJECT (res)->zo_name,
00119               nis_domain_of_r (NIS_RES_OBJECT (res)->zo_domain,
00120                              buf, strlen (NIS_RES_OBJECT (res)->zo_domain)
00121                              + 10));
00122       }
00123       if (mem_exp_cnt)
00124        {
00125          fputs (_("    Explicit members:\n"), stdout);
00126          for (i = 0; i < mem_exp_cnt; ++i)
00127            printf ("\t%s\n", mem_exp[i]);
00128        }
00129       else
00130        fputs (_("    No explicit members\n"), stdout);
00131       if (mem_imp_cnt)
00132        {
00133          fputs (_("    Implicit members:\n"), stdout);
00134          for (i = 0; i < mem_imp_cnt; ++i)
00135            printf ("\t%s\n", &mem_imp[i][2]);
00136        }
00137       else
00138        fputs (_("    No implicit members\n"), stdout);
00139       if (mem_rec_cnt)
00140        {
00141          fputs (_("    Recursive members:\n"), stdout);
00142          for (i = 0; i < mem_rec_cnt; ++i)
00143            printf ("\t%s\n", &mem_rec[i][1]);
00144        }
00145       else
00146         fputs (_("    No recursive members\n"), stdout);
00147       if (nomem_exp_cnt)
00148        {
00149          fputs (_("    Explicit nonmembers:\n"), stdout);
00150          for (i = 0; i < nomem_exp_cnt; ++i)
00151            printf ("\t%s\n", &nomem_exp[i][1]);
00152        }
00153       else
00154        fputs (_("    No explicit nonmembers\n"), stdout);
00155       if (nomem_imp_cnt)
00156        {
00157          fputs (_("    Implicit nonmembers:\n"), stdout);
00158          for (i = 0; i < nomem_imp_cnt; ++i)
00159            printf ("\t%s\n", &mem_imp[i][3]);
00160        }
00161       else
00162        fputs (_("    No implicit nonmembers\n"), stdout);
00163       if (nomem_rec_cnt)
00164        {
00165          fputs (_("    Recursive nonmembers:\n"), stdout);
00166          for (i = 0; i < nomem_rec_cnt; ++i)
00167            printf ("\t%s=n", &nomem_rec[i][2]);
00168        }
00169       else
00170         fputs (_("    No recursive nonmembers\n"), stdout);
00171 
00172       nis_freeresult (res);
00173     }
00174 }