mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-27 09:30:13 +03:00
Add possibility to pass userdata to the auth function.
This commit is contained in:
parent
c826f021d6
commit
3c618a3d7d
10 changed files with 50 additions and 17 deletions
|
@ -31,7 +31,8 @@
|
|||
/** Zero a structure */
|
||||
#define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))
|
||||
|
||||
int csync_auth(const char *prompt, char *buf, size_t len, int echo, int verify) {
|
||||
int csync_auth(const char *prompt, char *buf, size_t len, int echo, int verify,
|
||||
void *userdata) {
|
||||
struct termios attr;
|
||||
struct termios old_attr;
|
||||
int ok = 0;
|
||||
|
@ -39,6 +40,9 @@ int csync_auth(const char *prompt, char *buf, size_t len, int echo, int verify)
|
|||
char *ptr = NULL;
|
||||
char tmp[len];
|
||||
|
||||
/* unused variables */
|
||||
(void) userdata;
|
||||
|
||||
ZERO_STRUCT(attr);
|
||||
ZERO_STRUCT(old_attr);
|
||||
ZERO_STRUCT(tmp);
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#ifndef _CSYNC_CLIENT_AUTH_H
|
||||
#define _CSYNC_CLIENT_AUTH_H
|
||||
|
||||
int csync_auth(const char *prompt, char *buf, size_t len, int echo, int verify);
|
||||
int csync_auth(const char *prompt, char *buf, size_t len, int echo, int verify,
|
||||
void *userdata);
|
||||
|
||||
#endif /* _CSYNC_CLIENT_AUTH_H */
|
||||
|
|
|
@ -193,13 +193,15 @@ csync_vio_method_t _method = {
|
|||
.utimes = _utimes
|
||||
};
|
||||
|
||||
csync_vio_method_t *vio_module_init(const char *method_name, const char *args, csync_auth_callback cb) {
|
||||
csync_vio_method_t *vio_module_init(const char *method_name, const char *args,
|
||||
csync_auth_callback cb, void *userdata) {
|
||||
DEBUG_DUMMY(("csync_dummy - method_name: %s\n", method_name));
|
||||
DEBUG_DUMMY(("csync_dummy - args: %s\n", args));
|
||||
|
||||
(void) method_name;
|
||||
(void) args;
|
||||
(void) cb;
|
||||
(void) userdata;
|
||||
|
||||
mh = (void *) method_name;
|
||||
fs.mtime = 42;
|
||||
|
|
|
@ -35,7 +35,8 @@
|
|||
#endif
|
||||
|
||||
SMBCCTX *smb_context = NULL;
|
||||
csync_auth_callback auth_cb = NULL;
|
||||
csync_auth_callback _authcb = NULL;
|
||||
void *_userdata;
|
||||
|
||||
/* Do we build against Samba 3.2 */
|
||||
#ifdef DEPRECATED_SMBC_INTERFACE
|
||||
|
@ -74,10 +75,10 @@ static void get_auth_data_with_context_fn(SMBCCTX *c,
|
|||
}
|
||||
|
||||
/* Call the passwort prompt */
|
||||
if (auth_cb != NULL) {
|
||||
if (_authcb != NULL) {
|
||||
DEBUG_SMB(("csync_smb - execute authentication callback\n"));
|
||||
(*auth_cb) ("Username:", un, unlen, 1, 0);
|
||||
(*auth_cb) ("Password:", pw, pwlen, 0, 0);
|
||||
(*_authcb) ("Username:", un, unlen, 1, 0, smbc_getOptionUserData(c));
|
||||
(*_authcb) ("Password:", pw, pwlen, 0, 0, smbc_getOptionUserData(c));
|
||||
}
|
||||
|
||||
DEBUG_SMB(("csync_smb - user=%s, workgroup=%s, server=%s, share=%s\n",
|
||||
|
@ -123,10 +124,10 @@ static void get_auth_data_fn(const char *pServer,
|
|||
}
|
||||
|
||||
/* Call the passwort prompt */
|
||||
if (auth_cb != NULL) {
|
||||
if (_authcb != NULL) {
|
||||
DEBUG_SMB(("csync_smb - execute authentication callback\n"));
|
||||
(*auth_cb) ("Username:", pUsername, maxLenUsername, 1, 0);
|
||||
(*auth_cb) ("Password:", pPassword, maxLenPassword, 0, 0);
|
||||
(*_authcb) ("Username:", pUsername, maxLenUsername, 1, 0);
|
||||
(*_authcb) ("Password:", pPassword, maxLenPassword, 0, 0);
|
||||
}
|
||||
|
||||
DEBUG_SMB(("csync_smb - user=%s, workgroup=%s, server=%s, share=%s\n",
|
||||
|
@ -476,7 +477,7 @@ csync_vio_method_t _method = {
|
|||
};
|
||||
|
||||
csync_vio_method_t *vio_module_init(const char *method_name, const char *args,
|
||||
csync_auth_callback cb) {
|
||||
csync_auth_callback cb, void *userdata) {
|
||||
smb_context = smbc_new_context();
|
||||
|
||||
DEBUG_SMB(("csync_smb - method_name: %s\n", method_name));
|
||||
|
@ -491,12 +492,13 @@ csync_vio_method_t *vio_module_init(const char *method_name, const char *args,
|
|||
}
|
||||
|
||||
if (cb != NULL) {
|
||||
auth_cb = cb;
|
||||
_authcb = cb;
|
||||
}
|
||||
|
||||
/* set debug level and authentication function callback */
|
||||
#ifdef DEPRECATED_SMBC_INTERFACE
|
||||
smbc_setDebug(smb_context, 0);
|
||||
smbc_setOptionUserData(smb_context, userdata);
|
||||
smbc_setFunctionAuthDataWithContext(smb_context, get_auth_data_with_context_fn);
|
||||
|
||||
/* Kerberos support */
|
||||
|
|
18
src/csync.c
18
src/csync.c
|
@ -637,6 +637,24 @@ char *csync_get_statedb_file(CSYNC *ctx) {
|
|||
return c_strdup(ctx->statedb.file);
|
||||
}
|
||||
|
||||
void *csync_get_userdata(CSYNC *ctx) {
|
||||
if (ctx == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ctx->userdata;
|
||||
}
|
||||
|
||||
int csync_set_userdata(CSYNC *ctx, void *userdata) {
|
||||
if (ctx == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ctx->userdata = userdata;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
csync_auth_callback csync_get_auth_callback(CSYNC *ctx) {
|
||||
if (ctx == NULL) {
|
||||
return NULL;
|
||||
|
|
|
@ -66,7 +66,8 @@ extern "C" {
|
|||
#define CSYNC_EXCLUDE_FILE "csync_exclude.conf"
|
||||
#define CSYNC_LOCK_FILE "lock"
|
||||
|
||||
typedef int (*csync_auth_callback) (const char *prompt, char *buf, size_t len, int echo, int verify);
|
||||
typedef int (*csync_auth_callback) (const char *prompt, char *buf, size_t len,
|
||||
int echo, int verify, void *userdata);
|
||||
|
||||
/**
|
||||
* csync handle
|
||||
|
@ -163,6 +164,8 @@ int csync_remove_config_dir(CSYNC *ctx);
|
|||
int csync_enable_statedb(CSYNC *ctx);
|
||||
int csync_disable_statedb(CSYNC *ctx);
|
||||
int csync_is_statedb_disabled(CSYNC *ctx);
|
||||
void *csync_get_userdata(CSYNC *ctx);
|
||||
int csync_set_userdata(CSYNC *ctx, void *userdata);
|
||||
csync_auth_callback csync_get_auth_callback(CSYNC *ctx);
|
||||
int csync_set_auth_callback(CSYNC *ctx, csync_auth_callback cb);
|
||||
char *csync_get_statedb_file(CSYNC *ctx);
|
||||
|
|
|
@ -80,6 +80,7 @@ enum csync_replica_e {
|
|||
*/
|
||||
struct csync_s {
|
||||
csync_auth_callback auth_callback;
|
||||
void *userdata;
|
||||
c_strlist_t *excludes;
|
||||
|
||||
struct {
|
||||
|
|
|
@ -76,7 +76,8 @@ int csync_vio_init(CSYNC *ctx, const char *module, const char *args) {
|
|||
}
|
||||
|
||||
/* get the method struct */
|
||||
m = (*init_fn)(module, args, ctx->auth_callback);
|
||||
m = (*init_fn)(module, args, csync_get_auth_callback(ctx),
|
||||
csync_get_userdata(ctx));
|
||||
if (m == NULL) {
|
||||
CSYNC_LOG(CSYNC_LOG_PRIORITY_ERROR, "module %s returned a NULL method", module);
|
||||
return -1;
|
||||
|
|
|
@ -35,7 +35,8 @@
|
|||
|
||||
typedef struct csync_vio_method_s csync_vio_method_t;
|
||||
|
||||
typedef csync_vio_method_t *(*csync_vio_method_init_fn)(const char *method_name, const char *config_args, csync_auth_callback cb);
|
||||
typedef csync_vio_method_t *(*csync_vio_method_init_fn)(const char *method_name,
|
||||
const char *config_args, csync_auth_callback cb, void *userdata);
|
||||
typedef void (*csync_vio_method_finish_fn)(csync_vio_method_t *method);
|
||||
|
||||
typedef csync_vio_method_handle_t *(*csync_method_open_fn)(const char *durl, int flags, mode_t mode);
|
||||
|
|
|
@ -25,8 +25,8 @@
|
|||
|
||||
#include "vio/csync_vio_method.h"
|
||||
|
||||
extern csync_vio_method_t *vio_module_init (const char *method_name,
|
||||
const char *args, csync_auth_callback cb);
|
||||
extern csync_vio_method_t *vio_module_init(const char *method_name,
|
||||
const char *args, csync_auth_callback cb, void *userdata);
|
||||
extern void vio_module_shutdown(csync_vio_method_t *method);
|
||||
|
||||
#endif /* _CSYNC_VIO_MODULE_H */
|
||||
|
|
Loading…
Reference in a new issue