1/*
2 * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu)
3 * Copyright (c) 1990,1993 Regents of The University of Michigan.
4 * All Rights Reserved.  See COPYRIGHT.
5 *
6 * modified from main.c. this handles afp options.
7 */
8
9#ifdef HAVE_CONFIG_H
10#include "config.h"
11#endif /* HAVE_CONFIG_H */
12
13#include <stdio.h>
14#include <stdlib.h>
15#include <string.h>
16#include <ctype.h>
17#include <unistd.h>
18#include <sys/param.h>
19#include <sys/socket.h>
20#include <atalk/logger.h>
21
22#include <netinet/in.h>
23#include <arpa/inet.h>
24
25#ifdef HAVE_NETDB_H
26#include <netdb.h>
27#endif /* HAVE_NETDB_H */
28
29#ifdef ADMIN_GRP
30#include <grp.h>
31#include <sys/types.h>
32#endif /* ADMIN_GRP */
33
34#include <atalk/paths.h>
35#include <atalk/util.h>
36#include <atalk/compat.h>
37#include <atalk/globals.h>
38#include <atalk/fce_api.h>
39#include <atalk/errchk.h>
40
41#include "status.h"
42#include "auth.h"
43#include "dircache.h"
44
45#define LENGTH 512
46
47//Change some path by Edison in 20130923
48#define T_PATH_CONFDIR		"/usr/etc/"
49#define T_PATH_STATEDIR		"/tmp/netatalk/"
50#define T_PATH_AFPDUAMPATH	"/usr/lib/netatalk/"
51
52/*
53 * Show version information about afpd.
54 * Used by "afp -v".
55 */
56static void show_version( void )
57{
58	int num, i;
59
60	printf( "afpd %s - Apple Filing Protocol (AFP) daemon of Netatalk\n\n", VERSION );
61
62	puts( "This program is free software; you can redistribute it and/or modify it under" );
63	puts( "the terms of the GNU General Public License as published by the Free Software" );
64	puts( "Foundation; either version 2 of the License, or (at your option) any later" );
65	puts( "version. Please see the file COPYING for further information and details.\n" );
66
67	puts( "afpd has been compiled with support for these features:\n" );
68
69	num = sizeof( afp_versions ) / sizeof( afp_versions[ 0 ] );
70	printf( "          AFP versions:\t" );
71	for ( i = 0; i < num; i++ ) {
72		printf( "%d.%d ", afp_versions[ i ].av_number/10, afp_versions[ i ].av_number%10);
73	}
74	puts( "" );
75
76	printf( "         CNID backends:\t" );
77#ifdef CNID_BACKEND_CDB
78	printf( "cdb ");
79#endif
80#ifdef CNID_BACKEND_DB3
81	printf( "db3 " );
82#endif
83#ifdef CNID_BACKEND_DBD
84#ifdef CNID_BACKEND_DBD_TXN
85	printf( "dbd-txn " );
86#else
87	printf( "dbd " );
88#endif
89#endif
90#ifdef CNID_BACKEND_HASH
91	printf( "hash " );
92#endif
93#ifdef CNID_BACKEND_LAST
94	printf( "last " );
95#endif
96#ifdef CNID_BACKEND_MTAB
97	printf( "mtab " );
98#endif
99#ifdef CNID_BACKEND_TDB
100	printf( "tdb " );
101#endif
102	puts( "" );
103}
104
105/*
106 * Show extended version information about afpd and Netatalk.
107 * Used by "afp -V".
108 */
109static void show_version_extended(void )
110{
111	show_version( );
112
113	printf( "      Zeroconf support:\t" );
114#if defined (HAVE_MDNS)
115	puts( "mDNSResponder" );
116#elif defined (HAVE_AVAHI)
117	puts( "Avahi" );
118#else
119	puts( "No" );
120#endif
121
122	printf( "  TCP wrappers support:\t" );
123#ifdef TCPWRAP
124	puts( "Yes" );
125#else
126	puts( "No" );
127#endif
128
129	printf( "         Quota support:\t" );
130#ifndef NO_QUOTA_SUPPORT
131	puts( "Yes" );
132#else
133	puts( "No" );
134#endif
135
136	printf( "   Admin group support:\t" );
137#ifdef ADMIN_GRP
138	puts( "Yes" );
139#else
140	puts( "No" );
141#endif
142
143	printf( "    Valid shell checks:\t" );
144#ifndef DISABLE_SHELLCHECK
145	puts( "Yes" );
146#else
147	puts( "No" );
148#endif
149
150	printf( "      cracklib support:\t" );
151#ifdef USE_CRACKLIB
152	puts( "Yes" );
153#else
154	puts( "No" );
155#endif
156
157	printf( "            EA support:\t" );
158	puts( EA_MODULES );
159
160	printf( "           ACL support:\t" );
161#ifdef HAVE_ACLS
162	puts( "Yes" );
163#else
164	puts( "No" );
165#endif
166
167	printf( "          LDAP support:\t" );
168#ifdef HAVE_LDAP
169	puts( "Yes" );
170#else
171	puts( "No" );
172#endif
173
174	printf( "         D-Bus support:\t" );
175#ifdef HAVE_DBUS_GLIB
176	puts( "Yes" );
177#else
178	puts( "No" );
179#endif
180
181	printf( "         DTrace probes:\t" );
182#ifdef WITH_DTRACE
183	puts( "Yes" );
184#else
185	puts( "No" );
186#endif
187}
188
189/*
190 * Display compiled-in default paths
191 */
192
193//Edison modify 20130923
194static void show_paths( void )
195{
196	printf( "              afp.conf:\t%s\n", T_PATH_CONFDIR "afp.conf");
197	printf( "           extmap.conf:\t%s\n", T_PATH_CONFDIR "extmap.conf");
198	printf( "       state directory:\t%s\n", T_PATH_STATEDIR);
199	printf( "    afp_signature.conf:\t%s\n", T_PATH_STATEDIR "afp_signature.conf");
200	printf( "      afp_voluuid.conf:\t%s\n", T_PATH_STATEDIR "afp_voluuid.conf");
201	printf( "       UAM search path:\t%s\n", T_PATH_AFPDUAMPATH );
202	printf( "  Server messages path:\t%s\n", SERVERTEXT);
203}
204
205/*
206 * Display usage information about afpd.
207 */
208static void show_usage(void)
209{
210	fprintf( stderr, "Usage:\tafpd [-d] [-F configfile]\n");
211	fprintf( stderr, "\tafpd -h|-v|-V\n");
212}
213
214void afp_options_parse_cmdline(AFPObj *obj, int ac, char **av)
215{
216    int c, err = 0;
217
218    while (EOF != ( c = getopt( ac, av, "dF:vVh" )) ) {
219        switch ( c ) {
220        case 'd':
221            obj->cmdlineflags |= OPTION_DEBUG;
222            break;
223        case 'F':
224            obj->cmdlineconfigfile = strdup(optarg);
225            break;
226        case 'v':	/* version */
227            show_version( ); puts( "" );
228            show_paths( ); puts( "" );
229            exit( 0 );
230            break;
231        case 'V':	/* extended version */
232            show_version_extended( ); puts( "" );
233            show_paths( ); puts( "" );
234            exit( 0 );
235            break;
236        case 'h':	/* usage */
237            show_usage();
238            exit( 0 );
239            break;
240        default :
241            err++;
242        }
243    }
244    if ( err || optind != ac ) {
245        show_usage();
246        exit( 2 );
247    }
248
249    return;
250}
251