Add ncplogin/logout programs which allow manage connections
more precisely than mount_nwfs. Obtained from: ncplib-1.3.3
This commit is contained in:
parent
b78133c1d9
commit
27490905ca
@ -214,6 +214,7 @@ SUBDIR+=ar \
|
||||
gcore \
|
||||
gprof4 \
|
||||
ncplist \
|
||||
ncplogin \
|
||||
nm \
|
||||
ranlib \
|
||||
sasc \
|
||||
|
12
usr.bin/ncplogin/Makefile
Normal file
12
usr.bin/ncplogin/Makefile
Normal file
@ -0,0 +1,12 @@
|
||||
# $FreeBSD$
|
||||
|
||||
PROG= ncplogin
|
||||
SRCS= ncplogin.c
|
||||
MAN1= ncplogin.1 ncplogout.1
|
||||
|
||||
LINKS= ${BINDIR}/ncplogin ${BINDIR}/ncplogout
|
||||
|
||||
LDADD+= -lipx -lncp
|
||||
DPADD+= ${LIBIPX} ${LIBNCP}
|
||||
|
||||
.include <bsd.prog.mk>
|
159
usr.bin/ncplogin/ncplogin.1
Normal file
159
usr.bin/ncplogin/ncplogin.1
Normal file
@ -0,0 +1,159 @@
|
||||
.\" $FreeBSD$
|
||||
.Dd Sep 15, 1999
|
||||
.Dt NCPLOGIN 1
|
||||
.Os FreeBSD 4.0
|
||||
.Sh NAME
|
||||
.Nm ncplogin
|
||||
.Nd create permanent connection to a NetWare server,
|
||||
.Sh SYNOPSIS
|
||||
.Nm ncplogin
|
||||
.Op Fl S Ar server Fl U Ar user
|
||||
.Op Fl A Ar host
|
||||
.Op Fl B
|
||||
.Op Fl C
|
||||
.Op Fl D
|
||||
.Op Fl I Ar level
|
||||
.Op Fl M Ar mode
|
||||
.Op Fl N
|
||||
.\" hm, which is right way to do this ?
|
||||
.Op Fl O Ar owner Op :group
|
||||
.Op Fl O Ar :group
|
||||
|
|
||||
.Op Fl R Ar retrycount
|
||||
.Op Fl T Ar tree
|
||||
.Op Fl W Ar timeout
|
||||
.Ar /server:user
|
||||
.Sh DESCRIPTION
|
||||
Connections to a NetWare server can be created and used independently from
|
||||
.Xr mount_nwfs 8
|
||||
command. Connection can be created by any user. Each user can have multiple
|
||||
connections, but NetWareServer:NetWareUser pair should be unique.
|
||||
.Pp
|
||||
The
|
||||
.Nm ncplogin
|
||||
command used to create permanent connection to a NetWare server. Permanent
|
||||
connection will stay connected even if no applications use it. This allows
|
||||
user to run different ncp* programs without specifying file server and user
|
||||
to use. This connection can be destroyed by
|
||||
.Xr ncplogout 1
|
||||
command.
|
||||
.Pp
|
||||
Upper case options described in this manual are common for other ncp* programs
|
||||
and referred as
|
||||
.Ar connection options.
|
||||
Options
|
||||
.Fl U
|
||||
and
|
||||
.Fl S
|
||||
are mutually exclusive with
|
||||
.Ar /server:user
|
||||
syntax.
|
||||
.Pp
|
||||
The options are:
|
||||
.Bl -tag -width indent
|
||||
.It Fl S Ar server
|
||||
name of NetWare server to connect. This affect only IPX severs for native IP
|
||||
see
|
||||
.Fl A
|
||||
option.
|
||||
.It Fl U Ar user
|
||||
name of user used in login sequence.
|
||||
.It Fl A Ar host
|
||||
connect to NetWare/IP server, specified by host.
|
||||
.It Fl C
|
||||
don't convert password to uppercase.
|
||||
.It Fl D
|
||||
Marks connection as primary. Can be used to modify already established
|
||||
connection. Only
|
||||
.Nm
|
||||
program accept that option.
|
||||
.It Fl I Ar signature_level
|
||||
try to use
|
||||
.Ar signature_level .
|
||||
.Bd -literal -offset indent
|
||||
Value Meaning
|
||||
0 disable signatures
|
||||
1 enable, use if server require them.
|
||||
2 ask server for signing, but agree to work without.
|
||||
3 signatures are required.
|
||||
.Ed
|
||||
Please note that only packet headers signing are implemented.
|
||||
.It Fl M Ar mode
|
||||
Just like files connections can be shared by users. The bits in
|
||||
.Ar mode
|
||||
argument behaves much like file permissions:
|
||||
.Bd -literal -offset indent
|
||||
Mask Meaning
|
||||
4 READ - connection will be visible.
|
||||
2 WRITE - connection can be closed/modified
|
||||
1 EXECUTE - user allowed to execute requests.
|
||||
.Ed
|
||||
By default connection created with mode 0700 and only owner can do
|
||||
anything with it. If you want to share the connection, for example with group
|
||||
you may specify 0750 value. This means group can do NCP request, but can't
|
||||
destroy connection. When user doesn't explicitly specify server to use, ncp*
|
||||
programs try to find suitable connection in the next order:
|
||||
.Pp
|
||||
1. Try to find connection owned by user. If there is more than one such
|
||||
connection it try to figure out which is primary. Primary flag controlled
|
||||
by
|
||||
.Fl D
|
||||
option.
|
||||
.Pp
|
||||
2. If previous fail, first shared connection will be used.
|
||||
.It Fl N
|
||||
don't ask for a password. While loading
|
||||
.Nm
|
||||
reads ~/.nwfsrc file to get additional configuration parameters and
|
||||
password. If no password found for the specified SERVER:USER pair,
|
||||
.Nm
|
||||
prompts for it.
|
||||
.It Fl O
|
||||
Just like files, connection has
|
||||
.Ar owner and
|
||||
.Ar group
|
||||
attributes. Newly created connection takes
|
||||
.Ar owner
|
||||
parameter from creator's userid and
|
||||
.Ar group
|
||||
paramter
|
||||
from creator's primary group.
|
||||
This can be overrided with this option. Only superuser can override an
|
||||
.Ar owner
|
||||
parameter.
|
||||
.It Fl P
|
||||
Marks connection as permanent.
|
||||
.Nm
|
||||
always create permanent connection. This option can be used in other ncp*
|
||||
programs.
|
||||
.It Fl R Ar retry_count
|
||||
specifies number of retries before drop the connection. The default value is 10.
|
||||
|
||||
Note: after connection marked 'BAD' each request will try to restore it.
|
||||
This process restore only NCP connection, but do not reopen any opened files.
|
||||
.It Fl W Ar timeout
|
||||
This specifies server request timeout in seconds. The default is 5 seconds.
|
||||
.It Ar /server:user
|
||||
This syntax provided for the sake of simplicity and mutually exclusive with
|
||||
.Fl S
|
||||
and
|
||||
.Fl U
|
||||
options.
|
||||
.El
|
||||
.Sh FILES
|
||||
.Bl -tag -width /var/log/wtmp -compact
|
||||
.It Pa ~/.nwfsrc
|
||||
keeps description for each connection. See
|
||||
.Xr nwfsrc 8
|
||||
for details.
|
||||
|
||||
.Sh NOTES
|
||||
Low level connection management performed by ncp.ko module. For an IPX
|
||||
protocol it is also necessary to load IPXrouted program.
|
||||
|
||||
.Sh BUGS
|
||||
to number a few
|
||||
|
||||
.Sh AUTHORS
|
||||
.An Boris Popov Aq bp@butya.kz ,
|
||||
.Aq rbp@chat.ru
|
201
usr.bin/ncplogin/ncplogin.c
Normal file
201
usr.bin/ncplogin/ncplogin.c
Normal file
@ -0,0 +1,201 @@
|
||||
/*
|
||||
* Copyright (c) 1999, Boris Popov
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Boris Popov.
|
||||
* 4. Neither the name of the author nor the names of any co-contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
#include <sys/errno.h>
|
||||
#include <sys/stat.h>
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <strings.h>
|
||||
#include <stdlib.h>
|
||||
#include <sysexits.h>
|
||||
|
||||
#include <netncp/ncp_lib.h>
|
||||
#include <netncp/ncp_rcfile.h>
|
||||
|
||||
extern char *__progname;
|
||||
|
||||
static void
|
||||
login_usage() {
|
||||
printf("usage: %s [-Dh] [-A host] [-BCN] [-I level] [-M mode] \n"
|
||||
" [-R retrycount] [-W timeout] /server:user\n", __progname);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void
|
||||
logout_usage() {
|
||||
printf("usage: %s [-c handle] [-h] [/server:user]\n", __progname);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void
|
||||
login(int argc, char *argv[], struct ncp_conn_loginfo *li) {
|
||||
int error = 0, connid, opt, setprimary = 0;
|
||||
|
||||
while ((opt = getopt(argc, argv, STDPARAM_OPT"D")) != EOF){
|
||||
switch(opt){
|
||||
case STDPARAM_ARGS:
|
||||
if (ncp_li_arg(li, opt, optarg))
|
||||
exit(1);
|
||||
break;
|
||||
case 'D':
|
||||
setprimary = 1;
|
||||
break;
|
||||
default:
|
||||
login_usage();
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
}
|
||||
if (li->access_mode == 0)
|
||||
li->access_mode = S_IRWXU;
|
||||
if (ncp_li_check(li))
|
||||
exit(1);
|
||||
li->opt |= NCP_OPT_WDOG | NCP_OPT_PERMANENT;
|
||||
/* now we can try to login, or use already established connection */
|
||||
error = ncp_li_login(li, &connid);
|
||||
if (error) {
|
||||
ncp_error("Could not login to server %s", error, li->server);
|
||||
exit(1);
|
||||
}
|
||||
error = ncp_setpermanent(connid, 1);
|
||||
if (error && errno != EACCES){
|
||||
ncp_error("Can't make connection permanent", error);
|
||||
exit(1);
|
||||
}
|
||||
if (setprimary && ncp_setprimary(connid, 1) != 0)
|
||||
ncp_error("Warning: can't make connection primary", errno);
|
||||
printf("Logged in with conn handle:%d\n", connid);
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
logout(int argc, char *argv[], struct ncp_conn_loginfo *li) {
|
||||
int error = 0, connid, opt;
|
||||
|
||||
connid = -1;
|
||||
while ((opt = getopt(argc, argv, STDPARAM_OPT"c:")) != EOF){
|
||||
switch (opt) {
|
||||
case 'c':
|
||||
connid = atoi(optarg);
|
||||
break;
|
||||
case STDPARAM_ARGS:
|
||||
if (ncp_li_arg(li, opt, optarg))
|
||||
exit(1);
|
||||
break;
|
||||
default:
|
||||
logout_usage();
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
}
|
||||
if (connid == -1) {
|
||||
if (li->server[0] == 0)
|
||||
errx(EX_USAGE, "no server name specified");
|
||||
if (li->user == 0)
|
||||
errx(EX_USAGE, "no user name specified");
|
||||
if (ncp_conn_scan(li, &connid))
|
||||
errx(EX_OSERR, "You are not attached to server %s",
|
||||
li->server);
|
||||
}
|
||||
if (ncp_setpermanent(connid, 0) < 0 && errno != EACCES) {
|
||||
ncp_error("Connection isn't valid", errno);
|
||||
exit(EX_OSERR);
|
||||
}
|
||||
error = ncp_disconnect(connid);
|
||||
if (error) {
|
||||
if (errno == EACCES) {
|
||||
warnx("you logged out, but connection belongs"
|
||||
"to other user and not closed");
|
||||
} else {
|
||||
ncp_error("Can't logout with connid %d", error, connid);
|
||||
error = 1;
|
||||
}
|
||||
}
|
||||
exit(error ? 1 : 0);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[]) {
|
||||
int islogin, error;
|
||||
char *p, *p1;
|
||||
struct ncp_conn_loginfo li;
|
||||
|
||||
islogin = strcmp(__progname, "ncplogin") == 0;
|
||||
|
||||
if (argc == 2) {
|
||||
if (strcmp(argv[1], "-h") == 0) {
|
||||
if (islogin)
|
||||
login_usage();
|
||||
else
|
||||
logout_usage();
|
||||
}
|
||||
}
|
||||
|
||||
if (ncp_initlib())
|
||||
exit(1);
|
||||
if (ncp_li_init(&li, argc, argv))
|
||||
return 1;
|
||||
|
||||
if (argc >= 2 && argv[argc - 1][0] == '/') {
|
||||
p = argv[argc - 1];
|
||||
error = 1;
|
||||
do {
|
||||
if (*p++ != '/')
|
||||
break;
|
||||
p1 = strchr(p, ':');
|
||||
if (p1 == NULL)
|
||||
break;
|
||||
*p1++ = 0;
|
||||
if (ncp_li_setserver(&li, p))
|
||||
break;
|
||||
if (*p1 == 0)
|
||||
break;
|
||||
if (ncp_li_setuser(&li, p1)) break;
|
||||
error = 0;
|
||||
} while(0);
|
||||
if (error)
|
||||
errx(EX_DATAERR,
|
||||
"an error occured while parsing '%s'",
|
||||
argv[argc - 1]);
|
||||
}
|
||||
|
||||
if (ncp_li_readrc(&li))
|
||||
return 1;
|
||||
if (ncp_rc)
|
||||
rc_close(ncp_rc);
|
||||
if (islogin)
|
||||
login(argc, argv, &li);
|
||||
else
|
||||
logout(argc, argv, &li);
|
||||
return 0;
|
||||
}
|
52
usr.bin/ncplogin/ncplogout.1
Normal file
52
usr.bin/ncplogin/ncplogout.1
Normal file
@ -0,0 +1,52 @@
|
||||
.\" $FreeBSD$
|
||||
.Dd Sep 15, 1999
|
||||
.Dt NCPLOGOUT 1
|
||||
.Os FreeBSD 4.0
|
||||
.Sh NAME
|
||||
.Nm ncplogout
|
||||
.Nd shedule permanent connection to close
|
||||
.Sh SYNOPSIS
|
||||
.Nm ncplogout
|
||||
.Op -S Ar server
|
||||
.Op -U Ar user
|
||||
.Op -c Ar handle
|
||||
.Nm ncplogout
|
||||
.Op -c Ar handle
|
||||
.Ar /server:user
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
will shedule connection created by
|
||||
.Xr ncplogin 1
|
||||
command to close. If connection is busy (i.e. used by other processes) it will
|
||||
be closed when last process terminated. This command is similar to DOS
|
||||
logout.exe command.
|
||||
.Pp
|
||||
The options are:
|
||||
.Bl -tag -width indent
|
||||
.It Fl S Ar server
|
||||
name of Netware server to identify connection. Can be omitted if there is only
|
||||
one connection active.
|
||||
.It Fl U Ar user
|
||||
name of user used to identify connection. Can be omitted if there is only
|
||||
one connection active.
|
||||
.It Fl c Ar handle
|
||||
close connection by handle. List of available handles can be obtained via
|
||||
.Bd -literal -offset indent
|
||||
ncplist c
|
||||
.Ed
|
||||
command.
|
||||
.El
|
||||
.Sh FILES
|
||||
.Bl -tag -width /var/log/wtmp -compact
|
||||
.It Pa ~/.nwfsrc??
|
||||
keeps description for each connection. See
|
||||
.Xr nwfsrc 8
|
||||
for details.
|
||||
|
||||
.Sh BUGS
|
||||
to number a few
|
||||
|
||||
.Sh AUTHORS
|
||||
.An Boris Popov Aq bp@butya.kz ,
|
||||
.Aq bp@freebsd.org
|
Loading…
Reference in New Issue
Block a user