Merge branch 'master' of ssh://git.samba.org/data/git/samba
[samba.git] / source3 / lib / popt_common.c
index 2e6d3b3cb10538809021bf8957ed52eaa83a4914..e14477c9799b31c036ec4f81971fd9a9972d6f4a 100644 (file)
@@ -73,7 +73,7 @@ static void popt_common_callback(poptContext con,
        if (reason == POPT_CALLBACK_REASON_POST) {
 
                if (PrintSambaVersionString) {
-                       printf( "Version %s\n", SAMBA_VERSION_STRING);
+                       printf( "Version %s\n", samba_version_string());
                        exit(0);
                }
 
@@ -166,7 +166,7 @@ struct poptOption popt_common_configfile[] = {
 };
 
 struct poptOption popt_common_version[] = {
-       { NULL, 0, POPT_ARG_CALLBACK, (void *)popt_common_callback },
+       { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_POST, (void *)popt_common_callback },
        { "version", 'V', POPT_ARG_NONE, NULL, 'V', "Print version" },
        POPT_TABLEEND
 };
@@ -187,6 +187,8 @@ struct poptOption popt_common_debuglevel[] = {
  *             --modulesdir
  *             --shlibext
  *             --lockdir
+ *             --statedir
+ *             --cachedir
  *             --piddir
  *             --smb-passwd-file
  *             --private-dir
@@ -201,6 +203,8 @@ enum dyn_item{
        DYN_MODULESDIR,
        DYN_SHLIBEXT,
        DYN_LOCKDIR,
+       DYN_STATEDIR,
+       DYN_CACHEDIR,
        DYN_PIDDIR,
        DYN_SMB_PASSWD_FILE,
        DYN_PRIVATE_DIR,
@@ -262,6 +266,18 @@ static void popt_dynconfig_callback(poptContext con,
                }
                break;
 
+       case DYN_STATEDIR:
+               if (arg) {
+                       set_dyn_STATEDIR(arg);
+               }
+               break;
+
+       case DYN_CACHEDIR:
+               if (arg) {
+                       set_dyn_CACHEDIR(arg);
+               }
+               break;
+
        case DYN_PIDDIR:
                if (arg) {
                        set_dyn_PIDDIR(arg);
@@ -303,6 +319,10 @@ const struct poptOption popt_common_dynconfig[] = {
            "Shared library extension", "SHLIBEXT" },
        { "lockdir", '\0' , POPT_ARG_STRING, NULL, DYN_LOCKDIR,
            "Path to lock file directory", "LOCKDIR" },
+       { "statedir", '\0' , POPT_ARG_STRING, NULL, DYN_STATEDIR,
+           "Path to persistent state file directory", "STATEDIR" },
+       { "cachedir", '\0' , POPT_ARG_STRING, NULL, DYN_CACHEDIR,
+           "Path to temporary cache file directory", "CACHEDIR" },
        { "piddir", '\0' , POPT_ARG_STRING, NULL, DYN_PIDDIR,
            "Path to PID file directory", "PIDDIR" },
        { "smb-passwd-file", '\0' , POPT_ARG_STRING, NULL, DYN_SMB_PASSWD_FILE,
@@ -318,7 +338,7 @@ const struct poptOption popt_common_dynconfig[] = {
  * exit on failure
  * ****************************************************************************/
 
-static void get_password_file(void)
+static void get_password_file(struct user_auth_info *auth_info)
 {
        int fd = -1;
        char *p;
@@ -377,13 +397,14 @@ static void get_password_file(void)
        }
        SAFE_FREE(spec);
 
-       set_cmdline_auth_info_password(pass);
+       set_cmdline_auth_info_password(auth_info, pass);
        if (close_it) {
                close(fd);
        }
 }
 
-static void get_credentials_file(const char *file)
+static void get_credentials_file(struct user_auth_info *auth_info,
+                                const char *file)
 {
        XFILE *auth;
        fstring buf;
@@ -426,9 +447,9 @@ static void get_credentials_file(const char *file)
                        val++;
 
                if (strwicmp("password", param) == 0) {
-                       set_cmdline_auth_info_password(val);
+                       set_cmdline_auth_info_password(auth_info, val);
                } else if (strwicmp("username", param) == 0) {
-                       set_cmdline_auth_info_username(val);
+                       set_cmdline_auth_info_username(auth_info, val);
                } else if (strwicmp("domain", param) == 0) {
                        set_global_myworkgroup(val);
                }
@@ -453,13 +474,16 @@ static void popt_common_credentials_callback(poptContext con,
                                        const struct poptOption *opt,
                                        const char *arg, const void *data)
 {
+       struct user_auth_info *auth_info = talloc_get_type_abort(
+               *((const char **)data), struct user_auth_info);
        char *p;
 
        if (reason == POPT_CALLBACK_REASON_PRE) {
-               set_cmdline_auth_info_username("GUEST");
+               set_cmdline_auth_info_username(auth_info, "GUEST");
 
                if (getenv("LOGNAME")) {
-                       set_cmdline_auth_info_username(getenv("LOGNAME"));
+                       set_cmdline_auth_info_username(auth_info,
+                                                      getenv("LOGNAME"));
                }
 
                if (getenv("USER")) {
@@ -467,24 +491,25 @@ static void popt_common_credentials_callback(poptContext con,
                        if (!puser) {
                                exit(ENOMEM);
                        }
-                       set_cmdline_auth_info_username(puser);
+                       set_cmdline_auth_info_username(auth_info, puser);
 
                        if ((p = strchr_m(puser,'%'))) {
                                size_t len;
                                *p = 0;
                                len = strlen(p+1);
-                               set_cmdline_auth_info_password(p+1);
+                               set_cmdline_auth_info_password(auth_info, p+1);
                                memset(strchr_m(getenv("USER"),'%')+1,'X',len);
                        }
                        SAFE_FREE(puser);
                }
 
                if (getenv("PASSWD")) {
-                       set_cmdline_auth_info_password(getenv("PASSWD"));
+                       set_cmdline_auth_info_password(auth_info,
+                                                      getenv("PASSWD"));
                }
 
                if (getenv("PASSWD_FD") || getenv("PASSWD_FILE")) {
-                       get_password_file();
+                       get_password_file(auth_info);
                }
 
                return;
@@ -499,19 +524,22 @@ static void popt_common_credentials_callback(poptContext con,
                        if ((lp=strchr_m(puser,'%'))) {
                                size_t len;
                                *lp = 0;
-                               set_cmdline_auth_info_username(puser);
-                               set_cmdline_auth_info_password(lp+1);
+                               set_cmdline_auth_info_username(auth_info,
+                                                              puser);
+                               set_cmdline_auth_info_password(auth_info,
+                                                              lp+1);
                                len = strlen(lp+1);
                                memset(strchr_m(arg,'%')+1,'X',len);
                        } else {
-                               set_cmdline_auth_info_username(puser);
+                               set_cmdline_auth_info_username(auth_info,
+                                                              puser);
                        }
                        SAFE_FREE(puser);
                }
                break;
 
        case 'A':
-               get_credentials_file(arg);
+               get_credentials_file(auth_info, arg);
                break;
 
        case 'k':
@@ -519,31 +547,40 @@ static void popt_common_credentials_callback(poptContext con,
                d_printf("No kerberos support compiled in\n");
                exit(1);
 #else
-               set_cmdline_auth_info_use_krb5_ticket();
+               set_cmdline_auth_info_use_krb5_ticket(auth_info);
 #endif
                break;
 
        case 'S':
-               if (!set_cmdline_auth_info_signing_state(arg)) {
+               if (!set_cmdline_auth_info_signing_state(auth_info, arg)) {
                        fprintf(stderr, "Unknown signing option %s\n", arg );
                        exit(1);
                }
                break;
        case 'P':
-               set_cmdline_auth_info_use_machine_account();
+               set_cmdline_auth_info_use_machine_account(auth_info);
                break;
        case 'N':
-               set_cmdline_auth_info_password("");
+               set_cmdline_auth_info_password(auth_info, "");
                break;
        case 'e':
-               set_cmdline_auth_info_smb_encrypt();
+               set_cmdline_auth_info_smb_encrypt(auth_info);
                break;
 
        }
 }
 
+static struct user_auth_info *global_auth_info;
+
+void popt_common_set_auth_info(struct user_auth_info *auth_info)
+{
+       global_auth_info = auth_info;
+}
+
 struct poptOption popt_common_credentials[] = {
-       { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE, (void *)popt_common_credentials_callback },
+       { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE,
+         (void *)popt_common_credentials_callback, 0,
+         (const char *)&global_auth_info },
        { "user", 'U', POPT_ARG_STRING, NULL, 'U', "Set the network username", "USERNAME" },
        { "no-pass", 'N', POPT_ARG_NONE, NULL, 'N', "Don't ask for a password" },
        { "kerberos", 'k', POPT_ARG_NONE, NULL, 'k', "Use kerberos (active directory) authentication" },