2 Unix SMB/CIFS implementation.
3 Credentials popt routines
5 Copyright (C) Jelmer Vernooij 2002,2003,2005
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "lib/cmdline/popt_common.h"
23 #include "lib/cmdline/credentials.h"
24 #include "auth/credentials/credentials.h"
25 #include "auth/gensec/gensec.h"
26 #include "param/param.h"
28 /* Handle command line options:
30 * -A,--authentication-file
41 static bool machine_account_pending
;
43 enum opt
{ OPT_SIMPLE_BIND_DN
, OPT_PASSWORD
, OPT_KERBEROS
, OPT_SIGN
, OPT_ENCRYPT
, OPT_KRB5_CCACHE
};
46 disable asking for a password
48 void popt_common_dont_ask(void)
53 static void popt_common_credentials_callback(poptContext con
,
54 enum poptCallbackReason reason
,
55 const struct poptOption
*opt
,
56 const char *arg
, const void *data
)
58 if (reason
== POPT_CALLBACK_REASON_PRE
) {
59 cmdline_credentials
= cli_credentials_init(talloc_autofree_context());
63 if (reason
== POPT_CALLBACK_REASON_POST
) {
64 cli_credentials_guess(cmdline_credentials
, cmdline_lp_ctx
);
67 cli_credentials_set_cmdline_callbacks(cmdline_credentials
);
70 if (machine_account_pending
) {
71 cli_credentials_set_machine_account(cmdline_credentials
, cmdline_lp_ctx
);
83 cli_credentials_parse_string(cmdline_credentials
, arg
, CRED_SPECIFIED
);
84 /* This breaks the abstraction, including the const above */
85 if ((lp
=strchr_m(arg
,'%'))) {
88 /* Try to prevent this showing up in ps */
89 memset(lp
,0,strlen(lp
));
95 cli_credentials_set_password(cmdline_credentials
, arg
, CRED_SPECIFIED
);
96 /* Try to prevent this showing up in ps */
97 memset(discard_const(arg
),0,strlen(arg
));
101 cli_credentials_parse_file(cmdline_credentials
, arg
, CRED_SPECIFIED
);
105 /* Later, after this is all over, get the machine account details from the secrets.ldb */
106 machine_account_pending
= true;
111 bool use_kerberos
= true;
112 /* Force us to only use kerberos */
114 if (!set_boolean(arg
, &use_kerberos
)) {
115 fprintf(stderr
, "Error parsing -k %s. Should be "
116 "-k [yes|no]\n", arg
);
122 cli_credentials_set_kerberos_state(cmdline_credentials
,
124 ? CRED_MUST_USE_KERBEROS
125 : CRED_DONT_USE_KERBEROS
);
129 case OPT_SIMPLE_BIND_DN
:
131 cli_credentials_set_bind_dn(cmdline_credentials
, arg
);
134 case OPT_KRB5_CCACHE
:
136 const char *error_string
;
137 if (cli_credentials_set_ccache(cmdline_credentials
, cmdline_lp_ctx
, arg
, CRED_SPECIFIED
,
138 &error_string
) != 0) {
139 fprintf(stderr
, "Error reading krb5 credentials cache: '%s' %s", arg
, error_string
);
146 uint32_t gensec_features
;
148 gensec_features
= cli_credentials_get_gensec_features(cmdline_credentials
);
150 gensec_features
|= GENSEC_FEATURE_SIGN
;
151 cli_credentials_set_gensec_features(cmdline_credentials
,
157 uint32_t gensec_features
;
159 gensec_features
= cli_credentials_get_gensec_features(cmdline_credentials
);
161 gensec_features
|= GENSEC_FEATURE_SEAL
;
162 cli_credentials_set_gensec_features(cmdline_credentials
,
171 struct poptOption popt_common_credentials4
[] = {
172 { NULL
, 0, POPT_ARG_CALLBACK
|POPT_CBFLAG_PRE
|POPT_CBFLAG_POST
, (void *)popt_common_credentials_callback
},
173 { "user", 'U', POPT_ARG_STRING
, NULL
, 'U', "Set the network username", "[DOMAIN/]USERNAME[%PASSWORD]" },
174 { "no-pass", 'N', POPT_ARG_NONE
, &dont_ask
, 'N', "Don't ask for a password" },
175 { "password", 0, POPT_ARG_STRING
, NULL
, OPT_PASSWORD
, "Password" },
176 { "authentication-file", 'A', POPT_ARG_STRING
, NULL
, 'A', "Get the credentials from a file", "FILE" },
177 { "machine-pass", 'P', POPT_ARG_NONE
, NULL
, 'P', "Use stored machine account password (implies -k)" },
178 { "simple-bind-dn", 0, POPT_ARG_STRING
, NULL
, OPT_SIMPLE_BIND_DN
, "DN to use for a simple bind" },
179 { "kerberos", 'k', POPT_ARG_STRING
, NULL
, OPT_KERBEROS
, "Use Kerberos, -k [yes|no]" },
180 { "krb5-ccache", 0, POPT_ARG_STRING
, NULL
, OPT_KRB5_CCACHE
, "Credentials cache location for Kerberos" },
181 { "sign", 'S', POPT_ARG_NONE
, NULL
, OPT_SIGN
, "Sign connection to prevent modification in transit" },
182 { "encrypt", 'e', POPT_ARG_NONE
, NULL
, OPT_ENCRYPT
, "Encrypt connection for privacy" },