Code

sysdb: Added a initial client implementation.
[sysdb.git] / src / client / sysdb.c
1 /*
2  * SysDB - src/client/sysdb.c
3  * Copyright (C) 2013 Sebastian 'tokkee' Harl <sh@tokkee.org>
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
19  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
28 #if HAVE_CONFIG_H
29 #       include "config.h"
30 #endif /* HAVE_CONFIG_H */
32 #include "client/sysdb.h"
33 #include "client/sock.h"
35 #if HAVE_LIBGEN_H
36 #       include <libgen.h>
37 #else /* HAVE_LIBGEN_H */
38 #       define basename(path) (path)
39 #endif /* ! HAVE_LIBGEN_H */
41 #include <sys/stat.h>
42 #include <fcntl.h>
44 #include <stdio.h>
45 #include <stdlib.h>
46 #include <string.h>
48 #include <unistd.h>
50 #ifndef DEFAULT_SOCKET
51 #       define DEFAULT_SOCKET "unix:"LOCALSTATEDIR"/run/sysdbd.sock"
52 #endif
54 static void
55 exit_usage(char *name, int status)
56 {
57         printf(
58 "Usage: %s <options>\n"
60 "\nOptions:\n"
61 "  -h        display this help and exit\n"
62 "  -V        display the version number and copyright\n"
64 "\nSysDB client "SDB_CLIENT_VERSION_STRING SDB_CLIENT_VERSION_EXTRA", "
65 PACKAGE_URL"\n", basename(name));
66         exit(status);
67 } /* exit_usage */
69 static void
70 exit_version(void)
71 {
72         printf("SysDB version "SDB_CLIENT_VERSION_STRING
73                         SDB_CLIENT_VERSION_EXTRA", built "BUILD_DATE"\n"
74                         "using libsysdbclient version %s%s\n"
75                         "Copyright (C) 2012-2013 "PACKAGE_MAINTAINER"\n"
77                         "\nThis is free software under the terms of the BSD license, see "
78                         "the source for\ncopying conditions. There is NO WARRANTY; not "
79                         "even for MERCHANTABILITY or\nFITNESS FOR A PARTICULAR "
80                         "PURPOSE.\n", sdb_client_version_string(),
81                         sdb_client_version_extra());
82         exit(0);
83 } /* exit_version */
85 int
86 main(int argc, char **argv)
87 {
88         while (42) {
89                 int opt = getopt(argc, argv, "hV");
91                 if (-1 == opt)
92                         break;
94                 switch (opt) {
95                         case 'h':
96                                 exit_usage(argv[0], 0);
97                                 break;
98                         case 'V':
99                                 exit_version();
100                                 break;
101                         default:
102                                 exit_usage(argv[0], 1);
103                 }
104         }
106         if (optind < argc)
107                 exit_usage(argv[0], 1);
109         printf("SysDB client "SDB_CLIENT_VERSION_STRING
110                         SDB_CLIENT_VERSION_EXTRA"\n");
111         return 0;
112 } /* main */
114 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */