Back to index

glibc  2.9
nis_print.c
Go to the documentation of this file.
00001 /* Copyright (c) 1997, 1998, 1999, 2004 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 <time.h>
00021 #include <string.h>
00022 #include <libintl.h>
00023 
00024 #include <rpcsvc/nis.h>
00025 
00026 static const char *
00027 nis_nstype2str (const nstype type)
00028 {
00029 
00030 /* Name service names mustn't be translated, only UNKNOWN needs it */
00031 
00032   switch (type)
00033     {
00034     case NIS:
00035       return "NIS";
00036     case SUNYP:
00037       return "SUNYP";
00038     case IVY:
00039       return "IVY";
00040     case DNS:
00041       return "DNS";
00042     case X500:
00043       return "X500";
00044     case DNANS:
00045       return "DNANS";
00046     case XCHS:
00047       return "XCHS";
00048     case CDS:
00049       return "CDS";
00050     default:
00051       return N_("UNKNOWN");
00052     }
00053 }
00054 
00055 static void
00056 print_ttl (const uint32_t ttl)
00057 {
00058   uint32_t time, s, m, h;
00059 
00060   time = ttl;
00061 
00062   h = time / (60 * 60);
00063   time %= (60 * 60);
00064   m = time / 60;
00065   time %= 60;
00066   s = time;
00067   printf ("%u:%u:%u\n", h, m, s);
00068 }
00069 
00070 static void
00071 print_flags (const unsigned int flags)
00072 {
00073   fputs ("(", stdout);
00074 
00075   if (flags & TA_SEARCHABLE)
00076     fputs ("SEARCHABLE, ", stdout);
00077 
00078   if (flags & TA_BINARY)
00079     {
00080       fputs ("BINARY DATA", stdout);
00081       if (flags & TA_XDR)
00082        fputs (", XDR ENCODED", stdout);
00083       if (flags & TA_ASN1)
00084        fputs (", ASN.1 ENCODED", stdout);
00085       if (flags & TA_CRYPT)
00086        fputs (", ENCRYPTED", stdout);
00087     }
00088   else
00089     {
00090       fputs ("TEXTUAL DATA", stdout);
00091       if (flags & TA_SEARCHABLE)
00092        {
00093          if (flags & TA_CASE)
00094            fputs (", CASE INSENSITIVE", stdout);
00095          else
00096            fputs (", CASE SENSITIVE", stdout);
00097        }
00098     }
00099 
00100   fputs (")\n", stdout);
00101 }
00102 
00103 static void
00104 nis_print_objtype (enum zotypes type)
00105 {
00106   switch (type)
00107     {
00108     case NIS_BOGUS_OBJ:
00109       fputs (_("BOGUS OBJECT\n"), stdout);
00110       break;
00111     case NIS_NO_OBJ:
00112       fputs (_("NO OBJECT\n"), stdout);
00113       break;
00114     case NIS_DIRECTORY_OBJ:
00115       fputs (_("DIRECTORY\n"), stdout);
00116       break;
00117     case NIS_GROUP_OBJ:
00118       fputs (_("GROUP\n"), stdout);
00119       break;
00120     case NIS_TABLE_OBJ:
00121       fputs (_("TABLE\n"), stdout);
00122       break;
00123     case NIS_ENTRY_OBJ:
00124       fputs (_("ENTRY\n"), stdout);
00125       break;
00126     case NIS_LINK_OBJ:
00127       fputs (_("LINK\n"), stdout);
00128       break;
00129     case NIS_PRIVATE_OBJ:
00130       fputs (_("PRIVATE\n"), stdout);
00131       break;
00132     default:
00133       fputs (_("(Unknown object)\n"), stdout);
00134       break;
00135     }
00136 }
00137 
00138 void
00139 nis_print_rights (const unsigned int access)
00140 {
00141   char result[17];
00142   unsigned int acc;
00143   int i;
00144 
00145   acc = access;                    /* Parameter is const ! */
00146   result[i = 16] = '\0';
00147   while (i > 0)
00148     {
00149       i -= 4;
00150       result[i + 0] = (acc & NIS_READ_ACC) ? 'r' : '-';
00151       result[i + 1] = (acc & NIS_MODIFY_ACC) ? 'm' : '-';
00152       result[i + 2] = (acc & NIS_CREATE_ACC) ? 'c' : '-';
00153       result[i + 3] = (acc & NIS_DESTROY_ACC) ? 'd' : '-';
00154 
00155       acc >>= 8;
00156     }
00157   fputs (result, stdout);
00158 }
00159 libnsl_hidden_def (nis_print_rights)
00160 
00161 void
00162 nis_print_directory (const directory_obj *dir)
00163 {
00164   nis_server *sptr;
00165   unsigned int i;
00166 
00167   printf (_("Name : `%s'\n"), dir->do_name);
00168   printf (_("Type : %s\n"), nis_nstype2str (dir->do_type));
00169   sptr = dir->do_servers.do_servers_val;
00170   for (i = 0; i < dir->do_servers.do_servers_len; i++)
00171     {
00172       if (i == 0)
00173        fputs (_("Master Server :\n"), stdout);
00174       else
00175        fputs (_("Replicate :\n"), stdout);
00176       printf (_("\tName       : %s\n"), sptr->name);
00177       fputs (_("\tPublic Key : "), stdout);
00178       switch (sptr->key_type)
00179        {
00180        case NIS_PK_NONE:
00181          fputs (_("None.\n"), stdout);
00182          break;
00183        case NIS_PK_DH:
00184          printf (_("Diffie-Hellmann (%d bits)\n"),
00185                 (sptr->pkey.n_len - 1) * 4);
00186          /* sptr->pkey.n_len counts the last 0, too */
00187          break;
00188        case NIS_PK_RSA:
00189          printf (_("RSA (%d bits)\n"), (sptr->pkey.n_len - 1) * 4);
00190          break;
00191        case NIS_PK_KERB:
00192          fputs (_("Kerberos.\n"), stdout);
00193          break;
00194        default:
00195          printf (_("Unknown (type = %d, bits = %d)\n"), sptr->key_type,
00196                 (sptr->pkey.n_len - 1) * 4);
00197          break;
00198        }
00199 
00200       if (sptr->ep.ep_len != 0)
00201        {
00202          unsigned int j;
00203 
00204          endpoint *ptr;
00205          ptr = sptr->ep.ep_val;
00206          printf (_("\tUniversal addresses (%u)\n"), sptr->ep.ep_len);
00207          for (j = 0; j < sptr->ep.ep_len; j++)
00208            {
00209              printf ("\t[%d] - ", j + 1);
00210              if (ptr->proto != NULL && ptr->proto[0] != '\0')
00211               printf ("%s, ", ptr->proto);
00212              else
00213               printf ("-, ");
00214              if (ptr->family != NULL && ptr->family[0] != '\0')
00215               printf ("%s, ", ptr->family);
00216              else
00217               printf ("-, ");
00218              if (ptr->uaddr != NULL && ptr->uaddr[0] != '\0')
00219               printf ("%s\n", ptr->uaddr);
00220              else
00221               fputs ("-\n", stdout);
00222              ptr++;
00223            }
00224        }
00225       sptr++;
00226     }
00227 
00228   fputs (_("Time to live : "), stdout);
00229   print_ttl (dir->do_ttl);
00230   fputs (_("Default Access rights :\n"), stdout);
00231   if (dir->do_armask.do_armask_len != 0)
00232     {
00233       oar_mask *ptr;
00234 
00235       ptr = dir->do_armask.do_armask_val;
00236       for (i = 0; i < dir->do_armask.do_armask_len; i++)
00237        {
00238          nis_print_rights (ptr->oa_rights);
00239          printf (_("\tType         : %s\n"), nis_nstype2str (ptr->oa_otype));
00240          fputs (_("\tAccess rights: "), stdout);
00241          nis_print_rights (ptr->oa_rights);
00242          fputs ("\n", stdout);
00243          ptr++;
00244        }
00245     }
00246 }
00247 libnsl_hidden_def (nis_print_directory)
00248 
00249 void
00250 nis_print_group (const group_obj *obj)
00251 {
00252   unsigned int i;
00253 
00254   fputs (_("Group Flags :"), stdout);
00255   if (obj->gr_flags)
00256     printf ("0x%08X", obj->gr_flags);
00257   fputs (_("\nGroup Members :\n"), stdout);
00258 
00259   for (i = 0; i < obj->gr_members.gr_members_len; i++)
00260     printf ("\t%s\n", obj->gr_members.gr_members_val[i]);
00261 }
00262 libnsl_hidden_def (nis_print_group)
00263 
00264 void
00265 nis_print_table (const table_obj *obj)
00266 {
00267   unsigned int i;
00268 
00269   printf (_("Table Type          : %s\n"), obj->ta_type);
00270   printf (_("Number of Columns   : %d\n"), obj->ta_maxcol);
00271   printf (_("Character Separator : %c\n"), obj->ta_sep);
00272   printf (_("Search Path         : %s\n"), obj->ta_path);
00273   fputs (_("Columns             :\n"), stdout);
00274   for (i = 0; i < obj->ta_cols.ta_cols_len; i++)
00275     {
00276       printf (_("\t[%d]\tName          : %s\n"), i,
00277              obj->ta_cols.ta_cols_val[i].tc_name);
00278       fputs (_("\t\tAttributes    : "), stdout);
00279       print_flags (obj->ta_cols.ta_cols_val[i].tc_flags);
00280       fputs (_("\t\tAccess Rights : "), stdout);
00281       nis_print_rights (obj->ta_cols.ta_cols_val[i].tc_rights);
00282       fputc ('\n', stdout);
00283     }
00284 }
00285 libnsl_hidden_def (nis_print_table)
00286 
00287 void
00288 nis_print_link (const link_obj *obj)
00289 {
00290   fputs (_("Linked Object Type : "), stdout);
00291   nis_print_objtype (obj->li_rtype);
00292   printf (_("Linked to : %s\n"), obj->li_name);
00293   /* XXX Print the attributs here, if they exists */
00294 }
00295 libnsl_hidden_def (nis_print_link)
00296 
00297 void
00298 nis_print_entry (const entry_obj *obj)
00299 {
00300   unsigned int i;
00301 
00302   printf (_("\tEntry data of type %s\n"), obj->en_type);
00303   for (i = 0; i < obj->en_cols.en_cols_len; i++)
00304     {
00305       printf (_("\t[%u] - [%u bytes] "), i,
00306              obj->en_cols.en_cols_val[i].ec_value.ec_value_len);
00307       if ((obj->en_cols.en_cols_val[i].ec_flags & EN_CRYPT) == EN_CRYPT)
00308        fputs (_("Encrypted data\n"), stdout);
00309       else if ((obj->en_cols.en_cols_val[i].ec_flags & EN_BINARY) == EN_BINARY)
00310        fputs (_("Binary data\n"), stdout);
00311       else if (obj->en_cols.en_cols_val[i].ec_value.ec_value_len == 0)
00312        fputs ("'(nil)'\n", stdout);
00313       else
00314        printf ("'%.*s'\n",
00315               (int)obj->en_cols.en_cols_val[i].ec_value.ec_value_len,
00316               obj->en_cols.en_cols_val[i].ec_value.ec_value_val);
00317     }
00318 }
00319 libnsl_hidden_def (nis_print_entry)
00320 
00321 void
00322 nis_print_object (const nis_object * obj)
00323 {
00324   time_t buf;
00325 
00326   printf (_("Object Name   : %s\n"), obj->zo_name);
00327   printf (_("Directory     : %s\n"), obj->zo_domain);
00328   printf (_("Owner         : %s\n"), obj->zo_owner);
00329   printf (_("Group         : %s\n"), obj->zo_group);
00330   fputs (_("Access Rights : "), stdout);
00331   nis_print_rights (obj->zo_access);
00332   printf (_("\nTime to Live  : "));
00333   print_ttl (obj->zo_ttl);
00334   buf = obj->zo_oid.ctime;
00335   printf (_("Creation Time : %s"), ctime (&buf));
00336   buf = obj->zo_oid.mtime;
00337   printf (_("Mod. Time     : %s"), ctime (&buf));
00338   fputs (_("Object Type   : "), stdout);
00339   nis_print_objtype (obj->zo_data.zo_type);
00340   switch (obj->zo_data.zo_type)
00341     {
00342     case NIS_DIRECTORY_OBJ:
00343       nis_print_directory (&obj->zo_data.objdata_u.di_data);
00344       break;
00345     case NIS_GROUP_OBJ:
00346       nis_print_group (&obj->zo_data.objdata_u.gr_data);
00347       break;
00348     case NIS_TABLE_OBJ:
00349       nis_print_table (&obj->zo_data.objdata_u.ta_data);
00350       break;
00351     case NIS_ENTRY_OBJ:
00352       nis_print_entry (&obj->zo_data.objdata_u.en_data);
00353       break;
00354     case NIS_LINK_OBJ:
00355       nis_print_link (&obj->zo_data.objdata_u.li_data);
00356       break;
00357     case NIS_PRIVATE_OBJ:
00358       printf (_("    Data Length = %u\n"),
00359              obj->zo_data.objdata_u.po_data.po_data_len);
00360       break;
00361     default:
00362       break;
00363     }
00364 }
00365 libnsl_hidden_def (nis_print_object)
00366 
00367 void
00368 nis_print_result (const nis_result *res)
00369 {
00370   unsigned int i;
00371 
00372   printf (_("Status            : %s\n"), nis_sperrno (NIS_RES_STATUS (res)));
00373   printf (_("Number of objects : %u\n"), res->objects.objects_len);
00374 
00375   for (i = 0; i < res->objects.objects_len; i++)
00376     {
00377       printf (_("Object #%d:\n"), i);
00378       nis_print_object (&res->objects.objects_val[i]);
00379     }
00380 }