Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

vid.C

Go to the documentation of this file.
00001 // Copyright (C) 2001, Compaq Computer Corporation
00002 // 
00003 // This file is part of Vesta.
00004 // 
00005 // Vesta 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 // Vesta 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 Vesta; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019 //
00020 // vid.C
00021 // Last modified on Sun Jun  5 21:49:51 EDT 2005 by ken@xorian.net
00022 //      modified on Wed Jul 11 22:03:49 PDT 2001 by mann
00023 //
00024 // Get information about a user from the repository.
00025 //
00026 
00027 #include <Basics.H>
00028 #include <Text.H>
00029 #include <VestaConfig.H>
00030 #include <VestaSource.H>
00031 #include <VDirSurrogate.H>
00032 #if !defined(__sun__)
00033 extern "C" {
00034 #include <getopt.h>
00035 }
00036 #endif
00037 
00038 using std::cout;
00039 using std::cerr;
00040 using std::endl;
00041 
00042 Text program_name;
00043 
00044 void
00045 Usage()
00046 {
00047     cerr << "Usage: " << program_name <<
00048       " [-R repos] [user]" << endl << endl;
00049     exit(3);
00050 }
00051 
00052 int
00053 main(int argc, char* argv[])
00054 {
00055     try {
00056         program_name = argv[0];
00057         Text repos;
00058 
00059         int c;
00060         for (;;) {
00061             c = getopt(argc, argv, "h?R:");
00062             if (c == EOF) break;
00063             switch (c) {
00064               case 'R': repos = optarg; break;
00065               case 'h':
00066               case '?':
00067               default:
00068                 Usage();
00069             }
00070         }
00071 
00072         Text lhost(VDirSurrogate::defaultHost());
00073         Text lport(VDirSurrogate::defaultPort());
00074         bool default_repos = true;
00075         if (repos != "") {
00076           default_repos = false;
00077           int colon = repos.FindCharR(':');
00078           if (colon == -1) {
00079             lhost = repos;
00080             repos = repos + ":" + lport;
00081           } else {
00082             lhost = repos.Sub(0, colon);
00083             lport = repos.Sub(colon+1);
00084           }
00085         }
00086 
00087         Text subject;
00088         AccessControl::Identity subject_ident = 0;
00089         if (optind < argc) {
00090             subject = argv[optind];
00091             if(subject.FindChar('@') == -1)
00092               {
00093                 subject += "@";
00094                 subject += AccessControl::realm;
00095               }
00096             subject_ident =
00097               NEW_CONSTR(AccessControl::GlobalIdentityRep, (subject.cchars()));
00098         }
00099 
00100         AccessControl::IdInfo result;
00101 
00102         // Note that we always pass NULL for "who", so there's no way
00103         // to override the user who's requesting access.
00104         VDirSurrogate::getUserInfo(result, NULL, subject_ident, lhost, lport);
00105 
00106         cout << "User names and aliases:" << endl;
00107         for(unsigned int i = 0; i < result.names.length(); i++)
00108           {
00109             cout << "  " << result.names[i] << endl;
00110           }
00111 
00112         cout << "Groups:" << endl;
00113         for(unsigned int i = 0; i < result.groups.length(); i++)
00114           {
00115             cout << "  " << result.groups[i] << endl;
00116           }
00117 
00118         cout << "Unix (NFS) user ID:          " << result.unix_uid << endl;
00119 
00120         // If we're inquiring about ourselves at the local repository,
00121         // make sure our UNIX user ID matches what the repository has.
00122         // If not, print a warning.
00123         if((subject_ident == 0) && default_repos)
00124           {
00125             uid_t
00126               local_uid = getuid(),
00127               local_euid = geteuid();
00128             if((result.unix_uid != local_uid) &&
00129                (result.unix_uid != local_euid))
00130               {
00131                 cerr << endl
00132                      << "WARNING: Your local Unix user ID ("
00133                      << local_uid << ") doesn't match this." << endl
00134                      << ("         This indicates that your repository "
00135                          "server and this")
00136                      << endl
00137                      << ("         machine don't share Unix user tables, "
00138                          "which could be a")
00139                      << endl
00140                      << "         serious problem."
00141                      << endl << endl;
00142               }
00143           }
00144         cout << "Unix (NFS) primary group ID: " << result.unix_gid << endl;
00145 
00146         if(result.is_root || result.is_admin ||
00147            result.is_wizard || result.is_runtool)
00148           {
00149             cout << "Special permissions:" << endl;
00150             if(result.is_root)
00151               {
00152                 cout << "  root" << endl;
00153               }
00154             if(result.is_admin)
00155               {
00156                 cout << "  admin" << endl;
00157               }
00158             if(result.is_wizard)
00159               {
00160                 cout << "  wizard" << endl;
00161               }
00162             if(result.is_runtool)
00163               {
00164                 cout << "  runtool" << endl;
00165               }
00166           }
00167 
00168     } catch (VestaConfig::failure f) {
00169         cerr << program_name << ": " << f.msg << endl;
00170         exit(1);
00171     } catch (SRPC::failure f) {
00172         cerr << program_name
00173           << ": SRPC failure; " << f.msg << " (" << f.r << ")" << endl;
00174         exit(2);
00175     }
00176 
00177     return 0;
00178 }
00179 

Generated on Mon May 8 00:48:55 2006 for Vesta by  doxygen 1.4.2