1 /* cvm/cvm-testclient.c - Diagnostic CVM client
2  * Copyright (C) 2010  Bruce Guenter <bruce@untroubled.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18 #include <bglibs/sysdeps.h>
19 #include <string.h>
20 #include <bglibs/fmt.h>
21 #include <bglibs/obuf.h>
22 #include <bglibs/msg.h>
23 #include "v2client.h"
24 
25 const char program[] = "cvm-testclient";
26 const int msg_show_pid = 0;
27 const char usage[] = "\n"
28 "usage: cvm-testclient cvmodule account domain\n"
29 "   or: cvm-testclient cvmodule account domain password\n";
30 
s(const char * name,const char * value)31 static void s(const char* name, const char* value)
32 {
33   obuf_puts(&outbuf, name);
34   obuf_puts(&outbuf, (value == 0) ? "(null)" : value);
35   obuf_endl(&outbuf);
36 }
37 
u(const char * name,unsigned long value)38 static void u(const char* name, unsigned long value)
39 {
40   obuf_puts(&outbuf, name);
41   obuf_putu(&outbuf, value);
42   obuf_endl(&outbuf);
43 }
44 
main(int argc,char ** argv)45 int main(int argc, char** argv)
46 {
47   int i;
48   unsigned long v;
49   char num[FMT_ULONG_LEN];
50 
51   switch (argc) {
52   case 4:
53     i = cvm_client_authenticate_password(argv[1], argv[2], argv[3], 0, 1);
54     break;
55   case 5:
56     i = cvm_client_authenticate_password(argv[1], argv[2], argv[3], argv[4], 1);
57     break;
58   default:
59     die2(1, "Incorrect usage.", usage);
60     return 1;
61   }
62 
63   if (i) {
64     num[fmt_udec(num, i)] = 0;
65     msg5("Authentication failed, error #", num, " (",
66 	 (i < cvm_nerr) ? cvm_errlist[i] : "Unknown error code", ")");
67     if (cvm_client_fact_uint(CVM_FACT_OUTOFSCOPE, &v) == 0)
68       u("out of scope:     ", v);
69     return i;
70   }
71 
72   s("user name:        ", cvm_fact_username);
73   u("user ID:          ", cvm_fact_userid);
74   u("group ID:         ", cvm_fact_groupid);
75   s("real name:        ", cvm_fact_realname);
76   s("directory:        ", cvm_fact_directory);
77   s("shell:            ", cvm_fact_shell);
78   s("group name:       ", cvm_fact_groupname);
79   s("system user name: ", cvm_fact_sys_username);
80   s("system directory: ", cvm_fact_sys_directory);
81   s("domain:           ", cvm_fact_domain);
82   s("mailbox path:     ", cvm_fact_mailbox);
83   while (cvm_client_fact_uint(CVM_FACT_SUPP_GROUPID, &v) == 0)
84     u("supp. group ID:   ", v);
85   return 0;
86 }
87