Import ncpfs 2.2.4

This commit is contained in:
ncpfs archive import
2026-04-28 20:40:00 +02:00
parent f6ac693f98
commit ef8405088b
51 changed files with 31221 additions and 9147 deletions

View File

@@ -548,6 +548,8 @@ void init_mount_info(struct ncp_mount_info *info) {
memset(info, 0, sizeof(*info));
myuid = getuid();
info->version = -1;
info->flags = MS_MGC_VAL;
info->sig_level = -1;
@@ -557,8 +559,6 @@ void init_mount_info(struct ncp_mount_info *info) {
info->pathlen = 1;
info->passwd_fd = ~0;
myuid = getuid();
info->mdata.mounted_uid = myuid;
info->mdata.uid = myuid;
info->mdata.gid = getgid();
@@ -578,6 +578,10 @@ void init_mount_info(struct ncp_mount_info *info) {
info->mdata.mounted_vol = "";
info->upcase_password = 1;
info->bcastmode = NWCC_BCAST_PERMIT_ALL; /* all broadcasts by default */
if (!suser()) {
info->flags |= MS_NODEV | MS_NOEXEC | MS_NOSUID;
}
}
int ncp_mount(const char* mount_name, struct ncp_mount_info* info) {
@@ -1421,6 +1425,26 @@ static void opt_clear_flags(struct ncp_mount_info* info, unsigned int param) {
info->flags &= ~param;
}
static void opt_clear_flags_su(struct ncp_mount_info* info, unsigned int param) {
if (info->flags & param) {
if (suser()) {
info->flags &= ~param;
return;
}
errexit(82, _("You are not allowed to clear nosuid and nodev flags\n"));
}
}
static void opt_clear_noexec(struct ncp_mount_info* info, unsigned int param) {
if (info->flags & param) {
if (suser() || myuid == info->mdata.uid) {
info->flags &= ~param;
return;
}
errexit(83, _("You are not allowed to clear noexec flag\n"));
}
}
static void opt_remount(struct ncp_mount_info* info, unsigned int param) __attribute__((noreturn));
static void opt_remount(struct ncp_mount_info* info, unsigned int param) {
errexit(7, _("Remounting not supported, sorry\n"));
@@ -1542,11 +1566,11 @@ static struct optinfo globopts[] = {
{0, "ro", FN_NOPARAM, opt_set_flags, MS_RDONLY},
{0, "rw", FN_NOPARAM, opt_clear_flags, MS_RDONLY},
{0, "nosuid", FN_NOPARAM, opt_set_flags, MS_NOSUID},
{0, "suid", FN_NOPARAM, opt_clear_flags, MS_NOSUID},
{0, "suid", FN_NOPARAM, opt_clear_flags_su, MS_NOSUID},
{0, "nodev", FN_NOPARAM, opt_set_flags, MS_NODEV},
{0, "dev", FN_NOPARAM, opt_clear_flags, MS_NODEV},
{0, "dev", FN_NOPARAM, opt_clear_flags_su, MS_NODEV},
{0, "noexec", FN_NOPARAM, opt_set_flags, MS_NOEXEC},
{0, "exec", FN_NOPARAM, opt_clear_flags, MS_NOEXEC},
{0, "exec", FN_NOPARAM, opt_clear_noexec, MS_NOEXEC},
{0, "sync", FN_NOPARAM, opt_set_flags, MS_SYNCHRONOUS},
{0, "async", FN_NOPARAM, opt_clear_flags, MS_SYNCHRONOUS},
{0, "mand", FN_NOPARAM, opt_set_flags, MS_MANDLOCK},

View File

@@ -98,6 +98,7 @@ struct ncp_mount_info {
int echo_mnt_pnt; /*print out the mounted point if success*/
const char* use_local_mnt_dir; /* use /mnt/ncp/$USER instead of $HOME/ncp */
/*end additions*/
const char* auth_src; /* ncpmount -A ... */
};
void init_mount_info(struct ncp_mount_info *info);

View File

@@ -151,11 +151,16 @@ static void opt_set_allow_multiple(struct ncp_mount_info* info, unsigned int par
info->allow_multiple_connections = param;
}
static void opt_set_auth(struct ncp_mount_info* info, const char* param) {
info->auth_src = param;
}
static struct optinfo opts[] = {
{'T', "tree", FN_STRING, opt_set_tree, 0},
{'b', "bindery", FN_NOPARAM, opt_set_bindery, 1},
{'V', "volume", FN_STRING, opt_set_volume, 0},
{'m', "multiple", FN_NOPARAM, opt_set_allow_multiple, 1},
{'a', "auth", FN_STRING, opt_set_auth, 0},
{0, NULL, 0, NULL, 0}
};
@@ -165,6 +170,10 @@ main(int argc, char *argv[])
struct ncp_mount_info info;
struct stat st;
char mount_name[256];
#ifdef NDS_SUPPORT
NWDSContextHandle ctx;
NWCONN_HANDLE auth_conn;
#endif
int result;
@@ -194,7 +203,7 @@ main(int argc, char *argv[])
init_mount_info(&info);
while ((opt = getopt(argc, argv, "CS:U:c:u:g:f:d:P:nh?vV:t:r:o:"
while ((opt = getopt(argc, argv, "a:CS:U:c:u:g:f:d:P:nh?vV:t:r:o:"
"sN:y:p:bi:mA:T:"
#ifdef MOUNT2
"2"
@@ -213,6 +222,7 @@ main(int argc, char *argv[])
case 'b':
case 'm':
optarg = NULL;
case 'a':
case 'S':
case 'T':
case 'U':
@@ -369,7 +379,6 @@ main(int argc, char *argv[])
}
#ifdef NDS_SUPPORT
if (info.tree) {
NWDSContextHandle ctx;
static char vol[64];
static char serv[64];
nuint32 ctxf;
@@ -439,18 +448,46 @@ main(int argc, char *argv[])
}
}
}
if ((err = ncp_find_conn_spec3(info.server, info.user, info.password, 1,
info.mdata.uid, 1, &spec))
!= 0)
{
mycom_err(err, _("in find_conn_spec"));
exit(33);
}
if (info.upcase_password != 0)
{
str_upper(spec.password);
err = NWDSCreateContextHandle(&ctx);
if (err) {
mycom_err(err, _("in create context"));
exit(113);
}
if (info.auth_src) {
NWDSChar user[MAX_DN_BYTES];
err = ncp_open_mount(info.auth_src, &auth_conn);
if (err) {
NWDSFreeContext(ctx);
mycom_err(err, _("opening mount %s"), info.auth_src);
exit(114);
}
NWDSAddConnection(ctx, auth_conn);
err = NWDSWhoAmI(ctx, user);
if (err) {
NWDSFreeContext(ctx);
NWCCCloseConn(auth_conn);
mycom_err(err, _("retrieving user name"));
exit(117);
}
memset(&spec, 0, sizeof(spec));
strncpy(spec.server, info.server, sizeof(spec.server));
strncpy(spec.user, user, sizeof(spec.user));
} else {
if ((err = ncp_find_conn_spec3(info.server, info.user, info.password, 1,
info.mdata.uid, 1, &spec))
!= 0)
{
NWDSFreeContext(ctx);
mycom_err(err, _("in find_conn_spec"));
exit(33);
}
if (info.upcase_password != 0)
{
str_upper(spec.password);
}
auth_conn = NULL;
}
info.mdata.server_name = spec.server;
if (info.mdata.dir_mode == 0)
@@ -479,6 +516,10 @@ main(int argc, char *argv[])
if ((!info.allow_multiple_connections)&&
((tmp_mount = ncp_find_permanent(&spec)) != NULL))
{
NWDSFreeContext(ctx);
if (auth_conn) {
NWCCCloseConn(auth_conn);
}
fprintf(stderr,
_("You already have mounted server %s\nas user "
"%s\non mount point %s\n"), spec.server, spec.user,
@@ -493,6 +534,10 @@ main(int argc, char *argv[])
err = ncp_find_server_addr(&info.server_name, OT_FILE_SERVER, (struct sockaddr*)&info.mdata.serv_addr,
sizeof(info.mdata.serv_addr), tran);
if (err) {
NWDSFreeContext(ctx);
if (auth_conn) {
NWCCCloseConn(auth_conn);
}
eprintf(_("Get host address `%s': %s\n"), info.server_name, strnwerror(err));
exit(1);
}
@@ -509,6 +554,10 @@ ncpipx:;
if ((!info.allow_multiple_connections)&&
((tmp_mount = ncp_find_permanent(&spec)) != NULL))
{
NWDSFreeContext(ctx);
if (auth_conn) {
NWCCCloseConn(auth_conn);
}
fprintf(stderr,
_("You already have mounted server %s\nas user "
"%s\non mount point %s\n"), spec.server, spec.user,
@@ -517,6 +566,10 @@ ncpipx:;
}
if ((err = ncp_find_fileserver(spec.server, (struct sockaddr*)&info.mdata.serv_addr, sizeof(info.mdata.serv_addr))) != 0)
{
NWDSFreeContext(ctx);
if (auth_conn) {
NWCCCloseConn(auth_conn);
}
mycom_err(err, _("when trying to find %s"),
spec.server);
exit(36);
@@ -525,6 +578,10 @@ ncpipx:;
err = proc_buildconn(&info);
if (err) {
NWDSFreeContext(ctx);
if (auth_conn) {
NWCCCloseConn(auth_conn);
}
exit(err);
}
@@ -537,16 +594,34 @@ ncpipx:;
result = ncp_mount(mount_name, &info);
if (result)
{
NWDSFreeContext(ctx);
if (auth_conn) {
NWCCCloseConn(auth_conn);
}
mycom_err(result, _("in mount(2)"));
exit(51);
}
err = proc_aftermount(&info, &conn);
if (err) {
umount(info.mdata.mount_point);
NWDSFreeContext(ctx);
if (auth_conn) {
NWCCCloseConn(auth_conn);
}
exit(err);
}
#ifdef NDS_SUPPORT
if (!info.force_bindery_login && NWIsDSServer(conn, NULL))
if (info.auth_src != NULL) {
err = NWDSAuthenticateConn(ctx, conn);
if (err) {
NWDSFreeContext(ctx);
if (auth_conn) {
NWCCCloseConn(auth_conn);
}
mycom_err(err, _("in authenticate connection"));
exit(115);
}
} else if (!info.force_bindery_login && NWIsDSServer(conn, NULL))
{
if ((err = nds_login_auth(conn, spec.user, spec.password)))
{
@@ -555,6 +630,10 @@ ncpipx:;
fprintf(stderr, _("Login denied.\n"));
ncp_close(conn);
umount(mount_point);
NWDSFreeContext(ctx);
if (auth_conn) {
NWCCCloseConn(auth_conn);
}
exit(55);
}
fprintf(stderr, _("Your password has expired\n"));
@@ -575,6 +654,10 @@ ncpipx:;
fprintf(stderr, _("Login denied\n"));
ncp_close(conn);
umount(mount_point);
NWDSFreeContext(ctx);
if (auth_conn) {
NWCCCloseConn(auth_conn);
}
exit(56);
}
fprintf(stderr, _("Your password has expired\n"));
@@ -590,6 +673,17 @@ ncpipx:;
#ifdef NDS_SUPPORT
}
#endif
err = NWDSFreeContext(ctx);
if (err) {
if (auth_conn) {
NWCCCloseConn(auth_conn);
}
mycom_err(err, _("in free context"));
exit(116);
}
if (auth_conn) {
NWCCCloseConn(auth_conn);
}
if ((err = ncp_mount_specific(conn, -1, info.NWpath, info.pathlen)) != 0)
{
ncp_close(conn);