/* * Authentication callback for libsmbclient */ static void get_auth_data_with_context_fn(SMBCCTX *smb_ctx, const char *srv, const char *shr, char *wg, int wglen, char *un, int unlen, char *pw, int pwlen) { static int try_krb5 = 1; char *h; (void) smb_ctx; (void) shr; (void) wg; (void) wglen; DEBUG_SMB(("csync_smb - user=%s, workgroup=%s, server=%s, share=%s\n", un, wg, srv, shr)); /* Don't authenticate for workgroup listing */ if (srv == NULL || srv[0] == '\0') { DEBUG_SMB(("csync_smb - emtpy server name")); return; } /* Try kerberos authentication if available */ if (try_krb5 && getenv("KRB5CCNAME")) { try_krb5 = 0; return; } /* check for an existing user */ h = smbc_getUser(smb_ctx); if (h != NULL) { /* The username is known from the url. */ DEBUG_SMB(("csync_smb - have username from url: %s\n", h)); if (snprintf(un, unlen, "%s", h) < 0) { /* Even if that fials, go on. */ } } else { if (_authcb != NULL) { DEBUG_SMB(("csync_smb - execute authentication callback\n")); (*_authcb) ("Username:"******"Password:"******"csync_smb - user=%s, workgroup=%s, server=%s, share=%s\n", un, wg, srv, shr)); try_krb5 = 1; return; }
csync_vio_method_t *vio_module_init(const char *method_name, const char *args, csync_auth_callback cb, void *userdata) { smb_context = smbc_new_context(); DEBUG_SMB(("csync_smb - method_name: %s\n", method_name)); DEBUG_SMB(("csync_smb - args: %s\n", args)); (void) method_name; (void) args; (void) cb; if (smb_context == NULL) { fprintf(stderr, "csync_smb - failed to create new smbc context\n"); return NULL; } if (cb != NULL) { _authcb = cb; } /* set debug level and authentication function callback */ smbc_setDebug(smb_context, 0); smbc_setOptionUserData(smb_context, userdata); smbc_setFunctionAuthDataWithContext(smb_context, get_auth_data_with_context_fn); /* Kerberos support */ smbc_setOptionUseKerberos(smb_context, 1); smbc_setOptionFallbackAfterKerberos(smb_context, 1); DEBUG_SMB(("csync_smb - use kerberos = %d\n", smbc_getOptionUseKerberos(smb_context))); DEBUG_SMB(("csync_smb - use fallback after kerberos = %d\n", smbc_getOptionFallbackAfterKerberos(smb_context))); if (smbc_init_context(smb_context) == NULL) { fprintf(stderr, "csync_smb - failed to initialize the smbc context"); smbc_free_context(smb_context, 0); smb_context = NULL; return NULL; } DEBUG_SMB(("csync_smb - KRB5CCNAME = %s\n", getenv("KRB5CCNAME") != NULL ? getenv("KRB5CCNAME") : "not set")); smbc_set_context(smb_context); return &_method; }
/* * Authentication callback for libsmbclient */ static void get_auth_data_with_context_fn(SMBCCTX *c, const char *srv, const char *shr, char *wg, int wglen, char *un, int unlen, char *pw, int pwlen) { static int try_krb5 = 1; (void) c; (void) shr; (void) wg; (void) wglen; DEBUG_SMB(("csync_smb - user=%s, workgroup=%s, server=%s, share=%s\n", un, wg, srv, shr)); /* Don't authenticate for workgroup listing */ if (srv == NULL || srv[0] == '\0') { DEBUG_SMB(("csync_smb - emtpy server name")); return; } /* Try kerberos authentication if available */ if (try_krb5 && getenv("KRB5CCNAME")) { try_krb5 = 0; return; } /* Call the passwort prompt */ if (_authcb != NULL) { DEBUG_SMB(("csync_smb - execute authentication callback\n")); (*_authcb) ("Username:"******"Password:"******"csync_smb - user=%s, workgroup=%s, server=%s, share=%s\n", un, wg, srv, shr)); try_krb5 = 1; return; }