Import ncpfs 0.17
This commit is contained in:
@@ -2,9 +2,12 @@
|
||||
# Makefile for the linux ncp-filesystem routines.
|
||||
#
|
||||
|
||||
UTIL_EXECS = ncpmount ncpumount nprint slist pqlist fsinfo pserver
|
||||
UTILS = $(addprefix $(INTERM_BINDIR)/,$(UTIL_EXECS))
|
||||
USERUTILS = slist pqlist nwfsinfo pserver
|
||||
UIDUTILS = ncpmount ncpumount
|
||||
SBINUTILS = nwmsg
|
||||
|
||||
UTIL_EXECS = $(USERUTILS) $(UIDUTILS) $(SBINUTILS)
|
||||
UTILS = $(addprefix $(INTERM_BINDIR)/,$(UTIL_EXECS))
|
||||
|
||||
#CFLAGS = -Wall $(INCLUDES) $(KERNELD) -g -DNCPFS_VERSION=\"$(VERSION)\"
|
||||
CFLAGS = -Wall $(INCLUDES) $(KERNELD) -O2 -DNCPFS_VERSION=\"$(VERSION)\"
|
||||
@@ -14,8 +17,11 @@ all: $(UTILS) ncptest
|
||||
|
||||
install: all
|
||||
for i in $(UTIL_EXECS); \
|
||||
do install --strip $(INTERM_BINDIR)/$$i -m 755 $(BINDIR); done
|
||||
for i in $(UIDUTILS); do chmod 4755 $(BINDIR)/$$i; done
|
||||
do install $(INTERM_BINDIR)/$$i -m 755 $(BINDIR); done
|
||||
for i in $(UIDUTILS); \
|
||||
do install $(INTERM_BINDIR)/$$i -m 4755 $(BINDIR); done
|
||||
for i in $(SBINUTILS); \
|
||||
do install $(INTERM_BINDIR)/$$i -m 755 $(SBINDIR); done
|
||||
|
||||
$(UTILS): $(addsuffix .o,$(UTIL_EXECS)) ncplib.o
|
||||
$(CC) -o $@ $(addsuffix .o,$(notdir $@)) ncplib.o
|
||||
|
||||
@@ -2742,6 +2742,36 @@ ncp_write(struct ncp_conn *conn, const char *file_id,
|
||||
return already_written;
|
||||
}
|
||||
|
||||
int
|
||||
ncp_copy_file(struct ncp_conn *conn,
|
||||
const char source_file[6],
|
||||
const char target_file[6],
|
||||
__u32 source_offset,
|
||||
__u32 target_offset,
|
||||
__u32 count,
|
||||
__u32 *copied_count)
|
||||
{
|
||||
int result;
|
||||
|
||||
ncp_init_request(conn);
|
||||
|
||||
ncp_add_byte(conn, 0); /* reserved */
|
||||
ncp_add_mem(conn, source_file, 6);
|
||||
ncp_add_mem(conn, target_file, 6);
|
||||
ncp_add_dword(conn, source_offset);
|
||||
ncp_add_dword(conn, target_offset);
|
||||
ncp_add_dword(conn, count);
|
||||
|
||||
if ((result = ncp_request(conn, 74)) != 0)
|
||||
{
|
||||
ncp_unlock_conn(conn);
|
||||
return result;
|
||||
}
|
||||
|
||||
*copied_count = ncp_reply_dword(conn, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
ncp_get_broadcast_message(struct ncp_conn *conn, char message[256])
|
||||
{
|
||||
|
||||
@@ -257,6 +257,15 @@ int
|
||||
ncp_write(struct ncp_conn *conn, const char *file_id,
|
||||
off_t offset, size_t count, const char *source);
|
||||
|
||||
int
|
||||
ncp_copy_file(struct ncp_conn *conn,
|
||||
const char source_file[6],
|
||||
const char target_file[6],
|
||||
__u32 source_offset,
|
||||
__u32 target_offset,
|
||||
__u32 count,
|
||||
__u32 *copied_count);
|
||||
|
||||
int
|
||||
ncp_do_lookup(struct ncp_conn *conn,
|
||||
struct nw_info_struct *dir,
|
||||
|
||||
@@ -195,7 +195,7 @@ main(int argc, char *argv[])
|
||||
|
||||
upcase_password = 1;
|
||||
|
||||
while ((opt = getopt (argc, argv, "CS:U:c:u:g:f:d:P:nhv")) != EOF)
|
||||
while ((opt = getopt (argc, argv, "CS:U:c:u:g:f:d:P:nhvV:")) != EOF)
|
||||
{
|
||||
switch (opt)
|
||||
{
|
||||
@@ -285,6 +285,14 @@ main(int argc, char *argv[])
|
||||
}
|
||||
password = optarg;
|
||||
break;
|
||||
case 'V':
|
||||
if (strlen(optarg) >= sizeof(data.mounted_vol))
|
||||
{
|
||||
printf("Volume too long: %s\n", optarg);
|
||||
exit(1);
|
||||
}
|
||||
strcpy(data.mounted_vol, optarg);
|
||||
break;
|
||||
case 'n':
|
||||
password = "";
|
||||
break;
|
||||
@@ -346,6 +354,7 @@ main(int argc, char *argv[])
|
||||
|
||||
data.version = NCP_MOUNT_VERSION;
|
||||
data.mounted_uid = conn_uid;
|
||||
memcpy(data.server_name, spec->server, sizeof(data.server_name));
|
||||
|
||||
if (data.dir_mode == 0)
|
||||
{
|
||||
@@ -466,7 +475,8 @@ main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
if ( (ncp_open_mount(&conn, mount_point) != 0)
|
||||
|| (ncp_login_user(&conn, spec->user, spec->password) != 0))
|
||||
|| (ncp_login_user(&conn, spec->user, spec->password) != 0)
|
||||
|| (ioctl(conn.mount_fid, NCP_IOC_CONN_LOGGED_IN, NULL) != 0))
|
||||
{
|
||||
fprintf(stderr, "%s: login failed\n", strerror(errno));
|
||||
ncp_close(&conn);
|
||||
|
||||
@@ -178,20 +178,3 @@ main(int argc, char *argv[])
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Overrides for Emacs so that we follow Linus's tabbing style.
|
||||
* Emacs will notice this stuff at the end of the file and automatically
|
||||
* adjust the settings for this buffer only. This must remain at the end
|
||||
* of the file.
|
||||
* ---------------------------------------------------------------------------
|
||||
* Local variables:
|
||||
* c-indent-level: 8
|
||||
* c-brace-imaginary-offset: 0
|
||||
* c-brace-offset: -8
|
||||
* c-argdecl-indent: 8
|
||||
* c-label-offset: -8
|
||||
* c-continued-statement-offset: 8
|
||||
* c-continued-brace-offset: 0
|
||||
* End:
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* nwprint.c
|
||||
* nprint.c
|
||||
*
|
||||
* Send data to a NetWare print queue.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* fsinfo.c
|
||||
* nwfsinfo.c
|
||||
*
|
||||
* Print the info strings of a server, maybe sometime more.
|
||||
*
|
||||
219
util/nwmsg.c
Normal file
219
util/nwmsg.c
Normal file
@@ -0,0 +1,219 @@
|
||||
/*
|
||||
* nwmsg.c
|
||||
*
|
||||
* Fetch NetWare broadcast messages and write to the user
|
||||
*
|
||||
* Copyright (C) 1996 by Volker Lendecke
|
||||
*
|
||||
*/
|
||||
|
||||
#include <pwd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
#include <syslog.h>
|
||||
#include <signal.h>
|
||||
#include <paths.h>
|
||||
#include <utmp.h>
|
||||
#include <mntent.h>
|
||||
#include "ncplib.h"
|
||||
|
||||
static int search_utmp(char *user, char *tty);
|
||||
|
||||
static char *progname;
|
||||
|
||||
void
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
struct ncp_conn conn;
|
||||
char message[256];
|
||||
struct ncp_fs_info info;
|
||||
struct passwd *pwd;
|
||||
char tty[256];
|
||||
char tty_path[256];
|
||||
FILE *tty_file;
|
||||
FILE *mtab;
|
||||
struct mntent *mnt;
|
||||
|
||||
|
||||
progname = argv[0];
|
||||
|
||||
openlog("nwmsg", LOG_PID, LOG_LPR);
|
||||
|
||||
if (argc != 2)
|
||||
{
|
||||
fprintf(stderr, "usage: %s mount-point\n",
|
||||
progname);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (ncp_open_mount(&conn, argv[1]) != 0)
|
||||
{
|
||||
fprintf(stderr, "%s: could not open connection %s\n",
|
||||
progname, argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (ncp_get_broadcast_message(&conn, message) != 0)
|
||||
{
|
||||
fprintf(stderr, "%s: could not get broadcast message\n",
|
||||
progname);
|
||||
ncp_close(&conn);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (strlen(message) == 0)
|
||||
{
|
||||
syslog(LOG_DEBUG, "no message");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
#if 0
|
||||
syslog(LOG_DEBUG, "message: %s", message);
|
||||
#endif
|
||||
|
||||
info.version = NCP_GET_FS_INFO_VERSION;
|
||||
if (ioctl(conn.mount_fid, NCP_IOC_GET_FS_INFO, &info) < 0)
|
||||
{
|
||||
fprintf(stderr, "%s: could not ioctl on connection: %s\n",
|
||||
progname, strerror(errno));
|
||||
ncp_close(&conn);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ncp_close(&conn);
|
||||
|
||||
if ((pwd = getpwuid(info.mounted_uid)) == NULL)
|
||||
{
|
||||
fprintf(stderr, "%s: user %d not known\n",
|
||||
progname, info.mounted_uid);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ((mtab = fopen(MOUNTED, "r")) == NULL)
|
||||
{
|
||||
fprintf(stderr, "%s: can't open %s\n",
|
||||
progname, MOUNTED);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
while ((mnt = getmntent(mtab)) != NULL)
|
||||
{
|
||||
if (strcmp(mnt->mnt_dir, conn.mount_point) == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (mnt == NULL)
|
||||
{
|
||||
syslog(LOG_DEBUG, "cannot find mtab entry\n");
|
||||
}
|
||||
|
||||
if (search_utmp(pwd->pw_name, tty) != 0)
|
||||
{
|
||||
exit(1);
|
||||
}
|
||||
|
||||
sprintf(tty_path, "/dev/%s", tty);
|
||||
if ((tty_file = fopen(tty_path, "w")) == NULL)
|
||||
{
|
||||
fprintf(stderr, "%s: cannot open %s: %s\n",
|
||||
progname, tty_path, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fprintf(tty_file, "\r\n\007\007\007Message from NetWare Server: %s\n",
|
||||
mnt->mnt_fsname);
|
||||
fprintf(tty_file, "%s\n", message);
|
||||
fclose(tty_file);
|
||||
fclose(mtab);
|
||||
return;
|
||||
}
|
||||
|
||||
/* The following routines have been taken from util-linux-2.5's write.c */
|
||||
|
||||
/*
|
||||
* term_chk - check that a terminal exists, and get the message bit
|
||||
* and the access time
|
||||
*/
|
||||
static int
|
||||
term_chk(char *tty, int *msgsokP, time_t *atimeP, int *showerror)
|
||||
{
|
||||
struct stat s;
|
||||
char path[MAXPATHLEN];
|
||||
|
||||
(void)sprintf(path, "/dev/%s", tty);
|
||||
if (stat(path, &s) < 0) {
|
||||
if (showerror)
|
||||
(void)fprintf(stderr,
|
||||
"write: %s: %s\n", path, strerror(errno));
|
||||
return(1);
|
||||
}
|
||||
*msgsokP = (s.st_mode & (S_IWRITE >> 3)) != 0; /* group write bit */
|
||||
*atimeP = s.st_atime;
|
||||
return(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* search_utmp - search utmp for the "best" terminal to write to
|
||||
*
|
||||
* Ignores terminals with messages disabled, and of the rest, returns
|
||||
* the one with the most recent access time. Returns as value the number
|
||||
* of the user's terminals with messages enabled, or -1 if the user is
|
||||
* not logged in at all.
|
||||
*
|
||||
* Special case for writing to yourself - ignore the terminal you're
|
||||
* writing from, unless that's the only terminal with messages enabled.
|
||||
*/
|
||||
static int
|
||||
search_utmp(char *user, char *tty)
|
||||
{
|
||||
struct utmp u;
|
||||
time_t bestatime, atime;
|
||||
int ufd, nloggedttys, nttys, msgsok, user_is_me;
|
||||
|
||||
char atty[sizeof(u.ut_line) + 1];
|
||||
|
||||
if ((ufd = open(_PATH_UTMP, O_RDONLY)) < 0) {
|
||||
perror("utmp");
|
||||
return -1;
|
||||
}
|
||||
|
||||
nloggedttys = nttys = 0;
|
||||
bestatime = 0;
|
||||
user_is_me = 0;
|
||||
while (read(ufd, (char *) &u, sizeof(u)) == sizeof(u))
|
||||
if (strncmp(user, u.ut_name, sizeof(u.ut_name)) == 0) {
|
||||
++nloggedttys;
|
||||
|
||||
(void)strncpy(atty, u.ut_line, sizeof(u.ut_line));
|
||||
atty[sizeof(u.ut_line)] = '\0';
|
||||
|
||||
if (term_chk(atty, &msgsok, &atime, 0))
|
||||
continue; /* bad term? skip */
|
||||
if (!msgsok)
|
||||
continue; /* skip ttys with msgs off */
|
||||
|
||||
if (u.ut_type != USER_PROCESS)
|
||||
continue; /* it's not a valid entry */
|
||||
|
||||
++nttys;
|
||||
if (atime > bestatime) {
|
||||
bestatime = atime;
|
||||
(void)strcpy(tty, atty);
|
||||
}
|
||||
}
|
||||
|
||||
(void)close(ufd);
|
||||
if (nloggedttys == 0) {
|
||||
(void)fprintf(stderr, "write: %s is not logged in\n", user);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -62,7 +62,7 @@ main(int argc, char **argv)
|
||||
{
|
||||
found = 1;
|
||||
printf("%-52s", q.object_name);
|
||||
printf("%08X\n", q.object_id);
|
||||
printf("%08X\n", (unsigned int)q.object_id);
|
||||
}
|
||||
|
||||
if ((found == 0) && (isatty(1)))
|
||||
|
||||
@@ -9,10 +9,12 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <syslog.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/stat.h>
|
||||
#include <signal.h>
|
||||
#include "ncplib.h"
|
||||
|
||||
@@ -77,26 +79,29 @@ terminate_handler()
|
||||
term_request=1;
|
||||
}
|
||||
|
||||
static void
|
||||
daemonize()
|
||||
/* Daemon_init is taken from Stevens, Adv. Unix programming */
|
||||
static int
|
||||
daemon_init(void)
|
||||
{
|
||||
int fd,c;
|
||||
|
||||
if ((c = fork()) > 0) exit(0);
|
||||
if (c < 0)
|
||||
{
|
||||
fprintf(stderr, "ipxripd: can't fork: %s\n",strerror(errno));
|
||||
exit(1);
|
||||
pid_t pid;
|
||||
|
||||
if ((pid = fork()) < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else if (pid != 0)
|
||||
{
|
||||
exit(0); /* parent vanishes */
|
||||
}
|
||||
|
||||
/* child process */
|
||||
setsid();
|
||||
chdir("/");
|
||||
umask(0);
|
||||
close(0);
|
||||
close(1);
|
||||
close(2);
|
||||
if ((fd = open("/dev/tty", O_RDWR)) >= 0)
|
||||
{
|
||||
ioctl(fd, TIOCNOTTY, NULL);
|
||||
close(fd);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
@@ -137,12 +142,13 @@ main(int argc, char *argv[])
|
||||
|
||||
if (debug == 0)
|
||||
{
|
||||
daemonize();
|
||||
daemon_init();
|
||||
openlog("pserver", LOG_PID, LOG_LPR);
|
||||
}
|
||||
|
||||
if (ncp_initialize_as(&conn, &argc, argv, 1, NCP_BINDERY_PSERVER) != 0)
|
||||
{
|
||||
perror("Could not open connection");
|
||||
perror("Could not open connection");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -268,13 +274,13 @@ poll_queue(struct nw_queue *q)
|
||||
|
||||
if (pipe(fd) < 0)
|
||||
{
|
||||
perror("pipe");
|
||||
syslog(LOG_ERR, "pipe error: %m");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if ((pid = fork()) < 0)
|
||||
{
|
||||
perror("fork");
|
||||
syslog(LOG_ERR, "fork error: %m");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@@ -301,7 +307,7 @@ poll_queue(struct nw_queue *q)
|
||||
|
||||
if (waitpid(pid, NULL, 0) < 0)
|
||||
{
|
||||
perror("waitpid");
|
||||
syslog(LOG_ERR, "waitpid: %m\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -314,7 +320,7 @@ poll_queue(struct nw_queue *q)
|
||||
{
|
||||
if (dup2(fd[0], STDIN_FILENO) != STDIN_FILENO)
|
||||
{
|
||||
perror("dup2");
|
||||
syslog(LOG_ERR, "dup2 error: %m\n");
|
||||
close(fd[0]);
|
||||
exit(1);
|
||||
}
|
||||
@@ -322,7 +328,7 @@ poll_queue(struct nw_queue *q)
|
||||
}
|
||||
|
||||
execl("/bin/sh", "sh", "-c", q->command, NULL);
|
||||
perror("exec");
|
||||
syslog(LOG_ERR, "exec error: %m\n");
|
||||
close(fd[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user