00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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
00103
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
00121
00122
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