r12608: Remove some unused #include lines.
[kamenim/samba.git] / source4 / lib / cmdline / popt_credentials.c
1 /* 
2    Unix SMB/CIFS implementation.
3    Credentials popt routines
4
5    Copyright (C) Jelmer Vernooij 2002,2003,2005
6
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 2 of the License, or
10    (at your option) any later version.
11    
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.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include "includes.h"
23 #include "lib/cmdline/popt_common.h"
24
25 /* Handle command line options:
26  *              -U,--user
27  *              -A,--authentication-file
28  *              -k,--use-kerberos
29  *              -N,--no-pass
30  *              -S,--signing
31  *      -P --machine-pass
32  */
33
34
35 static BOOL dont_ask;
36
37 enum opt { OPT_SIMPLE_BIND_DN };
38
39 /*
40   disable asking for a password
41 */
42 void popt_common_dont_ask(void)
43 {
44         dont_ask = True;
45 }
46
47 static void popt_common_credentials_callback(poptContext con, 
48                                                 enum poptCallbackReason reason,
49                                                 const struct poptOption *opt,
50                                                 const char *arg, const void *data)
51 {
52         if (reason == POPT_CALLBACK_REASON_PRE) {
53                 cmdline_credentials = cli_credentials_init(talloc_autofree_context());
54                 return;
55         }
56         
57         if (reason == POPT_CALLBACK_REASON_POST) {
58                 cli_credentials_guess(cmdline_credentials);
59
60                 if (!dont_ask) {
61                         cli_credentials_set_cmdline_callbacks(cmdline_credentials);
62                 }
63                 return;
64         }
65
66         switch(opt->val) {
67         case 'U':
68                 {
69                         char *lp;
70
71                         cli_credentials_parse_string(cmdline_credentials, arg, CRED_SPECIFIED);
72                         /* This breaks the abstraction, including the const above */
73                         if ((lp=strchr_m(arg,'%'))) {
74                                 lp[0]='\0';
75                                 lp++;
76                                 memset(lp,0,strlen(lp));
77                         }
78                 }
79                 break;
80
81         case 'A':
82                 cli_credentials_parse_file(cmdline_credentials, arg, CRED_SPECIFIED);
83                 break;
84
85         case 'S':
86                 lp_set_cmdline("client signing", arg);
87                 break;
88
89         case 'P':
90                 /* Later, after this is all over, get the machine account details from the secrets.ldb */
91                 cli_credentials_set_machine_account_pending(cmdline_credentials);
92                 
93                 /* machine accounts only work with kerberos (fall though)*/
94                 break;
95         case OPT_SIMPLE_BIND_DN:
96                 cli_credentials_set_bind_dn(cmdline_credentials, arg);
97                 break;
98         }
99 }
100
101
102
103 struct poptOption popt_common_credentials[] = {
104         { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE|POPT_CBFLAG_POST, popt_common_credentials_callback },
105         { "user", 'U', POPT_ARG_STRING, NULL, 'U', "Set the network username", "[DOMAIN\\]USERNAME[%PASSWORD]" },
106         { "no-pass", 'N', POPT_ARG_NONE, &dont_ask, True, "Don't ask for a password" },
107         { "authentication-file", 'A', POPT_ARG_STRING, NULL, 'A', "Get the credentials from a file", "FILE" },
108         { "signing", 'S', POPT_ARG_STRING, NULL, 'S', "Set the client signing state", "on|off|required" },
109         { "machine-pass", 'P', POPT_ARG_NONE, NULL, 'P', "Use stored machine account password (implies -k)" },
110         { "simple-bind-dn", 0, POPT_ARG_STRING, NULL, OPT_SIMPLE_BIND_DN, "DN to use for a simple bind" },
111         POPT_TABLEEND
112 };