Import ncpfs 2.2.2
This commit is contained in:
@@ -127,8 +127,18 @@ sstart:;
|
||||
while ((cc = *cptr++) != 0) {
|
||||
if (cc == '\n')
|
||||
break;
|
||||
if (!ec && isspace(cc))
|
||||
break;
|
||||
if (!ec && isspace(cc)) {
|
||||
char* cp = sptr;
|
||||
|
||||
do {
|
||||
*cp++ = cc;
|
||||
cc = *cptr++;
|
||||
} while (cc && cc != '\n' && isspace(cc));
|
||||
if (!cc || cc == '\n' || cc == '#' || cc == ';') {
|
||||
break;
|
||||
}
|
||||
sptr = cp;
|
||||
}
|
||||
if (cc == ec)
|
||||
break;
|
||||
if (cc == '\\') {
|
||||
@@ -138,6 +148,13 @@ sstart:;
|
||||
if (cc == '\n')
|
||||
break;
|
||||
switch (cc) {
|
||||
case '#':
|
||||
case ';':
|
||||
case ' ':
|
||||
/* List these explicitly so it is clear that they are used/supported */
|
||||
break;
|
||||
case 't':
|
||||
cc = '\t'; break;
|
||||
case 'n':
|
||||
cc = '\n'; break;
|
||||
case 'r':
|
||||
|
||||
@@ -488,7 +488,7 @@ NWDSCCODE NWDSChangeObjectPassword(
|
||||
|
||||
NWDSCCODE nds_login(
|
||||
NWDSContextHandle ctx,
|
||||
const wchar_t* objectName,
|
||||
const NWDSChar* objectName,
|
||||
const char *objectPassword) {
|
||||
NWCONN_HANDLE conn;
|
||||
NWObjectID objectID;
|
||||
@@ -503,23 +503,23 @@ NWDSCCODE nds_login(
|
||||
nuint8 logindata[8];
|
||||
NWDSCCODE grace_err;
|
||||
wchar_t unaliasedName[MAX_DN_CHARS + 1];
|
||||
NWDSContextHandle wctx;
|
||||
|
||||
err = __NWDSGenerateObjectKeyPairStep1(ctx, (const NWDSChar*)objectName,
|
||||
err = __NWDSGenerateObjectKeyPairStep1(ctx, objectName,
|
||||
&conn, &objectID, &pseudoID, rndseed,
|
||||
&serverPublicKey);
|
||||
if (err)
|
||||
return err;
|
||||
{
|
||||
NWDSContextHandle wctx;
|
||||
|
||||
err = NWDSDuplicateContextHandleInt(ctx, &wctx);
|
||||
if (!err) {
|
||||
err = NWDSMapIDToName(wctx, conn, objectID,
|
||||
(NWDSChar*)unaliasedName);
|
||||
NWDSFreeContext(wctx);
|
||||
}
|
||||
if (err)
|
||||
wcscpy(unaliasedName, objectName);
|
||||
err = NWDSDuplicateContextHandleInt(ctx, &wctx);
|
||||
if (err) {
|
||||
__NWDSGenerateObjectKeyPairStep3(conn, serverPublicKey);
|
||||
return err;
|
||||
}
|
||||
err = NWDSMapIDToName(wctx, conn, objectID, (NWDSChar*)unaliasedName);
|
||||
if (err) {
|
||||
NWDSFreeContext(wctx);
|
||||
__NWDSGenerateObjectKeyPairStep3(conn, serverPublicKey);
|
||||
return err;
|
||||
}
|
||||
/* compute key... */
|
||||
pwdLen = strlen(objectPassword);
|
||||
@@ -541,7 +541,7 @@ NWDSCCODE nds_login(
|
||||
rndseed, objectID, pwdHash, logindata, &privKey, &privKeyLen);
|
||||
__NWDSGenerateObjectKeyPairStep3(conn, serverPublicKey);
|
||||
if (!grace_err || grace_err == NWE_PASSWORD_EXPIRED) {
|
||||
err = NWDSSetKeys(ctx, logindata, unaliasedName, privKey, privKeyLen);
|
||||
err = NWDSSetKeys(wctx, logindata, unaliasedName, privKey, privKeyLen);
|
||||
memset(privKey, 0, privKeyLen);
|
||||
free(privKey);
|
||||
if (err)
|
||||
@@ -549,6 +549,7 @@ NWDSCCODE nds_login(
|
||||
}
|
||||
err = grace_err;
|
||||
err_exit:
|
||||
NWDSFreeContext(wctx);
|
||||
memset(logindata, 0, sizeof(logindata));
|
||||
return err;
|
||||
}
|
||||
|
||||
125
lib/ncplib.c
125
lib/ncplib.c
@@ -151,6 +151,7 @@ int bindery_only = 0;
|
||||
#include <ncp/kernel/route.h>
|
||||
#include <sys/param.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/mman.h>
|
||||
#ifdef NCP_KERNEL_NCPFS_AVAILABLE
|
||||
#include <mntent.h>
|
||||
#endif
|
||||
@@ -167,6 +168,7 @@ int bindery_only = 0;
|
||||
|
||||
#include "private/ncp-new.h"
|
||||
#include "ncpcode.h"
|
||||
#include "cfgfile.h"
|
||||
|
||||
#include "private/libintl.h"
|
||||
#define _(X) dgettext(NCPFS_PACKAGE, (X))
|
||||
@@ -1578,11 +1580,12 @@ ncp_find_fileserver(const char *server_name, struct sockaddr* addr, socklen_t le
|
||||
return ncp_find_server(&server_name, OT_FILE_SERVER, addr, len);
|
||||
}
|
||||
|
||||
NWCCODE
|
||||
ncp_login_conn(struct ncp_conn* conn, const char* object_name, NWObjectType object_type, const char* password) {
|
||||
int err;
|
||||
|
||||
#ifdef NDS_SUPPORT
|
||||
static NWCCODE
|
||||
ncp_login_nds(struct ncp_conn* conn, const char* object_name, const char* password) {
|
||||
NWCCODE err;
|
||||
|
||||
err = NWE_NCP_NOT_SUPPORTED;
|
||||
if (NWIsDSServer(conn, NULL)) {
|
||||
err = nds_login_auth(conn, object_name, password);
|
||||
if (!err) return 0;
|
||||
@@ -1590,14 +1593,47 @@ ncp_login_conn(struct ncp_conn* conn, const char* object_name, NWObjectType obje
|
||||
fprintf(stderr, _("Your password has expired\n"));
|
||||
return 0;
|
||||
}
|
||||
// fprintf(stderr, _("Unable to NDS log-in (error %d [0x%04X]), trying bindery...\n"), err, err);
|
||||
}
|
||||
#endif
|
||||
err = ncp_login_object(conn, object_name, object_type, password);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
NWCCODE
|
||||
ncp_login_conn(struct ncp_conn* conn, const char* object_name, NWObjectType object_type, const char* password) {
|
||||
NWCCODE err;
|
||||
char* auth;
|
||||
|
||||
auth = cfgGetItem("Requester", "NetWare Protocol");
|
||||
if (auth) {
|
||||
char* ptr = auth;
|
||||
char* curr;
|
||||
|
||||
err = NWE_UNSUPPORTED_AUTHENTICATOR;
|
||||
while ((curr = strsep(&ptr, " \t,")) != NULL) {
|
||||
if (!strcasecmp(curr, "BIND")) {
|
||||
err = ncp_login_object(conn, object_name, object_type, password);
|
||||
#ifdef NDS_SUPPORT
|
||||
} else if (!strcasecmp(curr, "NDS")) {
|
||||
err = ncp_login_nds(conn, object_name, password);
|
||||
#endif
|
||||
} else {
|
||||
/* Leave error code as is... */
|
||||
}
|
||||
if (!err) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
free(auth);
|
||||
} else {
|
||||
#ifdef NDS_SUPPORT
|
||||
err = ncp_login_nds(conn, object_name, password);
|
||||
if (!err) {
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
err = ncp_login_object(conn, object_name, object_type, password);
|
||||
}
|
||||
return 0;
|
||||
return err;
|
||||
}
|
||||
|
||||
static long
|
||||
@@ -1956,6 +1992,11 @@ ncp_do_close(struct ncp_conn *conn)
|
||||
conn->ncp_reply_buffer = NULL;
|
||||
conn->ncp_reply_alloc = 0;
|
||||
}
|
||||
if (conn->private_key) {
|
||||
free(conn->private_key);
|
||||
conn->private_key = NULL;
|
||||
conn->private_key_len = 0;
|
||||
}
|
||||
ncpt_mutex_destroy(&conn->serverInfo.mutex);
|
||||
ncpt_mutex_destroy(&conn->buffer_mutex);
|
||||
free(conn);
|
||||
@@ -3969,8 +4010,8 @@ ncp_set_dentry_ttl(struct ncp_conn* conn, unsigned int ttl) {
|
||||
#endif
|
||||
}
|
||||
|
||||
NWCCODE
|
||||
ncp_get_private_key(struct ncp_conn* conn, void* pk, size_t* pk_len) {
|
||||
static NWCCODE
|
||||
ncp_get_private_key_perm(struct ncp_conn* conn, void* pk, size_t* pk_len) {
|
||||
#ifdef NCP_KERNEL_NCPFS_AVAILABLE
|
||||
int fd = ncp_get_fid(conn);
|
||||
struct ncp_privatedata_ioctl npi;
|
||||
@@ -3995,8 +4036,35 @@ ncp_get_private_key(struct ncp_conn* conn, void* pk, size_t* pk_len) {
|
||||
#endif
|
||||
}
|
||||
|
||||
static NWCCODE
|
||||
ncp_get_private_key_temp(struct ncp_conn* conn, void* pk, size_t* pk_len) {
|
||||
NWCCODE err = 0;
|
||||
|
||||
ncp_lock_conn(conn);
|
||||
if (pk) {
|
||||
size_t maxln = *pk_len;
|
||||
if (maxln > conn->private_key_len) {
|
||||
maxln = conn->private_key_len;
|
||||
}
|
||||
memcpy(pk, conn->private_key, maxln);
|
||||
}
|
||||
*pk_len = conn->private_key_len;
|
||||
ncp_unlock_conn(conn);
|
||||
return err;
|
||||
}
|
||||
|
||||
NWCCODE
|
||||
ncp_set_private_key(struct ncp_conn* conn, const void* pk, size_t pk_len) {
|
||||
ncp_get_private_key(struct ncp_conn* conn, void* pk, size_t* pk_len) {
|
||||
switch (ncp_get_conn_type(conn)) {
|
||||
case NCP_CONN_TEMPORARY:
|
||||
return ncp_get_private_key_temp(conn, pk, pk_len);
|
||||
default:
|
||||
return ncp_get_private_key_perm(conn, pk, pk_len);
|
||||
}
|
||||
}
|
||||
|
||||
static NWCCODE
|
||||
ncp_set_private_key_perm(struct ncp_conn* conn, const void* pk, size_t pk_len) {
|
||||
#ifdef NCP_KERNEL_NCPFS_AVAILABLE
|
||||
int fd = ncp_get_fid(conn);
|
||||
struct ncp_privatedata_ioctl npi;
|
||||
@@ -4015,6 +4083,37 @@ ncp_set_private_key(struct ncp_conn* conn, const void* pk, size_t pk_len) {
|
||||
#endif
|
||||
}
|
||||
|
||||
static NWCCODE
|
||||
ncp_set_private_key_temp(struct ncp_conn* conn, const void* pk, size_t pk_len) {
|
||||
void *keydata;
|
||||
void *oldkeydata;
|
||||
|
||||
keydata = malloc(pk_len);
|
||||
if (!keydata)
|
||||
return ENOMEM;
|
||||
mlock(keydata, pk_len);
|
||||
memcpy(keydata, pk, pk_len);
|
||||
|
||||
ncp_lock_conn(conn);
|
||||
oldkeydata = conn->private_key;
|
||||
conn->private_key = keydata;
|
||||
conn->private_key_len = pk_len;
|
||||
ncp_unlock_conn(conn);
|
||||
|
||||
free(oldkeydata);
|
||||
return 0;
|
||||
}
|
||||
|
||||
NWCCODE
|
||||
ncp_set_private_key(struct ncp_conn* conn, const void* pk, size_t pk_len) {
|
||||
switch (ncp_get_conn_type(conn)) {
|
||||
case NCP_CONN_TEMPORARY:
|
||||
return ncp_set_private_key_temp(conn, pk, pk_len);
|
||||
default:
|
||||
return ncp_set_private_key_perm(conn, pk, pk_len);
|
||||
}
|
||||
}
|
||||
|
||||
NWCCODE
|
||||
ncp_next_conn(NWCONN_HANDLE conn, NWCONN_HANDLE* next_conn) {
|
||||
struct list_head* h;
|
||||
|
||||
@@ -110,6 +110,9 @@ struct ncp_conn {
|
||||
int has_subfunction;
|
||||
int verbose;
|
||||
size_t ncp_reply_size;
|
||||
|
||||
void *private_key;
|
||||
size_t private_key_len;
|
||||
|
||||
int lock;
|
||||
|
||||
|
||||
12
lib/ndslib.c
12
lib/ndslib.c
@@ -1327,15 +1327,18 @@ long nds_login_auth(struct ncp_conn *conn, const char *user,
|
||||
err = NWDSCreateContextHandle(&ctx);
|
||||
if (err)
|
||||
return err;
|
||||
ctx->dck.flags = DCV_XLATE_STRINGS | DCV_TYPELESS_NAMES | DCV_DEREF_ALIASES;
|
||||
ctx->dck.flags = DCV_XLATE_STRINGS | DCV_TYPELESS_NAMES | DCV_DEREF_ALIASES | DCV_CANONICALIZE_NAMES;
|
||||
ctx->priv_flags |= DCV_PRIV_AUTHENTICATING;
|
||||
err = NWDSXlateFromCtx(ctx, user_w, sizeof(user_w), user);
|
||||
if (err)
|
||||
goto err_exit;
|
||||
err = NWDSSetContext(ctx, DCK_LOCAL_CHARSET, "WCHAR_T//");
|
||||
if (err)
|
||||
goto err_exit;
|
||||
NWDSAddConnection(ctx, conn);
|
||||
strcpy_cw(user_w, user);
|
||||
err = nds_login(ctx, (const wchar_t*)user_w, pwd);
|
||||
err = nds_login(ctx, (const NWDSChar*)user_w, pwd);
|
||||
if ((err == ERR_NO_SUCH_ENTRY) &&
|
||||
(user_w[0] != '.') &&
|
||||
(user_w[wcslen(user_w)-1] != '.')) {
|
||||
#ifdef ERR_MSG
|
||||
printf(_("User %s not found in current context.\n"
|
||||
@@ -1354,7 +1357,8 @@ long nds_login_auth(struct ncp_conn *conn, const char *user,
|
||||
memcpy(user_w + wcslen(user_w),
|
||||
server_name + i,
|
||||
(wcslen(server_name + i) + 1) * sizeof(wchar_t));
|
||||
err = nds_login(ctx, user_w, pwd);
|
||||
ctx->dck.flags &= ~DCV_CANONICALIZE_NAMES;
|
||||
err = nds_login(ctx, (const NWDSChar*)user_w, pwd);
|
||||
}
|
||||
if (err) {
|
||||
if (err != NWE_PASSWORD_EXPIRED) {
|
||||
|
||||
@@ -48,7 +48,7 @@ NWDSCCODE __NWDSGetPrivateKey(NWCONN_HANDLE conn, const nuint8* connPublicKey,
|
||||
const nuint8 rndseed[4], NWObjectID objectID,
|
||||
const nuint8 pwdHash[16], nuint8 logindata[8],
|
||||
nuint8** privateKey, size_t* privateKeyLen);
|
||||
NWDSCCODE nds_login(NWDSContextHandle ctx, const wchar_t* objectName,
|
||||
NWDSCCODE nds_login(NWDSContextHandle ctx, const NWDSChar* objectName,
|
||||
const char* objectPassword);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -277,6 +277,9 @@ strrqerror(int err)
|
||||
{NWE_UNSUPPORTED_TRAN_TYPE, /* 8870 */
|
||||
N_("Unsupported transport type")},
|
||||
/* ... */
|
||||
{NWE_UNSUPPORTED_AUTHENTICATOR, /* 8873 */
|
||||
N_("Unsupported authenticator")},
|
||||
/* ... */
|
||||
{0x10000,
|
||||
NULL}};
|
||||
const struct errxlat* eptr = rqerrors;
|
||||
|
||||
Reference in New Issue
Block a user