1 /* cvm/cvm-v1testclient.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 "v1client.h"
24
25 const char program[] = "cvm-v1testclient";
26 const int msg_show_pid = 0;
27
s(const char * name,const char * value)28 static void s(const char* name, const char* value)
29 {
30 obuf_puts(&outbuf, name);
31 obuf_puts(&outbuf, (value == 0) ? "(null)" : value);
32 obuf_putc(&outbuf, '\n');
33 }
34
u(const char * name,unsigned long value)35 static void u(const char* name, unsigned long value)
36 {
37 obuf_puts(&outbuf, name);
38 obuf_putu(&outbuf, value);
39 obuf_putc(&outbuf, '\n');
40 }
41
main(int argc,char ** argv)42 int main(int argc, char** argv)
43 {
44 int i;
45 unsigned long v;
46 char num[FMT_ULONG_LEN];
47
48 if (argc < 4)
49 die1(1, "Incorrect usage.\n"
50 "usage: cvm-testclient cvmodule account domain [credential [credential ...]]\n");
51
52 i = cvm_client_authenticate(argv[1], argv[2], argv[3], (const char**)(argv+4), 0);
53 if (i) {
54 num[fmt_udec(num, i)] = 0;
55 die5(i, "Authentication failed, error #", num, " (",
56 (i < cvm_nerr) ? cvm_errlist[i] : "Unknown error code", ")");
57 }
58
59 s("user name: ", cvm_fact_username);
60 u("user ID: ", cvm_fact_userid);
61 u("group ID: ", cvm_fact_groupid);
62 s("real name: ", cvm_fact_realname);
63 s("directory: ", cvm_fact_directory);
64 s("shell: ", cvm_fact_shell);
65 s("group name: ", cvm_fact_groupname);
66 s("system user name: ", cvm_fact_sys_username);
67 s("system directory: ", cvm_fact_sys_directory);
68 s("domain: ", cvm_fact_domain);
69 s("mailbox path: ", cvm_fact_mailbox);
70 while (cvm_client_fact_uint(CVM_FACT_SUPP_GROUPID, &v) == 0)
71 u("supp. group ID: ", v);
72 obuf_flush(&outbuf);
73 return 0;
74 }
75