Compare commits

...

3 Commits

Author SHA1 Message Date
ncpfs archive import
c6c6fbe4ca Import ncpfs 2.1.1 2026-04-28 20:39:59 +02:00
ncpfs archive import
f813517d69 Import ncpfs 2.0.12 2026-04-28 20:39:59 +02:00
ncpfs archive import
915f560f85 Import ncpfs 2.0.11 2026-04-28 20:39:59 +02:00
83 changed files with 8027 additions and 8204 deletions

BIN
.downloads/ncpfs-2.0.11.tgz Normal file

Binary file not shown.

BIN
.downloads/ncpfs-2.0.12.tgz Normal file

Binary file not shown.

BIN
.downloads/ncpfs-2.1.1.tgz Normal file

Binary file not shown.

View File

@@ -1,6 +1,10 @@
I only began this file with ncpfs-0.12. If you're interested in older
versions, you can find them on ftp.gwdg.de:/pub/linux/misc/ncpfs/old.
ncpfs-2.0.10 -> ncpfs-2.1.1
- Restructured the kernel part a bit, moved watchdog and message support
out of the kernel into ncpmount.
ncpfs-2.0.9 -> ncpfs-2.0.10
- Made nwtrustee hopefully work ;-)
- Made the manpages a little bit prettier

View File

@@ -2,7 +2,7 @@
# Makefile for the linux ncp-filesystem routines.
#
VERSION = 2.0.10
VERSION = 2.1.1
# If you are using kerneld to autoload ncp support,
# uncomment this (kerneld is in linux since about 1.3.57):
@@ -23,11 +23,6 @@ KVERSION=$(shell uname -r | cut -b1-3)
INCLUDES=-I$(TOPDIR)/include
ifeq ($(KVERSION),1.2)
SUBDIRS += kernel-1.2/src
INCLUDES += -I$(TOPDIR)/kernel-1.2
endif
COPT = -O2
COPT += -g
CFLAGS = $(COPT) -Wall $(INCLUDES) $(KERNELD) -DNCPFS_VERSION=\"$(VERSION)\"

45
README
View File

@@ -1,7 +1,7 @@
This is ncpfs, a free NetWare client filesystem for Linux. Besides
some little utilities it also contains nprint, which enables you to
print on NetWare print queues. The opposite side, pserver, is also
provided.
This is ncpfs, the user utilities that are needed to use the NCP kernel support
present in Linux since version 1.3.71. This version of ncpfs is only usable
with Linux 2.1.29 and later. To use it, please apply the patch contained in the
patches/ directory.
ncpfs works with NetWare versions 3.x and following. It does NOT work
with NetWare version 2.x. Some of the NetWare look-alikes, such as
@@ -24,38 +24,11 @@ information.
INSTALLATION
Before you start the installation, make sure that your kernel has IPX
support compiled in. When 'make config' asks you for
The IPX protocol (CONFIG_IPX) [N/y/m/?]
simply answer 'y'. Probably you do not need the full internal net that
you are asked for next.
The installation of ncpfs depends on the kernel version you are
using. For kernel 1.2, you should simply type 'make' and look at
what's in the bin/ directory after that. Please be sure that your
kernel resides in /usr/src/linux, because the file
kernel-1.2/src/sock.c has to refer directly to it.
If you use Kernel 1.3, please be sure that you use at least
1.3.71. ncpfs does NOT work with any earlier 1.3.x kernel.
If you use Kernel 1.3.71 or later, you might have to recompile your
kernel. With these kernels, the kernel part of ncpfs is already
included in the main source tree. If you want to use ncpfs, you should
say 'y' to 'make config' when you are asked for IPX, and again when it
asks for ncpfs. After you have rebooted with the new kernel, 'cat
/proc/filesystems' should show you a line saying that the kernel knows
ncpfs.
If you are running kerneld, please uncomment the corresponding line in
the Makefile to reflect this.
If your system is ELF, please enable the use of the shared ncp-library
in the Makefile. This will save at least 1MB of disk space.
After you adapted your Makefile, type 'make' and, as root, 'make install'.
Before you start the installation of the user utilities, please make sure that
your kernel is 2.1.29 or later. If you are using 2.1.29, please apply the patch
contained in patches/linux-2.1.29.diff. You have to compile your kernel with
IPX and NCP support compiled in. But as you are using a development kernel, you
probably know what you're doing :-).
HELP

View File

@@ -27,8 +27,7 @@ static int search_utmp(char *user, char *tty);
static char *progname;
void
main(int argc, char *argv[])
void main(int argc, char *argv[])
{
struct ncp_conn *conn;
char message[256];
@@ -51,27 +50,23 @@ main(int argc, char *argv[])
openlog("nwmsg", LOG_PID, LOG_LPR);
if (argc != 2)
{
if (argc != 2) {
fprintf(stderr, "usage: %s mount-point\n",
progname);
exit(1);
}
mount_point = argv[1];
if ((conn = ncp_open_mount(mount_point, &err)) == NULL)
{
if ((conn = ncp_open_mount(mount_point, &err)) == NULL) {
com_err(progname, err, "in ncp_open_mount");
exit(1);
}
if (ncp_get_broadcast_message(conn, message) != 0)
{
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)
{
if (strlen(message) == 0) {
syslog(LOG_DEBUG, "no message");
exit(0);
}
@@ -80,8 +75,7 @@ main(int argc, char *argv[])
#endif
info.version = NCP_GET_FS_INFO_VERSION;
if (ioctl(conn->mount_fid, NCP_IOC_GET_FS_INFO, &info) < 0)
{
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);
@@ -89,37 +83,30 @@ main(int argc, char *argv[])
}
ncp_close(conn);
if ((pwd = getpwuid(info.mounted_uid)) == NULL)
{
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)
{
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, mount_point) == 0)
{
while ((mnt = getmntent(mtab)) != NULL) {
if (strcmp(mnt->mnt_dir, mount_point) == 0) {
break;
}
}
if (mnt == NULL)
{
if (mnt == NULL) {
syslog(LOG_DEBUG, "cannot find mtab entry\n");
}
if (search_utmp(pwd->pw_name, tty) != 0)
{
if (search_utmp(pwd->pw_name, tty) != 0) {
exit(1);
}
sprintf(tty_path, "/dev/%s", tty);
if ((tty_file = fopen(tty_path, "w")) == NULL)
{
if ((tty_file = fopen(tty_path, "w")) == NULL) {
fprintf(stderr, "%s: cannot open %s: %s\n",
progname, tty_path, strerror(errno));
exit(1);
@@ -152,18 +139,16 @@ main(int argc, char *argv[])
* 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)
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 (stat(path, &s) < 0) {
if (showerror)
(void) fprintf(stderr,
"write: %s: %s\n", path, strerror(errno));
"write: %s: %s\n", path, strerror(errno));
return (1);
}
*msgsokP = (s.st_mode & (S_IWRITE >> 3)) != 0; /* group write bit */
@@ -182,8 +167,7 @@ term_chk(char *tty, int *msgsokP, time_t * atimeP, int *showerror)
* 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)
static int search_utmp(char *user, char *tty)
{
struct utmp u;
time_t bestatime, atime;
@@ -191,8 +175,7 @@ search_utmp(char *user, char *tty)
char atty[sizeof(u.ut_line) + 1];
if ((ufd = open(_PATH_UTMP, O_RDONLY)) < 0)
{
if ((ufd = open(_PATH_UTMP, O_RDONLY)) < 0) {
perror("utmp");
return -1;
}
@@ -200,8 +183,7 @@ search_utmp(char *user, char *tty)
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)
{
if (strncmp(user, u.ut_name, sizeof(u.ut_name)) == 0) {
++nloggedttys;
(void) strncpy(atty, u.ut_line, sizeof(u.ut_line));
@@ -216,15 +198,13 @@ search_utmp(char *user, char *tty)
continue; /* it's not a valid entry */
++nttys;
if (atime > bestatime)
{
if (atime > bestatime) {
bestatime = atime;
(void) strcpy(tty, atty);
}
}
(void) close(ufd);
if (nloggedttys == 0)
{
if (nloggedttys == 0) {
(void) fprintf(stderr, "write: %s is not logged in\n", user);
return -1;
}

View File

@@ -10,8 +10,7 @@
#include <linux/types.h>
#include <linux/ncp.h>
#include <linux/ncp_fs.h>
#include "ncp.h"
#include <linux/ipx.h>
#include <stdio.h>
@@ -33,14 +32,12 @@ typedef unsigned char IPXNode[IPX_NODE_LEN];
#define IPX_SAP_FILE_SERVER (0x0004)
struct sap_query
{
struct sap_query {
unsigned short query_type; /* net order */
unsigned short server_type; /* net order */
};
struct sap_server_ident
{
struct sap_server_ident {
unsigned short server_type __attribute__((packed));
char server_name[48] __attribute__((packed));
IPXNet server_network __attribute__((packed));
@@ -52,16 +49,13 @@ struct sap_server_ident
#define IPX_RIP_REQUEST (0x1)
#define IPX_RIP_RESPONSE (0x2)
struct ipx_rip_packet
{
struct ipx_rip_packet {
__u16 operation __attribute__((packed));
struct ipx_rt_def
{
struct ipx_rt_def {
__u32 network __attribute__((packed));
__u16 hops __attribute__((packed));
__u16 ticks __attribute__((packed));
}
rt[1] __attribute__((packed));
} rt[1] __attribute__((packed));
};
#define IPX_BROADCAST_NODE ("\xff\xff\xff\xff\xff\xff")

123
include/ncp.h Normal file
View File

@@ -0,0 +1,123 @@
/*
* ncp.h
*
* Copyright (C) 1995 by Volker Lendecke
* Modified for sparc by J.F. Chadima
*
*/
#ifndef _NCP_H
#define _NCP_H
#include <linux/types.h>
#include <linux/ipx.h>
#include <linux/ncp.h>
#include <linux/ncp_fs.h>
#define NCP_BINDERY_USER (0x0001)
#define NCP_BINDERY_UGROUP (0x0002)
#define NCP_BINDERY_PQUEUE (0x0003)
#define NCP_BINDERY_FSERVER (0x0004)
#define NCP_BINDERY_NAME_LEN (48)
struct ncp_bindery_object {
__u32 object_id;
__u16 object_type;
__u8 object_name[NCP_BINDERY_NAME_LEN];
__u8 object_flags;
__u8 object_security;
__u8 object_has_prop;
};
struct nw_property {
__u8 value[128];
__u8 more_flag;
__u8 property_flag;
};
struct prop_net_address {
__u32 network __attribute__((packed));
__u8 node[IPX_NODE_LEN] __attribute__((packed));
__u16 port __attribute__((packed));
};
struct ncp_filesearch_info {
__u8 volume_number;
__u16 directory_id;
__u16 sequence_no;
__u8 access_rights;
};
#define NCP_MAX_FILENAME (14)
struct ncp_file_info {
__u8 file_id[NCP_FILE_ID_LEN];
char file_name[NCP_MAX_FILENAME + 1];
__u8 file_attributes;
__u8 file_mode;
__u32 file_length;
__u16 creation_date;
__u16 access_date;
__u16 update_date;
__u16 update_time;
};
struct nw_queue_job_entry {
__u16 InUse __attribute__((packed));
__u32 prev __attribute__((packed));
__u32 next __attribute__((packed));
__u32 ClientStation __attribute__((packed));
__u32 ClientTask __attribute__((packed));
__u32 ClientObjectID __attribute__((packed));
__u32 TargetServerID __attribute__((packed));
__u8 TargetExecTime[6] __attribute__((packed));
__u8 JobEntryTime[6] __attribute__((packed));
__u32 JobNumber __attribute__((packed));
__u16 JobType __attribute__((packed));
__u16 JobPosition __attribute__((packed));
__u16 JobControlFlags __attribute__((packed));
__u8 FileNameLen __attribute__((packed));
char JobFileName[13] __attribute__((packed));
__u32 JobFileHandle __attribute__((packed));
__u32 ServerStation __attribute__((packed));
__u32 ServerTaskNumber __attribute__((packed));
__u32 ServerObjectID __attribute__((packed));
char JobTextDescription[50] __attribute__((packed));
char ClientRecordArea[152] __attribute__((packed));
};
struct queue_job {
struct nw_queue_job_entry j;
__u8 file_handle[6];
};
#define QJE_OPER_HOLD 0x80
#define QJE_USER_HOLD 0x40
#define QJE_ENTRYOPEN 0x20
#define QJE_SERV_RESTART 0x10
#define QJE_SERV_AUTO 0x08
/* ClientRecordArea for print jobs */
#define KEEP_ON 0x0400
#define NO_FORM_FEED 0x0800
#define NOTIFICATION 0x1000
#define DELETE_FILE 0x2000
#define EXPAND_TABS 0x4000
#define PRINT_BANNER 0x8000
struct print_job_record {
__u8 Version __attribute__((packed));
__u8 TabSize __attribute__((packed));
__u16 Copies __attribute__((packed));
__u16 CtrlFlags __attribute__((packed));
__u16 Lines __attribute__((packed));
__u16 Rows __attribute__((packed));
char FormName[16] __attribute__((packed));
__u8 Reserved[6] __attribute__((packed));
char BannerName[13] __attribute__((packed));
char FnameBanner[13] __attribute__((packed));
char FnameHeader[14] __attribute__((packed));
char Path[80] __attribute__((packed));
};
#endif /* _NCP_H */

View File

@@ -9,8 +9,7 @@
#define _NCPLIB_H
#include <linux/types.h>
#include <linux/ncp.h>
#include <linux/ncp_fs.h>
#include "ncp.h"
#include <linux/ipx.h>
#include <sys/param.h>
#include <stdio.h>
@@ -33,23 +32,21 @@ typedef __u32 dword;
#define BSET(buf,pos,val) (BVAL(buf,pos) = (val))
static inline word
WVAL_HL(__u8 * buf, int pos)
WVAL_HL(__u8 * buf, int pos)
{
return PVAL(buf, pos) << 8 | PVAL(buf, pos + 1);
}
static inline dword
DVAL_HL(__u8 * buf, int pos)
DVAL_HL(__u8 * buf, int pos)
{
return WVAL_HL(buf, pos) << 16 | WVAL_HL(buf, pos + 2);
}
static inline void
WSET_HL(__u8 * buf, int pos, word val)
static inline void WSET_HL(__u8 * buf, int pos, word val)
{
BSET(buf, pos, val >> 8);
BSET(buf, pos + 1, val & 0xff);
}
static inline void
DSET_HL(__u8 * buf, int pos, dword val)
static inline void DSET_HL(__u8 * buf, int pos, dword val)
{
WSET_HL(buf, pos, val >> 16);
WSET_HL(buf, pos + 2, val & 0xffff);
@@ -61,22 +58,20 @@ DSET_HL(__u8 * buf, int pos, dword val)
#if defined(__i386__)
static inline word
WVAL_LH(__u8 * buf, int pos)
WVAL_LH(__u8 * buf, int pos)
{
return *((word *) (buf + pos));
}
static inline dword
DVAL_LH(__u8 * buf, int pos)
DVAL_LH(__u8 * buf, int pos)
{
return *((dword *) (buf + pos));
}
static inline void
WSET_LH(__u8 * buf, int pos, word val)
static inline void WSET_LH(__u8 * buf, int pos, word val)
{
*((word *) (buf + pos)) = val;
}
static inline void
DSET_LH(__u8 * buf, int pos, dword val)
static inline void DSET_LH(__u8 * buf, int pos, dword val)
{
*((dword *) (buf + pos)) = val;
}
@@ -84,23 +79,21 @@ DSET_LH(__u8 * buf, int pos, dword val)
#else
static inline word
WVAL_LH(__u8 * buf, int pos)
WVAL_LH(__u8 * buf, int pos)
{
return PVAL(buf, pos) | PVAL(buf, pos + 1) << 8;
}
static inline dword
DVAL_LH(__u8 * buf, int pos)
DVAL_LH(__u8 * buf, int pos)
{
return WVAL_LH(buf, pos) | WVAL_LH(buf, pos + 2) << 16;
}
static inline void
WSET_LH(__u8 * buf, int pos, word val)
static inline void WSET_LH(__u8 * buf, int pos, word val)
{
BSET(buf, pos, val & 0xff);
BSET(buf, pos + 1, val >> 8);
}
static inline void
DSET_LH(__u8 * buf, int pos, dword val)
static inline void DSET_LH(__u8 * buf, int pos, dword val)
{
WSET_LH(buf, pos, val & 0xffff);
WSET_LH(buf, pos + 2, val >> 16);
@@ -114,15 +107,13 @@ DSET_LH(__u8 * buf, int pos, dword val)
void
str_upper(char *name);
enum connect_state
{
enum connect_state {
NOT_CONNECTED = 0,
CONN_PERMANENT,
CONN_TEMPORARY
};
struct ncp_conn
{
struct ncp_conn {
enum connect_state is_connected;
@@ -155,8 +146,7 @@ struct ncp_conn
char packet[NCP_PACKET_SIZE];
};
struct ncp_conn_spec
{
struct ncp_conn_spec {
char server[NCP_BINDERY_NAME_LEN];
char user[NCP_BINDERY_NAME_LEN];
uid_t uid;
@@ -164,14 +154,12 @@ struct ncp_conn_spec
char password[NCP_BINDERY_NAME_LEN];
};
struct ncp_search_seq
{
struct ncp_search_seq {
struct nw_search_sequence s;
int namespace;
};
struct ncp_property_info
{
struct ncp_property_info {
__u8 property_name[16];
__u8 property_flags;
__u8 property_security;
@@ -225,8 +213,7 @@ long
/* like getmntent, get_ncp_conn_ent scans /etc/mtab for usable
connections */
struct ncp_conn_ent
{
struct ncp_conn_ent {
char server[NCP_BINDERY_NAME_LEN];
char user[NCP_BINDERY_NAME_LEN];
uid_t uid;
@@ -254,8 +241,7 @@ long
long
ncp_set_file_server_time(struct ncp_conn *conn, time_t * source);
struct ncp_file_server_info
{
struct ncp_file_server_info {
__u8 ServerName[48] __attribute__((packed));
__u8 FileServiceVersion __attribute__((packed));
__u8 FileServiceSubVersion __attribute__((packed));
@@ -316,7 +302,7 @@ long
struct ncp_bindery_object *target);
long
ncp_scan_bindery_object(struct ncp_conn *conn,
__u32 last_id, __u16 object_type, char *search_string,
__u32 last_id, __u16 object_type, char *search_string,
struct ncp_bindery_object *target);
long
ncp_create_bindery_object(struct ncp_conn *conn,
@@ -335,15 +321,13 @@ long
const char *object_name,
__u8 security);
struct ncp_station_addr
{
struct ncp_station_addr {
__u32 NetWork __attribute__((packed));
__u8 Node[6] __attribute__((packed));
__u16 Socket __attribute__((packed));
};
struct ncp_prop_login_control
{
struct ncp_prop_login_control {
__u8 AccountExpireDate[3] __attribute__((packed));
__u8 Disabled __attribute__((packed));
__u8 PasswordExpireDate[3] __attribute__((packed));
@@ -606,8 +590,8 @@ long
long
ncp_ren_or_mov_file_or_subdir(struct ncp_conn *conn,
struct nw_info_struct *old_dir, char *old_name,
struct nw_info_struct *new_dir, char *new_name);
struct nw_info_struct *old_dir, char *old_name,
struct nw_info_struct *new_dir, char *new_name);
long
ncp_create_queue_job_and_file(struct ncp_conn *conn,
@@ -660,8 +644,7 @@ long
struct nw_info_struct *file,
__u16 * target);
struct ncp_trustee_struct
{
struct ncp_trustee_struct {
__u32 object_id;
__u16 rights;
};

View File

@@ -5,8 +5,7 @@
#include <sys/socket.h>
#include <errno.h>
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
struct sockaddr_ipx sipx;
int s;
@@ -15,8 +14,7 @@ main(int argc, char **argv)
int len;
s = socket(AF_IPX, SOCK_DGRAM, AF_IPX);
if (s < 0)
{
if (s < 0) {
perror("IPX: socket: ");
exit(-1);
}
@@ -26,16 +24,14 @@ main(int argc, char **argv)
sipx.sipx_type = 17;
len = sizeof(sipx);
result = bind(s, (struct sockaddr *) &sipx, sizeof(sipx));
if (result < 0)
{
if (result < 0) {
perror("IPX: bind: ");
exit(-1);
}
msg[0] = '\0';
result = recvfrom(s, msg, sizeof(msg), 0, (struct sockaddr *) &sipx,
&len);
if (result < 0)
{
if (result < 0) {
perror("IPX: recvfrom: ");
}
printf("From %08lX:%02X%02X%02X%02X%02X%02X:%04X\n",

View File

@@ -9,8 +9,7 @@
#include <sys/socket.h>
#include <errno.h>
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
struct sockaddr_ipx sipx;
int s;
@@ -19,8 +18,7 @@ main(int argc, char **argv)
int len = sizeof(sipx);
s = socket(AF_IPX, SOCK_DGRAM, AF_IPX);
if (s < 0)
{
if (s < 0) {
perror("IPX: socket: ");
exit(-1);
}
@@ -30,8 +28,7 @@ main(int argc, char **argv)
sipx.sipx_type = 17;
result = bind(s, (struct sockaddr *) &sipx, sizeof(sipx));
if (result < 0)
{
if (result < 0) {
perror("IPX: bind: ");
exit(-1);
}
@@ -39,8 +36,7 @@ main(int argc, char **argv)
sipx.sipx_port = htons(0x5000);
result = sendto(s, msg, sizeof(msg), 0, (struct sockaddr *) &sipx,
sizeof(sipx));
if (result < 0)
{
if (result < 0) {
perror("IPX: send: ");
exit(-1);
}

View File

@@ -9,15 +9,13 @@
#include <sys/socket.h>
#include <errno.h>
struct rip_data
{
struct rip_data {
unsigned long rip_net;
unsigned short rip_hops __attribute__((packed));
unsigned short rip_ticks __attribute__((packed));
};
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
struct sockaddr_ipx sipx;
int result;
@@ -28,8 +26,7 @@ main(int argc, char **argv)
struct rip_data *rp;
s = socket(AF_IPX, SOCK_DGRAM, AF_IPX);
if (s < 0)
{
if (s < 0) {
perror("IPX: socket: ");
exit(-1);
}
@@ -38,18 +35,15 @@ main(int argc, char **argv)
sipx.sipx_port = htons(0x453);
sipx.sipx_type = 17;
result = bind(s, (struct sockaddr *) &sipx, sizeof(sipx));
if (result < 0)
{
if (result < 0) {
perror("IPX: bind: ");
exit(-1);
}
while (1)
{
while (1) {
len = sizeof(sipx);
result = recvfrom(s, msg, sizeof(msg), 0,
(struct sockaddr *) &sipx, &len);
if (result < 0)
{
if (result < 0) {
perror("IPX: recvfrom");
exit(-1);
}
@@ -62,8 +56,7 @@ main(int argc, char **argv)
sipx.sipx_node[6], sipx.sipx_node[5]);
bptr += 2;
rp = (struct rip_data *) bptr;
while (result >= sizeof(struct rip_data))
{
while (result >= sizeof(struct rip_data)) {
printf("\tNET: %08lX HOPS: %d\n", ntohl(rp->rip_net),
ntohs(rp->rip_hops));
result -= sizeof(struct rip_data);

View File

@@ -10,8 +10,7 @@
#include <errno.h>
struct sap_data
{
struct sap_data {
unsigned short sap_type __attribute__((packed));
char sap_name[48] __attribute__((packed));
unsigned long sap_net __attribute__((packed));
@@ -20,8 +19,7 @@ struct sap_data
unsigned short sap_hops __attribute__((packed));
};
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
int s;
int result;
@@ -33,14 +31,12 @@ main(int argc, char **argv)
struct sap_data *sp;
s = socket(AF_IPX, SOCK_DGRAM, AF_IPX);
if (s < 0)
{
if (s < 0) {
perror("IPX: socket: ");
exit(-1);
}
result = setsockopt(s, SOL_SOCKET, SO_DEBUG, &val, 4);
if (result < 0)
{
if (result < 0) {
perror("IPX: setsockopt: ");
exit(-1);
}
@@ -50,18 +46,15 @@ main(int argc, char **argv)
sipx.sipx_type = 17;
result = bind(s, (struct sockaddr *) &sipx, sizeof(sipx));
if (result < 0)
{
if (result < 0) {
perror("IPX: bind: ");
exit(-1);
}
while (1)
{
while (1) {
len = 1024;
result = recvfrom(s, msg, sizeof(msg), 0,
(struct sockaddr *) &sipx, &len);
if (result < 0)
{
if (result < 0) {
perror("IPX: recvfrom: ");
exit(-1);
}
@@ -74,8 +67,7 @@ main(int argc, char **argv)
bptr += 2;
sp = (struct sap_data *) bptr;
while (result >= sizeof(struct sap_data))
{
while (result >= sizeof(struct sap_data)) {
int i;
sp->sap_name[32] = '\0';

View File

@@ -24,8 +24,7 @@ struct option options[] =
char *progname;
void
usage(void)
void usage(void)
{
fprintf(stderr,
"Usage: %s --auto_primary=[on|off]\n\
@@ -34,27 +33,23 @@ Usage: %s --help\n\
Usage: %s\n", progname, progname, progname, progname);
}
int
map_string_to_bool(char *optarg)
int map_string_to_bool(char *optarg)
{
if ((strcasecmp(optarg, "ON") == 0) ||
(strcasecmp(optarg, "TRUE") == 0) ||
(strcasecmp(optarg, "SET") == 0) ||
(strcasecmp(optarg, "YES") == 0))
{
(strcasecmp(optarg, "YES") == 0)) {
return 1;
} else if ((strcasecmp(optarg, "OFF") == 0) ||
(strcasecmp(optarg, "FALSE") == 0) ||
(strcasecmp(optarg, "CLEAR") == 0) ||
(strcasecmp(optarg, "NO") == 0))
{
(strcasecmp(optarg, "NO") == 0)) {
return 0;
}
return -1;
}
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
int s;
int result;
@@ -68,13 +63,11 @@ main(int argc, char **argv)
progname = argv[0];
s = socket(AF_IPX, SOCK_DGRAM, AF_IPX);
if (s < 0)
{
if (s < 0) {
int old_errno = errno;
sprintf(errmsg, "%s: socket", progname);
perror(errmsg);
if (old_errno == -EINVAL)
{
if (old_errno == -EINVAL) {
fprintf(stderr, "Probably you have no IPX support in "
"your kernel\n");
}
@@ -82,24 +75,20 @@ main(int argc, char **argv)
}
sprintf(errmsg, "%s: ioctl", progname);
while ((result = getopt_long(argc, argv, "", options,
&option_index)) != -1)
{
switch (result)
{
&option_index)) != -1) {
switch (result) {
case 1:
if (got_auto_pri)
break;
got_auto_pri++;
val = map_string_to_bool(optarg);
if (val < 0)
{
if (val < 0) {
usage();
exit(-1);
}
result = ioctl(s, SIOCAIPXPRISLT, &val);
if (result < 0)
{
if (result < 0) {
perror(errmsg);
exit(-1);
}
@@ -110,14 +99,12 @@ main(int argc, char **argv)
got_auto_itf++;
val = map_string_to_bool(optarg);
if (val < 0)
{
if (val < 0) {
usage();
exit(-1);
}
result = ioctl(s, SIOCAIPXITFCRT, &val);
if (result < 0)
{
if (result < 0) {
perror(errmsg);
exit(-1);
}
@@ -128,17 +115,15 @@ main(int argc, char **argv)
}
}
result = ioctl(s, SIOCIPXCFGDATA, &data);
if (result < 0)
{
if (result < 0) {
perror(errmsg);
exit(-1);
}
if (argc == 1)
{
if (argc == 1) {
fprintf(stdout, "Auto Primary Select is %s\n\
Auto Interface Create is %s\n",
(data.ipxcfg_auto_select_primary) ? "ON" : "OFF",
(data.ipxcfg_auto_create_interfaces) ? "ON" : "OFF");
(data.ipxcfg_auto_create_interfaces) ? "ON" : "OFF");
}
exit(0);
}

View File

@@ -21,8 +21,7 @@
static struct ifreq id;
static char *progname;
void
usage(void)
void usage(void)
{
fprintf(stderr, "Usage: %s add [-p] device frame_type [net_number]\n\
Usage: %s del device frame_type\n\
@@ -31,12 +30,11 @@ Usage: %s check device frame_type\n", progname, progname, progname, progname);
exit(-1);
}
struct frame_type
{
struct frame_type {
char *ft_name;
unsigned char ft_val;
}
frame_types[] =
} frame_types[] =
{
{
"802.2", IPX_FRAME_8022
@@ -63,22 +61,19 @@ frame_types[] =
#define NFTYPES (sizeof(frame_types)/sizeof(struct frame_type))
int
lookup_frame_type(char *frame)
int lookup_frame_type(char *frame)
{
int j;
for (j = 0; (j < NFTYPES) &&
(strcasecmp(frame_types[j].ft_name, frame));
j++)
;
j++);
if (j != NFTYPES)
return j;
fprintf(stderr, "%s: Frame type must be", progname);
for (j = 0; j < NFTYPES; j++)
{
for (j = 0; j < NFTYPES; j++) {
fprintf(stderr, "%s%s",
(j == NFTYPES - 1) ? " or " : " ",
frame_types[j].ft_name);
@@ -87,8 +82,7 @@ lookup_frame_type(char *frame)
return -1;
}
int
ipx_add_interface(int argc, char **argv)
int ipx_add_interface(int argc, char **argv)
{
struct sockaddr_ipx *sipx = (struct sockaddr_ipx *) &id.ifr_addr;
int s;
@@ -101,24 +95,19 @@ ipx_add_interface(int argc, char **argv)
sipx->sipx_special = IPX_SPECIAL_NONE;
sipx->sipx_network = 0L;
sipx->sipx_type = IPX_FRAME_NONE;
while ((c = getopt(argc, argv, "p")) > 0)
{
switch (c)
{
while ((c = getopt(argc, argv, "p")) > 0) {
switch (c) {
case 'p':
sipx->sipx_special = IPX_PRIMARY;
break;
}
}
if (((i = (argc - optind)) < 2) || (i > 3))
{
if (((i = (argc - optind)) < 2) || (i > 3)) {
usage();
}
for (i = optind; i < argc; i++)
{
switch (i - optind)
{
for (i = optind; i < argc; i++) {
switch (i - optind) {
case 0: /* Physical Device - Required */
strcpy(id.ifr_name, argv[i]);
break;
@@ -131,10 +120,9 @@ ipx_add_interface(int argc, char **argv)
case 2: /* Network Number - Optional */
netnum = strtoul(argv[i], (char **) NULL, 16);
if (netnum == 0xffffffffL)
{
if (netnum == 0xffffffffL) {
fprintf(stderr,
"%s: Inappropriate network number %08lX\n",
"%s: Inappropriate network number %08lX\n",
progname, netnum);
exit(-1);
}
@@ -144,13 +132,11 @@ ipx_add_interface(int argc, char **argv)
}
s = socket(AF_IPX, SOCK_DGRAM, AF_IPX);
if (s < 0)
{
if (s < 0) {
int old_errno = errno;
sprintf(errmsg, "%s: socket", progname);
perror(errmsg);
if (old_errno == -EINVAL)
{
if (old_errno == -EINVAL) {
fprintf(stderr, "Probably you have no IPX support in "
"your kernel\n");
}
@@ -159,8 +145,7 @@ ipx_add_interface(int argc, char **argv)
i = 0;
sipx->sipx_family = AF_IPX;
sipx->sipx_action = IPX_CRTITF;
do
{
do {
result = ioctl(s, SIOCSIFADDR, &id);
i++;
}
@@ -169,8 +154,7 @@ ipx_add_interface(int argc, char **argv)
if (result == 0)
exit(0);
switch (errno)
{
switch (errno) {
case EEXIST:
fprintf(stderr, "%s: Primary network already selected.\n",
progname);
@@ -208,8 +192,7 @@ ipx_add_interface(int argc, char **argv)
exit(-1);
}
int
ipx_delall_interface(int argc, char **argv)
int ipx_delall_interface(int argc, char **argv)
{
struct sockaddr_ipx *sipx = (struct sockaddr_ipx *) &id.ifr_addr;
int s;
@@ -222,31 +205,26 @@ ipx_delall_interface(int argc, char **argv)
FILE *fp;
s = socket(AF_IPX, SOCK_DGRAM, AF_IPX);
if (s < 0)
{
if (s < 0) {
sprintf(errmsg, "%s: socket", progname);
perror(errmsg);
exit(-1);
}
fp = fopen("/proc/net/ipx_interface", "r");
if (fp == NULL)
{
if (fp == NULL) {
fprintf(stderr,
"%s: Unable to open \"/proc/net/ipx_interface.\"\n",
"%s: Unable to open \"/proc/net/ipx_interface.\"\n",
progname);
exit(-1);
}
fgets(buffer, 80, fp);
while (fscanf(fp, "%s %s %s %s %s", buffer, buffer, buffer,
device, frame_type) == 5)
{
device, frame_type) == 5) {
sipx->sipx_network = 0L;
if (strcasecmp(device, "Internal") == 0)
{
if (strcasecmp(device, "Internal") == 0) {
sipx->sipx_special = IPX_INTERNAL;
} else
{
} else {
sipx->sipx_special = IPX_SPECIAL_NONE;
strcpy(id.ifr_name, device);
fti = lookup_frame_type(frame_type);
@@ -260,8 +238,7 @@ ipx_delall_interface(int argc, char **argv)
result = ioctl(s, SIOCSIFADDR, &id);
if (result == 0)
continue;
switch (errno)
{
switch (errno) {
case EPROTONOSUPPORT:
fprintf(stderr, "%s: Invalid frame type (%s).\n",
progname, frame_type);
@@ -284,8 +261,7 @@ ipx_delall_interface(int argc, char **argv)
exit(0);
}
int
ipx_del_interface(int argc, char **argv)
int ipx_del_interface(int argc, char **argv)
{
struct sockaddr_ipx *sipx = (struct sockaddr_ipx *) &id.ifr_addr;
int s;
@@ -293,8 +269,7 @@ ipx_del_interface(int argc, char **argv)
char errmsg[80];
int fti;
if (argc != 3)
{
if (argc != 3) {
usage();
}
sipx->sipx_network = 0L;
@@ -306,8 +281,7 @@ ipx_del_interface(int argc, char **argv)
sipx->sipx_type = frame_types[fti].ft_val;
s = socket(AF_IPX, SOCK_DGRAM, AF_IPX);
if (s < 0)
{
if (s < 0) {
sprintf(errmsg, "%s: socket", progname);
perror(errmsg);
exit(-1);
@@ -318,8 +292,7 @@ ipx_del_interface(int argc, char **argv)
if (result == 0)
exit(0);
switch (errno)
{
switch (errno) {
case EPROTONOSUPPORT:
fprintf(stderr, "%s: Invalid frame type (%s).\n",
progname, frame_types[fti].ft_name);
@@ -340,8 +313,7 @@ ipx_del_interface(int argc, char **argv)
exit(-1);
}
int
ipx_check_interface(int argc, char **argv)
int ipx_check_interface(int argc, char **argv)
{
struct sockaddr_ipx *sipx = (struct sockaddr_ipx *) &id.ifr_addr;
int s;
@@ -349,8 +321,7 @@ ipx_check_interface(int argc, char **argv)
char errmsg[80];
int fti;
if (argc != 3)
{
if (argc != 3) {
usage();
}
sipx->sipx_network = 0L;
@@ -361,27 +332,24 @@ ipx_check_interface(int argc, char **argv)
sipx->sipx_type = frame_types[fti].ft_val;
s = socket(AF_IPX, SOCK_DGRAM, AF_IPX);
if (s < 0)
{
if (s < 0) {
sprintf(errmsg, "%s: socket", progname);
perror(errmsg);
exit(-1);
}
sipx->sipx_family = AF_IPX;
result = ioctl(s, SIOCGIFADDR, &id);
if (result == 0)
{
if (result == 0) {
printf(
"IPX Address for (%s, %s) is %08lX:%02X%02X%02X%02X%02X%02X.\n",
argv[1], frame_types[fti].ft_name,
htonl(sipx->sipx_network), sipx->sipx_node[0],
htonl(sipx->sipx_network), sipx->sipx_node[0],
sipx->sipx_node[1], sipx->sipx_node[2],
sipx->sipx_node[3], sipx->sipx_node[4],
sipx->sipx_node[5]);
exit(0);
}
switch (errno)
{
switch (errno) {
case EPROTONOSUPPORT:
fprintf(stderr, "%s: Invalid frame type (%s).\n",
progname, frame_types[fti].ft_name);
@@ -402,34 +370,28 @@ ipx_check_interface(int argc, char **argv)
exit(-1);
}
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
int i;
progname = argv[0];
if (argc < 2)
{
if (argc < 2) {
usage();
exit(-1);
}
if (strncasecmp(argv[1], "add", 3) == 0)
{
if (strncasecmp(argv[1], "add", 3) == 0) {
for (i = 1; i < (argc - 1); i++)
argv[i] = argv[i + 1];
ipx_add_interface(argc - 1, argv);
} else if (strncasecmp(argv[1], "delall", 6) == 0)
{
} else if (strncasecmp(argv[1], "delall", 6) == 0) {
for (i = 1; i < (argc - 1); i++)
argv[i] = argv[i + 1];
ipx_delall_interface(argc - 1, argv);
} else if (strncasecmp(argv[1], "del", 3) == 0)
{
} else if (strncasecmp(argv[1], "del", 3) == 0) {
for (i = 1; i < (argc - 1); i++)
argv[i] = argv[i + 1];
ipx_del_interface(argc - 1, argv);
} else if (strncasecmp(argv[1], "check", 5) == 0)
{
} else if (strncasecmp(argv[1], "check", 5) == 0) {
for (i = 1; i < (argc - 1); i++)
argv[i] = argv[i + 1];
ipx_check_interface(argc - 1, argv);

View File

@@ -18,32 +18,26 @@
static struct ifreq id;
static char *progname;
void
usage(void)
void usage(void)
{
fprintf(stderr, "Usage: %s add net_number(hex) node(hex)\n\
Usage: %s del\n", progname, progname);
exit(-1);
}
int
map_char_to_val(char dig)
int map_char_to_val(char dig)
{
char digit = tolower(dig);
if ((digit >= '0') && (digit <= '9'))
{
if ((digit >= '0') && (digit <= '9')) {
return digit - '0';
} else if ((digit >= 'a') && (digit <= 'f'))
{
} else if ((digit >= 'a') && (digit <= 'f')) {
return (10 + (digit - 'a'));
} else
{
} else {
return 0;
}
}
int
ipx_add_internal_net(int argc, char **argv)
int ipx_add_internal_net(int argc, char **argv)
{
struct sockaddr_ipx *sipx = (struct sockaddr_ipx *) &id.ifr_addr;
int s;
@@ -57,45 +51,38 @@ ipx_add_internal_net(int argc, char **argv)
char *tin;
int i;
if (argc != 3)
{
if (argc != 3) {
usage();
}
netnum = strtoul(argv[1], (char **) NULL, 16);
if ((netnum == 0L) || (netnum == 0xffffffffL))
{
if ((netnum == 0L) || (netnum == 0xffffffffL)) {
fprintf(stderr, "%s: Inappropriate network number %08lX\n",
progname, netnum);
exit(-1);
}
node = argv[2];
nodelen = strlen(node);
if (nodelen > 12)
{
if (nodelen > 12) {
fprintf(stderr, "%s: Node length is too long (> 12).\n", progname);
exit(-1);
}
for (i = 0; (i < nodelen) && isxdigit(node[i]); i++)
;
for (i = 0; (i < nodelen) && isxdigit(node[i]); i++);
if (i < nodelen)
{
if (i < nodelen) {
fprintf(stderr, "%s: Invalid value in node, must be hex digits.\n",
progname);
exit(-1);
}
strcpy(tmpnode, "000000000000");
memcpy(&(tmpnode[12 - nodelen]), node, nodelen);
for (tin = tmpnode, tout = sipx->sipx_node; *tin != '\0'; tin += 2, tout++)
{
for (tin = tmpnode, tout = sipx->sipx_node; *tin != '\0'; tin += 2, tout++) {
*tout = (unsigned char) map_char_to_val(*tin);
*tout <<= 4;
*tout |= (unsigned char) map_char_to_val(*(tin + 1));
}
if ((memcmp(sipx->sipx_node, "\0\0\0\0\0\0\0\0", IPX_NODE_LEN) == 0) ||
(memcmp(sipx->sipx_node, "\377\377\377\377\377\377", IPX_NODE_LEN) == 0))
{
(memcmp(sipx->sipx_node, "\377\377\377\377\377\377", IPX_NODE_LEN) == 0)) {
fprintf(stderr, "%s: Node is invalid.\n", progname);
exit(-1);
}
@@ -103,8 +90,7 @@ ipx_add_internal_net(int argc, char **argv)
sipx->sipx_type = IPX_FRAME_NONE;
sipx->sipx_special = IPX_INTERNAL;
s = socket(AF_IPX, SOCK_DGRAM, AF_IPX);
if (s < 0)
{
if (s < 0) {
sprintf(errmsg, "%s: socket", progname);
perror(errmsg);
exit(-1);
@@ -112,8 +98,7 @@ ipx_add_internal_net(int argc, char **argv)
sipx->sipx_family = AF_IPX;
sipx->sipx_action = IPX_CRTITF;
i = 0;
do
{
do {
result = ioctl(s, SIOCSIFADDR, &id);
i++;
}
@@ -122,8 +107,7 @@ ipx_add_internal_net(int argc, char **argv)
if (result == 0)
exit(0);
switch (errno)
{
switch (errno) {
case EEXIST:
fprintf(stderr, "%s: Primary network already selected.\n",
progname);
@@ -134,7 +118,7 @@ ipx_add_internal_net(int argc, char **argv)
break;
case EAGAIN:
fprintf(stderr,
"%s: Insufficient memory to create internal net.\n",
"%s: Insufficient memory to create internal net.\n",
progname);
break;
default:
@@ -145,23 +129,20 @@ ipx_add_internal_net(int argc, char **argv)
exit(-1);
}
int
ipx_del_internal_net(int argc, char **argv)
int ipx_del_internal_net(int argc, char **argv)
{
struct sockaddr_ipx *sipx = (struct sockaddr_ipx *) &id.ifr_addr;
int s;
int result;
char errmsg[80];
if (argc != 1)
{
if (argc != 1) {
usage();
}
sipx->sipx_network = 0L;
sipx->sipx_special = IPX_INTERNAL;
s = socket(AF_IPX, SOCK_DGRAM, AF_IPX);
if (s < 0)
{
if (s < 0) {
sprintf(errmsg, "%s: socket", progname);
perror(errmsg);
exit(-1);
@@ -172,8 +153,7 @@ ipx_del_internal_net(int argc, char **argv)
if (result == 0)
exit(0);
switch (errno)
{
switch (errno) {
case ENOENT:
fprintf(stderr, "%s: No internal network configured.\n", progname);
break;
@@ -185,24 +165,20 @@ ipx_del_internal_net(int argc, char **argv)
exit(-1);
}
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
int i;
progname = argv[0];
if (argc < 2)
{
if (argc < 2) {
usage();
exit(-1);
}
if (strncasecmp(argv[1], "add", 3) == 0)
{
if (strncasecmp(argv[1], "add", 3) == 0) {
for (i = 1; i < (argc - 1); i++)
argv[i] = argv[i + 1];
ipx_add_internal_net(argc - 1, argv);
} else if (strncasecmp(argv[1], "del", 3) == 0)
{
} else if (strncasecmp(argv[1], "del", 3) == 0) {
for (i = 1; i < (argc - 1); i++)
argv[i] = argv[i + 1];
ipx_del_internal_net(argc - 1, argv);

View File

@@ -20,24 +20,19 @@
static struct rtentry rd;
static char *progname;
int
map_char_to_val(char dig)
int map_char_to_val(char dig)
{
char digit = tolower(dig);
if ((digit >= '0') && (digit <= '9'))
{
if ((digit >= '0') && (digit <= '9')) {
return digit - '0';
} else if ((digit >= 'a') && (digit <= 'f'))
{
} else if ((digit >= 'a') && (digit <= 'f')) {
return (10 + (digit - 'a'));
} else
{
} else {
return 0;
}
}
void
usage(void)
void usage(void)
{
fprintf(stderr,
"Usage: %s add network(hex) router_network(hex) router_node(hex)\n\
@@ -45,8 +40,7 @@ Usage: %s del network(hex)\n", progname, progname);
exit(-1);
}
int
ipx_add_route(int argc, char **argv)
int ipx_add_route(int argc, char **argv)
{
/* Router */
struct sockaddr_ipx *sr = (struct sockaddr_ipx *) &rd.rt_gateway;
@@ -68,8 +62,7 @@ ipx_add_route(int argc, char **argv)
/* Network Number */
netnum = strtoul(argv[1], (char **) NULL, 16);
if ((netnum == 0xffffffffL) || (netnum == 0L))
{
if ((netnum == 0xffffffffL) || (netnum == 0L)) {
fprintf(stderr, "%s: Inappropriate network number %08lX\n",
progname, netnum);
exit(-1);
@@ -79,8 +72,7 @@ ipx_add_route(int argc, char **argv)
/* Router Network Number */
netnum = strtoul(argv[2], (char **) NULL, 16);
if ((netnum == 0xffffffffL) || (netnum == 0L))
{
if ((netnum == 0xffffffffL) || (netnum == 0L)) {
fprintf(stderr, "%s: Inappropriate network number %08lX\n",
progname, netnum);
exit(-1);
@@ -90,47 +82,40 @@ ipx_add_route(int argc, char **argv)
/* Router Node */
node = argv[3];
nodelen = strlen(node);
if (nodelen > 12)
{
if (nodelen > 12) {
fprintf(stderr, "%s: Node length is too long (> 12).\n",
progname);
exit(-1);
}
for (i = 0; (i < nodelen) && isxdigit(node[i]); i++)
;
for (i = 0; (i < nodelen) && isxdigit(node[i]); i++);
if (i < nodelen)
{
if (i < nodelen) {
fprintf(stderr, "%s: Invalid value in node, must be hex digits.\n",
progname);
exit(-1);
}
strcpy(tmpnode, "000000000000");
memcpy(&(tmpnode[12 - nodelen]), node, nodelen);
for (tin = tmpnode, tout = sr->sipx_node; *tin != '\0'; tin += 2, tout++)
{
for (tin = tmpnode, tout = sr->sipx_node; *tin != '\0'; tin += 2, tout++) {
*tout = (unsigned char) map_char_to_val(*tin);
*tout <<= 4;
*tout |= (unsigned char) map_char_to_val(*(tin + 1));
}
if ((memcmp(sr->sipx_node, "\0\0\0\0\0\0\0\0", IPX_NODE_LEN) == 0) ||
(memcmp(sr->sipx_node, "\377\377\377\377\377\377", IPX_NODE_LEN) == 0))
{
(memcmp(sr->sipx_node, "\377\377\377\377\377\377", IPX_NODE_LEN) == 0)) {
fprintf(stderr, "%s: Node (%s) is invalid.\n", progname, tmpnode);
exit(-1);
}
s = socket(AF_IPX, SOCK_DGRAM, AF_IPX);
if (s < 0)
{
if (s < 0) {
sprintf(errmsg, "%s: socket", progname);
perror(errmsg);
exit(-1);
}
sr->sipx_family = st->sipx_family = AF_IPX;
i = 0;
do
{
do {
result = ioctl(s, SIOCADDRT, &rd);
i++;
}
@@ -139,8 +124,7 @@ ipx_add_route(int argc, char **argv)
if (result == 0)
exit(0);
switch (errno)
{
switch (errno) {
case ENETUNREACH:
fprintf(stderr, "%s: Router network (%08lX) not reachable.\n",
progname, htonl(sr->sipx_network));
@@ -153,8 +137,7 @@ ipx_add_route(int argc, char **argv)
exit(-1);
}
int
ipx_del_route(int argc, char **argv)
int ipx_del_route(int argc, char **argv)
{
/* Router */
struct sockaddr_ipx *sr = (struct sockaddr_ipx *) &rd.rt_gateway;
@@ -165,15 +148,13 @@ ipx_del_route(int argc, char **argv)
unsigned long netnum;
char errmsg[80];
if (argc != 2)
{
if (argc != 2) {
usage();
}
rd.rt_flags = RTF_GATEWAY;
/* Network Number */
netnum = strtoul(argv[1], (char **) NULL, 16);
if ((netnum == 0xffffffffL) || (netnum == 0L))
{
if ((netnum == 0xffffffffL) || (netnum == 0L)) {
fprintf(stderr, "%s: Inappropriate network number %08lX.\n",
progname, netnum);
exit(-1);
@@ -182,8 +163,7 @@ ipx_del_route(int argc, char **argv)
st->sipx_family = sr->sipx_family = AF_IPX;
s = socket(AF_IPX, SOCK_DGRAM, AF_IPX);
if (s < 0)
{
if (s < 0) {
sprintf(errmsg, "%s: socket", progname);
perror(errmsg);
exit(-1);
@@ -192,8 +172,7 @@ ipx_del_route(int argc, char **argv)
if (result == 0)
exit(0);
switch (errno)
{
switch (errno) {
case ENOENT:
fprintf(stderr, "%s: Route not found for network %08lX.\n",
progname, netnum);
@@ -210,24 +189,20 @@ ipx_del_route(int argc, char **argv)
exit(-1);
}
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
int i;
progname = argv[0];
if (argc < 2)
{
if (argc < 2) {
usage();
exit(-1);
}
if (strncasecmp(argv[1], "add", 3) == 0)
{
if (strncasecmp(argv[1], "add", 3) == 0) {
for (i = 1; i < (argc - 1); i++)
argv[i] = argv[i + 1];
ipx_add_route(argc - 1, argv);
} else if (strncasecmp(argv[1], "del", 3) == 0)
{
} else if (strncasecmp(argv[1], "del", 3) == 0) {
for (i = 1; i < (argc - 1); i++)
argv[i] = argv[i + 1];
ipx_del_route(argc - 1, argv);

View File

@@ -34,15 +34,13 @@
#include <signal.h>
#include "ipxutil.h"
struct ipx_address
{
struct ipx_address {
unsigned long net;
unsigned char node[IPX_NODE_LEN];
unsigned short sock;
};
struct ipx_packet
{
struct ipx_packet {
unsigned short ipx_checksum;
#define IPX_NO_CHECKSUM 0xFFFF
unsigned short ipx_pktsize;
@@ -66,14 +64,12 @@ static int filter = 0;
static IPXNode filter_node;
static int exit_request = 0;
static void
int_handler()
static void int_handler()
{
exit_request = 1;
}
void
main(int argc, char *argv[])
void main(int argc, char *argv[])
{
int sd;
struct ifreq ifr, oldifr;
@@ -85,17 +81,14 @@ main(int argc, char *argv[])
signal(SIGINT, int_handler);
if (argc > 1)
{
if (ipx_sscanf_node(argv[1], filter_node) != 0)
{
if (argc > 1) {
if (ipx_sscanf_node(argv[1], filter_node) != 0) {
fprintf(stderr, "usage: %s [node]\n", argv[0]);
exit(1);
}
filter = 1;
}
if ((sd = socket(AF_INET, SOCK_PACKET, htons(ETH_P_ALL))) < 0)
{
if ((sd = socket(AF_INET, SOCK_PACKET, htons(ETH_P_ALL))) < 0) {
perror("Can't get socket");
fprintf(stderr, "You must run %s as root\n", argv[0]);
exit(1);
@@ -103,8 +96,7 @@ main(int argc, char *argv[])
/* SET PROMISC */
strcpy(oldifr.ifr_name, device);
if (ioctl(sd, SIOCGIFFLAGS, &oldifr) < 0)
{
if (ioctl(sd, SIOCGIFFLAGS, &oldifr) < 0) {
close(sd);
perror("Can't get flags");
exit(2);
@@ -113,14 +105,12 @@ main(int argc, char *argv[])
ifr = oldifr;
ifr.ifr_flags |= IFF_PROMISC;
if (ioctl(sd, SIOCSIFFLAGS, &ifr) < 0)
{
if (ioctl(sd, SIOCSIFFLAGS, &ifr) < 0) {
close(sd);
perror("Can't set flags");
exit(3);
}
while (exit_request == 0)
{
while (exit_request == 0) {
/* This is the main data-gathering loop; keep it small
and fast */
sizeaddr = sizeof(saddr);
@@ -132,8 +122,7 @@ main(int argc, char *argv[])
}
/* This should be rewritten to cooperate with other net tools */
if (ioctl(sd, SIOCSIFFLAGS, &oldifr) < 0)
{
if (ioctl(sd, SIOCSIFFLAGS, &oldifr) < 0) {
close(sd);
perror("Can't set flags");
exit(4);
@@ -142,8 +131,7 @@ main(int argc, char *argv[])
exit(0);
}
void
handle_ipx(char *frame, unsigned char *buf)
void handle_ipx(char *frame, unsigned char *buf)
{
int i;
struct ipx_packet *h = (struct ipx_packet *) buf;
@@ -163,38 +151,32 @@ handle_ipx(char *frame, unsigned char *buf)
d_addr.sipx_port = h->ipx_dest.sock;
d_addr.sipx_network = h->ipx_dest.net;
if (filter != 0)
{
if (filter != 0) {
if ((memcmp(filter_node, s_addr.sipx_node,
sizeof(filter_node)) != 0)
&& (memcmp(filter_node, d_addr.sipx_node,
sizeof(filter_node)) != 0))
{
sizeof(filter_node)) != 0)) {
/* Not for us */
return;
}
}
printf("%s ", frame);
for (i = 0; i < length; i++)
{
for (i = 0; i < length; i++) {
printf("%2.2X", buf[i]);
}
printf("\n");
if (!isatty(STDOUT_FILENO))
{
if (!isatty(STDOUT_FILENO)) {
fflush(stdout);
}
}
void
handle_other(unsigned char *buf, int length, struct sockaddr *saddr)
void handle_other(unsigned char *buf, int length, struct sockaddr *saddr)
{
struct ethhdr *eth = (struct ethhdr *) buf;
unsigned char *p = &(buf[sizeof(struct ethhdr)]);
if (ntohs(eth->h_proto) < 1536)
{
if (ntohs(eth->h_proto) < 1536) {
/* This is a magic hack to spot IPX packets. Older
* Novell breaks the protocol design and runs IPX over
* 802.3 without an 802.2 LLC layer. We look for FFFF
@@ -202,32 +184,27 @@ handle_other(unsigned char *buf, int length, struct sockaddr *saddr)
* for fault tolerant netware but does for the rest.
*/
if (*(unsigned short *) p == 0xffff)
{
if (*(unsigned short *) p == 0xffff) {
handle_ipx("802.3", p);
return;
}
if ((*(unsigned short *) p == htons(0xe0e0))
&& (p[2] == 0x03))
{
&& (p[2] == 0x03)) {
handle_ipx("802.2", p + 3);
return;
}
if (memcmp(p, "\252\252\003\000\000\000\201\067", 8) == 0)
{
if (memcmp(p, "\252\252\003\000\000\000\201\067", 8) == 0) {
handle_ipx("snap", p + 8);
return;
}
}
}
void
handle_frame(unsigned char *buf, int length, struct sockaddr *saddr)
void handle_frame(unsigned char *buf, int length, struct sockaddr *saddr)
{
/* Ethernet packet type ID field */
unsigned short packet_type = ((struct ethhdr *) buf)->h_proto;
switch (packet_type)
{
switch (packet_type) {
case __constant_ntohs(ETH_P_IPX):
handle_ipx("EtherII", &(buf[sizeof(struct ethhdr)]));
break;

View File

@@ -37,15 +37,13 @@
#define DUMPALLSAPS /* #define if you want to dump all SAP's */
struct ipx_address
{
struct ipx_address {
unsigned long net;
unsigned char node[IPX_NODE_LEN];
unsigned short sock;
};
struct ipx_packet
{
struct ipx_packet {
unsigned short ipx_checksum;
#define IPX_NO_CHECKSUM 0xFFFF
unsigned short ipx_pktsize;
@@ -65,8 +63,7 @@ struct ipx_packet
#define NCP_REQUEST (0x2222)
#define NCP_DEALLOC_SLOT_REQUEST (0x5555)
struct ncp_request_header
{
struct ncp_request_header {
__u16 type __attribute__((packed));
__u8 sequence __attribute__((packed));
__u8 conn_low __attribute__((packed));
@@ -79,8 +76,7 @@ struct ncp_request_header
#define NCP_REPLY (0x3333)
#define NCP_POSITIVE_ACK (0x9999)
struct ncp_reply_header
{
struct ncp_reply_header {
__u16 type __attribute__((packed));
__u8 sequence __attribute__((packed));
__u8 conn_low __attribute__((packed));
@@ -93,8 +89,7 @@ struct ncp_reply_header
#define NCP_BURST_PACKET (0x7777)
struct ncp_burst_header
{
struct ncp_burst_header {
__u16 type __attribute__((packed));
__u8 system_flags __attribute__((packed));
__u8 stream_type __attribute__((packed));
@@ -125,37 +120,29 @@ int handle_burst(struct sockaddr_ipx *source,
/* SAP Query structure (returned in sap_packet as an array)
* NBO == Network Byte Order)
*/
typedef struct saps
{
typedef struct saps {
__u16 serverType __attribute__((packed)); /* NBO */
__u8 serverName[SAP_MAX_SERVER_NAME_LENGTH] __attribute__((packed));
struct ipx_address serverAddress __attribute__((packed));
__u16 serverHops __attribute__((packed)); /* NBO */
}
SAPS;
} SAPS;
/* General Service/Nearest Server Response SAP packet */
union sap_packet
{
union sap_packet {
unsigned short sapOperation;
struct sap_query
{
struct sap_query {
__u16 sapOperation __attribute__((packed));
__u16 serverType __attribute__((packed));
}
query;
struct sap_response
{
} query;
struct sap_response {
__u16 sapOperation __attribute__((packed));
/* each SAP can has a max of SAP_MAX_SAPS_PER_PACKET packets */
SAPS sap[SAP_MAX_SAPS_PER_PACKET] __attribute__((packed));
}
response;
} response;
};
/* print out one SAP record */
static void
print_sap(FILE * file, SAPS * sapp)
static void print_sap(FILE * file, SAPS * sapp)
{
fprintf(file, " Name:%s, serverType 0x%x, ",
sapp->serverName,
@@ -168,8 +155,7 @@ print_sap(FILE * file, SAPS * sapp)
fprintf(file, " (Hops %d)\n", ntohs(sapp->serverHops));
}
void
handle_ipx(unsigned char *buf, int length, char *frame, int no)
void handle_ipx(unsigned char *buf, int length, char *frame, int no)
{
struct ipx_packet *h = (struct ipx_packet *) buf;
struct sockaddr_ipx s_addr;
@@ -197,13 +183,11 @@ handle_ipx(unsigned char *buf, int length, char *frame, int no)
printf("\n");
if (handle_burst(&s_addr, &d_addr, buf + sizeof(struct ipx_packet),
length - sizeof(struct ipx_packet), no) != 0)
{
length - sizeof(struct ipx_packet), no) != 0) {
return;
}
if ((ntohs(s_addr.sipx_port) == 0x451)
|| (ntohs(d_addr.sipx_port) == 0x451))
{
|| (ntohs(d_addr.sipx_port) == 0x451)) {
handle_ncp(&s_addr, &d_addr, buf + sizeof(struct ipx_packet),
length - sizeof(struct ipx_packet), no);
} else
@@ -214,25 +198,21 @@ handle_ipx(unsigned char *buf, int length, char *frame, int no)
printf(" type 0x05 (SPX sequenced packet)\n");
else if (h->ipx_type == 0x14)
printf(" type 0x14 (propogated Client-NetBios)\n");
else
{
else {
hbo_dsock = ntohs(d_addr.sipx_port);
if (hbo_dsock == 0x452) /* SAP */
{
if (hbo_dsock == 0x452) { /* SAP */
sappacket = (union sap_packet *)
(buf + sizeof(struct ipx_packet));
hbo_sapop = ntohs(sappacket->sapOperation);
if ((hbo_sapop == 0x01) || (hbo_sapop == 0x03))
{
if ((hbo_sapop == 0x01) || (hbo_sapop == 0x03)) {
printf(" type 0x%x, SAP op:0x%x %s Query, "
"serverType 0x%x wanted\n",
h->ipx_type, hbo_sapop,
(hbo_sapop == 0x01) ? "General Service" :
(hbo_sapop == 0x03) ? "Nearest Server" :
(hbo_sapop == 0x01) ? "General Service" :
(hbo_sapop == 0x03) ? "Nearest Server" :
"Error",
ntohs(sappacket->query.serverType));
} else
{
ntohs(sappacket->query.serverType));
} else {
int hops;
hops = ntohs(sappacket->
@@ -248,20 +228,18 @@ handle_ipx(unsigned char *buf, int length, char *frame, int no)
? "[Shutdown]" : "");
/* Service ending */
if (hops >= SAP_SHUTDOWN)
{
if (hops >= SAP_SHUTDOWN) {
print_sap(stdout,
sappacket->response.sap);
sappacket->response.sap);
}
#ifdef DUMPALLSAPS
/* If you want to dump all SAP's */
else
{
else {
int num_saps;
SAPS *sapp;
num_saps = (length
- sizeof(struct ipx_packet)
- sizeof(struct ipx_packet)
- 2) / sizeof(SAPS);
sapp = sappacket->response.sap;
@@ -285,15 +263,13 @@ handle_ipx(unsigned char *buf, int length, char *frame, int no)
}
int
handle_burst(struct sockaddr_ipx *source,
struct sockaddr_ipx *target,
unsigned char *buf, int length, int no)
int handle_burst(struct sockaddr_ipx *source,
struct sockaddr_ipx *target,
unsigned char *buf, int length, int no)
{
struct ncp_burst_header *rq = (struct ncp_burst_header *) buf;
if (rq->type != NCP_BURST_PACKET)
{
if (rq->type != NCP_BURST_PACKET) {
return 0;
}
printf("Burst Packet\n");
@@ -303,25 +279,22 @@ handle_burst(struct sockaddr_ipx *source,
rq->source_conn, rq->dest_conn,
(unsigned int) ntohl(rq->packet_sequence));
printf("Send Delay: %08X, Burst Seq: %04X, Ack Seq: %04X\n",
(unsigned int) ntohl(rq->send_delay), ntohs(rq->burst_sequence),
(unsigned int) ntohl(rq->send_delay), ntohs(rq->burst_sequence),
ntohs(rq->ack_sequence));
printf("Burst Length: %08X\n", (unsigned int) ntohl(rq->burst_length));
printf("Data Offset: %08X, Data Bytes: %04X, Missing Frags: %04X\n",
(unsigned int) ntohl(rq->data_offset), ntohs(rq->data_bytes),
(unsigned int) ntohl(rq->data_offset), ntohs(rq->data_bytes),
ntohs(rq->missing_frags));
if (ntohs(rq->data_bytes) == 24)
{
struct ncp_burst_request
{
if (ntohs(rq->data_bytes) == 24) {
struct ncp_burst_request {
struct ncp_burst_header h __attribute__((packed));
__u32 function __attribute__((packed));
__u32 file_handle __attribute__((packed));
__u8 reserved[8] __attribute__((packed));
__u32 file_offset __attribute__((packed));
__u32 number_of_bytes __attribute__((packed));
}
*brq = (struct ncp_burst_request *) rq;
} *brq = (struct ncp_burst_request *) rq;
printf("Assuming Burst Request:\n");
printf("%s: Handle %08X, Offset %08X, Bytes %08X\n",
@@ -334,10 +307,9 @@ handle_burst(struct sockaddr_ipx *source,
return 1;
}
void
handle_ncp(struct sockaddr_ipx *source,
struct sockaddr_ipx *target,
unsigned char *buf, int length, int no)
void handle_ncp(struct sockaddr_ipx *source,
struct sockaddr_ipx *target,
unsigned char *buf, int length, int no)
{
struct ncp_request_header *rq = (struct ncp_request_header *) buf;
struct ncp_reply_header *rs = (struct ncp_reply_header *) buf;
@@ -349,8 +321,7 @@ handle_ncp(struct sockaddr_ipx *source,
static struct ncp_request_header request_header;
static char request_data[5];
if (ntohs(rq->type) == NCP_REQUEST)
{
if (ntohs(rq->type) == NCP_REQUEST) {
/* Request */
printf("NCP request: conn: %-5d, seq: %-3d, task: %-3d, ",
rq->conn_low + 256 * rq->conn_high,
@@ -363,8 +334,7 @@ handle_ncp(struct sockaddr_ipx *source,
data = buf + sizeof(struct ncp_request_header);
data_length = length - sizeof(struct ncp_request_header);
switch (rq->function)
{
switch (rq->function) {
case 18:
printf("fn: %-3d\n", rq->function);
printf("Get Volume Info with Number\n");
@@ -376,8 +346,7 @@ handle_ncp(struct sockaddr_ipx *source,
case 21:
printf("fn: %-3d, subfn: %-3d\n",
rq->function, data[2]);
switch (data[2])
{
switch (data[2]) {
case 0:
printf("Send Broadcast Message\n");
break;
@@ -391,8 +360,7 @@ handle_ncp(struct sockaddr_ipx *source,
case 22:
printf("fn: %-3d, subfn: %-3d\n",
rq->function, data[2]);
switch (data[2])
{
switch (data[2]) {
case 00:
printf("Set Directory Handle\n");
break;
@@ -436,8 +404,7 @@ handle_ncp(struct sockaddr_ipx *source,
case 23:
printf("fn: %-3d, subfn: %-3d\n", rq->function,
data[2]);
switch (data[2])
{
switch (data[2]) {
case 17:
printf("Get Fileserver Information\n");
break;
@@ -560,8 +527,7 @@ handle_ncp(struct sockaddr_ipx *source,
case 87:
printf("fn: %-3d, subfn: %-3d\n",
rq->function, data[0]);
switch (data[0])
{
switch (data[0]) {
case 1:
{
unsigned char *p = &(data[0]);
@@ -571,7 +537,7 @@ handle_ncp(struct sockaddr_ipx *source,
printf("Search Attributes: %x\n",
*(__u16 *) & (p[3]));
printf("Return Information Mask: %x\n",
(unsigned int) (*(__u32 *) & (p[5])));
(unsigned int) (*(__u32 *) & (p[5])));
printf("Desired Access Rights: %x\n",
*(__u16 *) & (p[9]));
break;
@@ -598,12 +564,10 @@ handle_ncp(struct sockaddr_ipx *source,
break;
case 97:
{
struct INPUT
{
struct INPUT {
__u16 proposed_max_size;
__u8 security_flag;
}
*i = (struct INPUT *) data;
} *i = (struct INPUT *) data;
printf("fn: %-3d\n", rq->function);
printf("Get Big Packet NCP Max Packet Size\n");
@@ -615,15 +579,13 @@ handle_ncp(struct sockaddr_ipx *source,
}
case 101:
{
struct INPUT
{
struct INPUT {
__u32 local_conn_id;
__u32 local_max_packet_size;
__u16 local_target_socket;
__u32 local_max_send_size;
__u32 local_max_recv_size;
}
*i = (struct INPUT *) data;
} *i = (struct INPUT *) data;
printf("fn: %-3d\n", rq->function);
printf("Packet Burst Connection Request\n");
@@ -655,23 +617,20 @@ handle_ncp(struct sockaddr_ipx *source,
workstation, and tell me whether anything
of this makes sense at all. */
switch (data[0])
{
switch (data[0]) {
case 1:
printf("Ping for NDS\n");
break;
case 2:
{
struct INPUT
{
struct INPUT {
__u8 subfunction_code;
__u32 fragger_handle;
__u32 max_fragment_size;
__u32 message_size;
__u32 fragment_flag;
__u32 verb;
}
*i = (struct INPUT *) data;
} *i = (struct INPUT *) data;
printf("Send NDS Fragment Request/Reply\n");
printf("fragger_handle: %lx\n",
(unsigned long) i->fragger_handle);
@@ -683,8 +642,7 @@ handle_ncp(struct sockaddr_ipx *source,
(unsigned long) i->fragment_flag);
printf("verb: %d\n", i->verb);
switch (i->verb)
{
switch (i->verb) {
case 1:
printf("Resolve Name\n");
break;
@@ -941,8 +899,7 @@ handle_ncp(struct sockaddr_ipx *source,
printf("fn: %-3d\n", rq->function);
}
}
if (ntohs(rs->type) == NCP_REPLY)
{
if (ntohs(rs->type) == NCP_REPLY) {
printf("NCP respons: conn: %-5d, seq: %-3d, task: %-3d, ",
rs->conn_low + 256 * rs->conn_high,
rs->sequence, rs->task);
@@ -954,25 +911,20 @@ handle_ncp(struct sockaddr_ipx *source,
if ((memcmp(&request_source, target,
sizeof(request_source)) == 0)
&& (request_header.sequence == rs->sequence))
{
switch (request_header.function)
{
&& (request_header.sequence == rs->sequence)) {
switch (request_header.function) {
case 22:
switch (request_data[2])
{
switch (request_data[2]) {
case 18:
{
struct XDATA
{
struct XDATA {
__u8 new_directory_handle;
__u8 access_rights_mask;
}
*x = (struct XDATA *) data;
} *x = (struct XDATA *) data;
printf("new_directory_handle: %x\n",
x->new_directory_handle);
x->new_directory_handle);
printf("access_rights_mask: %x\n",
x->access_rights_mask);
x->access_rights_mask);
}
break;
}
@@ -983,15 +935,13 @@ handle_ncp(struct sockaddr_ipx *source,
break;
case 97:
{
struct XDATA
{
struct XDATA {
__u16 accepted_max_size;
__u16 echo_socket;
__u8 security_flag;
}
*x = (struct XDATA *) data;
} *x = (struct XDATA *) data;
printf("accepted_max_size: %x\n",
ntohs(x->accepted_max_size));
ntohs(x->accepted_max_size));
printf("echo_socket: %x\n",
ntohs(x->echo_socket));
printf("security_flag: %x\n",
@@ -1000,55 +950,44 @@ handle_ncp(struct sockaddr_ipx *source,
break;
case 101:
{
struct XDATA
{
struct XDATA {
__u8 completion_code;
__u32 remote_target_id;
__u32 remote_max_packet_size;
}
*x = (struct XDATA *) data;
} *x = (struct XDATA *) data;
printf("completion_code: %x\n",
x->completion_code);
printf("remote_target_id: %lx\n",
ntohl(x->remote_target_id));
ntohl(x->remote_target_id));
printf("remote_max_packet_size: %lx\n",
ntohl(x->remote_max_packet_size));
ntohl(x->remote_max_packet_size));
}
break;
}
}
}
if (data == NULL)
{
if (data == NULL) {
data = buf;
data_length = length;
}
i = 0;
while (i < data_length)
{
while (i < data_length) {
int j;
for (j = i; j < i + 16; j++)
{
if (j >= data_length)
{
for (j = i; j < i + 16; j++) {
if (j >= data_length) {
printf(" ");
} else
{
} else {
printf("%-2.2X", data[j]);
}
}
printf(" ");
for (j = i; j < i + 16; j++)
{
if (j >= data_length)
{
for (j = i; j < i + 16; j++) {
if (j >= data_length) {
break;
}
if (isprint(data[j]))
{
if (isprint(data[j])) {
printf("%c", data[j]);
} else
{
} else {
printf(".");
}
}
@@ -1059,8 +998,7 @@ handle_ncp(struct sockaddr_ipx *source,
}
void
main(int argc, char *argv[])
void main(int argc, char *argv[])
{
unsigned char buf[16384];
unsigned char packet[8192];
@@ -1068,16 +1006,13 @@ main(int argc, char *argv[])
int len;
int i = 1;
while (fgets(buf, sizeof(buf), stdin) != NULL)
{
if (strlen(buf) == sizeof(buf) - 1)
{
while (fgets(buf, sizeof(buf), stdin) != NULL) {
if (strlen(buf) == sizeof(buf) - 1) {
fprintf(stderr, "line too long\n");
exit(1);
}
b = strchr(buf, ' ');
if (b == NULL)
{
if (b == NULL) {
fprintf(stderr, "illegal line format\n");
exit(1);
}
@@ -1085,11 +1020,9 @@ main(int argc, char *argv[])
b += 1;
len = 0;
while ((b[0] != '\0') && (b[1] != '\0'))
{
while ((b[0] != '\0') && (b[1] != '\0')) {
unsigned int value;
if (sscanf(b, "%2x", &value) != 1)
{
if (sscanf(b, "%2x", &value) != 1) {
fprintf(stderr, "illegal packet\n");
exit(1);
}

View File

@@ -27,8 +27,7 @@
#include <netinet/in.h>
#include "ipxutil.h"
void
ipx_fprint_node(FILE * file, IPXNode node)
void ipx_fprint_node(FILE * file, IPXNode node)
{
fprintf(file, "%02X%02X%02X%02X%02X%02X",
(unsigned char) node[0],
@@ -40,20 +39,17 @@ ipx_fprint_node(FILE * file, IPXNode node)
);
}
void
ipx_fprint_network(FILE * file, IPXNet net)
void ipx_fprint_network(FILE * file, IPXNet net)
{
fprintf(file, "%08lX", net);
}
void
ipx_fprint_port(FILE * file, IPXPort port)
void ipx_fprint_port(FILE * file, IPXPort port)
{
fprintf(file, "%04X", port);
}
void
ipx_fprint_saddr(FILE * file, struct sockaddr_ipx *sipx)
void ipx_fprint_saddr(FILE * file, struct sockaddr_ipx *sipx)
{
ipx_fprint_network(file, ntohl(sipx->sipx_network));
fprintf(file, ":");
@@ -62,66 +58,55 @@ ipx_fprint_saddr(FILE * file, struct sockaddr_ipx *sipx)
ipx_fprint_port(file, ntohs(sipx->sipx_port));
}
void
ipx_print_node(IPXNode node)
void ipx_print_node(IPXNode node)
{
ipx_fprint_node(stdout, node);
}
void
ipx_print_network(IPXNet net)
void ipx_print_network(IPXNet net)
{
ipx_fprint_network(stdout, net);
}
void
ipx_print_port(IPXPort port)
void ipx_print_port(IPXPort port)
{
ipx_fprint_port(stdout, port);
}
void
ipx_print_saddr(struct sockaddr_ipx *sipx)
void ipx_print_saddr(struct sockaddr_ipx *sipx)
{
ipx_fprint_saddr(stdout, sipx);
}
void
ipx_assign_node(IPXNode dest, IPXNode src)
void ipx_assign_node(IPXNode dest, IPXNode src)
{
memcpy(dest, src, sizeof(IPXNode));
}
int
ipx_node_equal(IPXNode n1, IPXNode n2)
int ipx_node_equal(IPXNode n1, IPXNode n2)
{
return memcmp(n1, n2, sizeof(IPXNode)) == 0;
}
int
ipx_sscanf_node(char *buf, IPXNode node)
int ipx_sscanf_node(char *buf, IPXNode node)
{
int i;
int n[6];
if ((i = sscanf(buf, "%2x%2x%2x%2x%2x%2x",
&(n[0]), &(n[1]), &(n[2]),
&(n[3]), &(n[4]), &(n[5]))) != 6)
{
&(n[3]), &(n[4]), &(n[5]))) != 6) {
return -1;
}
for (i = 0; i < 6; i++)
{
for (i = 0; i < 6; i++) {
node[i] = n[i];
}
return 0;
}
int
ipx_sscanf_net(char *buf, IPXNet * target)
int ipx_sscanf_net(char *buf, IPXNet * target)
{
if (sscanf(buf, "%8lX", target) == 1)
{
if (sscanf(buf, "%8lX", target) == 1) {
return 0;
}
return -1;

View File

@@ -1,317 +0,0 @@
/*
* ncp.h
*
* Copyright (C) 1995 by Volker Lendecke
*
*/
#ifndef _LINUX_NCP_H
#define _LINUX_NCP_H
#include <linux/types.h>
#include <linux/ipx.h>
#define NCP_PTYPE (0x11)
#define NCP_PORT (0x0451)
#define NCP_ALLOC_SLOT_REQUEST (0x1111)
#define NCP_REQUEST (0x2222)
#define NCP_DEALLOC_SLOT_REQUEST (0x5555)
struct ncp_request_header
{
__u16 type __attribute__((packed));
__u8 sequence __attribute__((packed));
__u8 conn_low __attribute__((packed));
__u8 task __attribute__((packed));
__u8 conn_high __attribute__((packed));
__u8 function __attribute__((packed));
__u8 data[0] __attribute__((packed));
};
#define NCP_REPLY (0x3333)
#define NCP_POSITIVE_ACK (0x9999)
struct ncp_reply_header
{
__u16 type __attribute__((packed));
__u8 sequence __attribute__((packed));
__u8 conn_low __attribute__((packed));
__u8 task __attribute__((packed));
__u8 conn_high __attribute__((packed));
__u8 completion_code __attribute__((packed));
__u8 connection_state __attribute__((packed));
__u8 data[0] __attribute__((packed));
};
#define NCP_BINDERY_USER (0x0001)
#define NCP_BINDERY_UGROUP (0x0002)
#define NCP_BINDERY_PQUEUE (0x0003)
#define NCP_BINDERY_FSERVER (0x0004)
#define NCP_BINDERY_NAME_LEN (48)
struct ncp_bindery_object
{
__u32 object_id;
__u16 object_type;
__u8 object_name[NCP_BINDERY_NAME_LEN];
__u8 object_flags;
__u8 object_security;
__u8 object_has_prop;
};
struct nw_property
{
__u8 value[128];
__u8 more_flag;
__u8 property_flag;
};
struct prop_net_address
{
__u32 network __attribute__((packed));
__u8 node[IPX_NODE_LEN] __attribute__((packed));
__u16 port __attribute__((packed));
};
#define NCP_VOLNAME_LEN (16)
#define NCP_NUMBER_OF_VOLUMES (64)
struct ncp_volume_info
{
__u32 total_blocks;
__u32 free_blocks;
__u32 purgeable_blocks;
__u32 not_yet_purgeable_blocks;
__u32 total_dir_entries;
__u32 available_dir_entries;
__u8 sectors_per_block;
char volume_name[NCP_VOLNAME_LEN + 1];
};
struct ncp_filesearch_info
{
__u8 volume_number;
__u16 directory_id;
__u16 sequence_no;
__u8 access_rights;
};
#define NCP_MAX_FILENAME 14
/* these define the attribute byte as seen by NCP */
#define aRONLY (1L<<0)
#define aHIDDEN (1L<<1)
#define aSYSTEM (1L<<2)
#define aEXECUTE (1L<<3)
#define aDIR (1L<<4)
#define aARCH (1L<<5)
#define AR_READ (0x01)
#define AR_WRITE (0x02)
#define AR_EXCLUSIVE (0x20)
#define NCP_FILE_ID_LEN 6
struct ncp_file_info
{
__u8 file_id[NCP_FILE_ID_LEN];
char file_name[NCP_MAX_FILENAME + 1];
__u8 file_attributes;
__u8 file_mode;
__u32 file_length;
__u16 creation_date;
__u16 access_date;
__u16 update_date;
__u16 update_time;
};
/* Defines for Name Spaces */
#define NW_NS_DOS 0
#define NW_NS_MAC 1
#define NW_NS_NFS 2
#define NW_NS_FTAM 3
#define NW_NS_OS2 4
/* Defines for ReturnInformationMask */
#define RIM_NAME (0x0001L)
#define RIM_SPACE_ALLOCATED (0x0002L)
#define RIM_ATTRIBUTES (0x0004L)
#define RIM_DATA_SIZE (0x0008L)
#define RIM_TOTAL_SIZE (0x0010L)
#define RIM_EXT_ATTR_INFO (0x0020L)
#define RIM_ARCHIVE (0x0040L)
#define RIM_MODIFY (0x0080L)
#define RIM_CREATION (0x0100L)
#define RIM_OWNING_NAMESPACE (0x0200L)
#define RIM_DIRECTORY (0x0400L)
#define RIM_RIGHTS (0x0800L)
#define RIM_ALL (0x0FFFL)
#define RIM_COMPRESSED_INFO (0x80000000L)
/* open/create modes */
#define OC_MODE_OPEN 0x01
#define OC_MODE_TRUNCATE 0x02
#define OC_MODE_REPLACE 0x02
#define OC_MODE_CREATE 0x08
/* open/create results */
#define OC_ACTION_NONE 0x00
#define OC_ACTION_OPEN 0x01
#define OC_ACTION_CREATE 0x02
#define OC_ACTION_TRUNCATE 0x04
#define OC_ACTION_REPLACE 0x04
/* access rights attributes */
#ifndef AR_READ_ONLY
#define AR_READ_ONLY 0x0001
#define AR_WRITE_ONLY 0x0002
#define AR_DENY_READ 0x0004
#define AR_DENY_WRITE 0x0008
#define AR_COMPATIBILITY 0x0010
#define AR_WRITE_THROUGH 0x0040
#define AR_OPEN_COMPRESSED 0x0100
#endif
struct nw_info_struct
{
__u32 spaceAlloc __attribute__((packed));
__u32 attributes __attribute__((packed));
__u16 flags __attribute__((packed));
__u32 dataStreamSize __attribute__((packed));
__u32 totalStreamSize __attribute__((packed));
__u16 numberOfStreams __attribute__((packed));
__u16 creationTime __attribute__((packed));
__u16 creationDate __attribute__((packed));
__u32 creatorID __attribute__((packed));
__u16 modifyTime __attribute__((packed));
__u16 modifyDate __attribute__((packed));
__u32 modifierID __attribute__((packed));
__u16 lastAccessDate __attribute__((packed));
__u16 archiveTime __attribute__((packed));
__u16 archiveDate __attribute__((packed));
__u32 archiverID __attribute__((packed));
__u16 inheritedRightsMask __attribute__((packed));
__u32 dirEntNum __attribute__((packed));
__u32 DosDirNum __attribute__((packed));
__u32 volNumber __attribute__((packed));
__u32 EADataSize __attribute__((packed));
__u32 EAKeyCount __attribute__((packed));
__u32 EAKeySize __attribute__((packed));
__u32 NSCreator __attribute__((packed));
__u8 nameLen __attribute__((packed));
__u8 entryName[256] __attribute__((packed));
};
/* modify mask - use with MODIFY_DOS_INFO structure */
#define DM_ATTRIBUTES (0x0002L)
#define DM_CREATE_DATE (0x0004L)
#define DM_CREATE_TIME (0x0008L)
#define DM_CREATOR_ID (0x0010L)
#define DM_ARCHIVE_DATE (0x0020L)
#define DM_ARCHIVE_TIME (0x0040L)
#define DM_ARCHIVER_ID (0x0080L)
#define DM_MODIFY_DATE (0x0100L)
#define DM_MODIFY_TIME (0x0200L)
#define DM_MODIFIER_ID (0x0400L)
#define DM_LAST_ACCESS_DATE (0x0800L)
#define DM_INHERITED_RIGHTS_MASK (0x1000L)
#define DM_MAXIMUM_SPACE (0x2000L)
struct nw_modify_dos_info
{
__u32 attributes __attribute__((packed));
__u16 creationDate __attribute__((packed));
__u16 creationTime __attribute__((packed));
__u32 creatorID __attribute__((packed));
__u16 modifyDate __attribute__((packed));
__u16 modifyTime __attribute__((packed));
__u32 modifierID __attribute__((packed));
__u16 archiveDate __attribute__((packed));
__u16 archiveTime __attribute__((packed));
__u32 archiverID __attribute__((packed));
__u16 lastAccessDate __attribute__((packed));
__u16 inheritanceGrantMask __attribute__((packed));
__u16 inheritanceRevokeMask __attribute__((packed));
__u32 maximumSpace __attribute__((packed));
};
struct nw_file_info
{
struct nw_info_struct i;
int opened;
int access;
__u32 server_file_handle __attribute__((packed));
__u8 open_create_action __attribute__((packed));
__u8 file_handle[6] __attribute__((packed));
};
struct nw_search_sequence
{
__u8 volNumber __attribute__((packed));
__u32 dirBase __attribute__((packed));
__u32 sequence __attribute__((packed));
};
struct nw_queue_job_entry
{
__u16 InUse __attribute__((packed));
__u32 prev __attribute__((packed));
__u32 next __attribute__((packed));
__u32 ClientStation __attribute__((packed));
__u32 ClientTask __attribute__((packed));
__u32 ClientObjectID __attribute__((packed));
__u32 TargetServerID __attribute__((packed));
__u8 TargetExecTime[6] __attribute__((packed));
__u8 JobEntryTime[6] __attribute__((packed));
__u32 JobNumber __attribute__((packed));
__u16 JobType __attribute__((packed));
__u16 JobPosition __attribute__((packed));
__u16 JobControlFlags __attribute__((packed));
__u8 FileNameLen __attribute__((packed));
char JobFileName[13] __attribute__((packed));
__u32 JobFileHandle __attribute__((packed));
__u32 ServerStation __attribute__((packed));
__u32 ServerTaskNumber __attribute__((packed));
__u32 ServerObjectID __attribute__((packed));
char JobTextDescription[50] __attribute__((packed));
char ClientRecordArea[152] __attribute__((packed));
};
struct queue_job
{
struct nw_queue_job_entry j;
__u8 file_handle[6];
};
#define QJE_OPER_HOLD 0x80
#define QJE_USER_HOLD 0x40
#define QJE_ENTRYOPEN 0x20
#define QJE_SERV_RESTART 0x10
#define QJE_SERV_AUTO 0x08
/* ClientRecordArea for print jobs */
#define KEEP_ON 0x0400
#define NO_FORM_FEED 0x0800
#define NOTIFICATION 0x1000
#define DELETE_FILE 0x2000
#define EXPAND_TABS 0x4000
#define PRINT_BANNER 0x8000
struct print_job_record
{
__u8 Version __attribute__((packed));
__u8 TabSize __attribute__((packed));
__u16 Copies __attribute__((packed));
__u16 CtrlFlags __attribute__((packed));
__u16 Lines __attribute__((packed));
__u16 Rows __attribute__((packed));
char FormName[16] __attribute__((packed));
__u8 Reserved[6] __attribute__((packed));
char BannerName[13] __attribute__((packed));
char FnameBanner[13] __attribute__((packed));
char FnameHeader[14] __attribute__((packed));
char Path[80] __attribute__((packed));
};
#endif /* _LINUX_NCP_H */

View File

@@ -1,166 +0,0 @@
/*
* ncp_fs.h
*
* Copyright (C) 1995 by Volker Lendecke
*
*/
#ifndef _LINUX_NCP_FS_H
#define _LINUX_NCP_FS_H
#include <linux/fs.h>
#include <linux/in.h>
#include <linux/types.h>
#include <linux/ncp_mount.h>
#include <linux/ncp_fs_sb.h>
#include <linux/ncp_fs_i.h>
/*
* ioctl commands
*/
struct ncp_ioctl_request
{
unsigned int function;
unsigned int size;
char *data;
};
struct ncp_fs_info
{
int version;
struct sockaddr_ipx addr;
uid_t mounted_uid;
int connection; /* Connection number the server assigned us */
int buffer_size; /* The negotiated buffer size, to be
used for read/write requests! */
int volume_number;
__u32 directory_id;
};
#define NCP_IOC_NCPREQUEST _IOR('n', 1, struct ncp_ioctl_request)
#define NCP_IOC_GETMOUNTUID _IOW('n', 2, uid_t)
#define NCP_IOC_CONN_LOGGED_IN _IO('n', 3)
#define NCP_GET_FS_INFO_VERSION (1)
#define NCP_IOC_GET_FS_INFO _IOWR('n', 4, struct ncp_fs_info)
/*
* The packet size to allocate. One page should be enough.
*/
#define NCP_PACKET_SIZE 4070
#define NCP_MAXPATHLEN 255
#define NCP_MAXNAMELEN 14
#ifdef __KERNEL__
/* The readdir cache size controls how many directory entries are
* cached.
*/
#define NCP_READDIR_CACHE_SIZE 64
#define NCP_MAX_RPC_TIMEOUT (6*HZ)
/* Guess, what 0x564c is :-) */
#define NCP_SUPER_MAGIC 0x564c
#define NCP_SBP(sb) ((struct ncp_server *)((sb)->u.generic_sbp))
#define NCP_INOP(inode) ((struct ncp_inode_info *)((inode)->u.generic_ip))
#define NCP_SERVER(inode) NCP_SBP((inode)->i_sb)
#define NCP_FINFO(inode) (&(NCP_INOP(inode)->finfo))
#define NCP_ISTRUCT(inode) (&(NCP_FINFO(inode)->i))
#ifdef DEBUG_NCP_MALLOC
#include <linux/malloc.h>
extern int ncp_malloced;
extern int ncp_current_malloced;
static inline void *
ncp_kmalloc(unsigned int size, int priority)
{
ncp_malloced += 1;
ncp_current_malloced += 1;
return kmalloc(size, priority);
}
static inline void
ncp_kfree_s(void *obj, int size)
{
ncp_current_malloced -= 1;
kfree_s(obj, size);
}
#else /* DEBUG_NCP_MALLOC */
#define ncp_kmalloc(s,p) kmalloc(s,p)
#define ncp_kfree_s(o,s) kfree_s(o,s)
#endif /* DEBUG_NCP_MALLOC */
#if DEBUG_NCP > 0
#define DPRINTK(format, args...) printk(format , ## args)
#else
#define DPRINTK(format, args...)
#endif
#if DEBUG_NCP > 1
#define DDPRINTK(format, args...) printk(format , ## args)
#else
#define DDPRINTK(format, args...)
#endif
/* linux/fs/ncpfs/file.c */
extern struct inode_operations ncp_file_inode_operations;
int ncp_make_open(struct inode *i, int right);
/* linux/fs/ncpfs/dir.c */
extern struct inode_operations ncp_dir_inode_operations;
void ncp_free_inode_info(struct ncp_inode_info *i);
void ncp_free_all_inodes(struct ncp_server *server);
void ncp_init_root(struct ncp_server *server);
int ncp_conn_logged_in(struct ncp_server *server);
int ncp_stat_root(struct ncp_server *server);
void ncp_init_dir_cache(void);
void ncp_invalid_dir_cache(struct inode *ino);
struct ncp_inode_info *ncp_find_inode(struct inode *inode);
ino_t ncp_info_ino(struct ncp_server *server, struct ncp_inode_info *info);
void ncp_invalidate_all_inodes(struct ncp_server *server);
void ncp_free_dir_cache(void);
int ncp_date_dos2unix(__u16 time, __u16 date);
void ncp_date_unix2dos(int unix_date, __u16 * time, __u16 * date);
/* linux/fs/ncpfs/ioctl.c */
int ncp_ioctl(struct inode *inode, struct file *filp,
unsigned int cmd, unsigned long arg);
/* linux/fs/ncpfs/inode.c */
struct super_block *ncp_read_super(struct super_block *sb,
void *raw_data, int silent);
void ncp_invalidate_connection(struct ncp_server *server);
int ncp_conn_is_valid(struct ncp_server *server);
/* linux/fs/ncpfs/sock.c */
int ncp_request(struct ncp_server *server, int function);
int ncp_connect(struct ncp_server *server);
int ncp_disconnect(struct ncp_server *server);
int ncp_catch_watchdog(struct ncp_server *server);
int ncp_dont_catch_watchdog(struct ncp_server *server);
void ncp_lock_server(struct ncp_server *server);
void ncp_unlock_server(struct ncp_server *server);
/* linux/fs/ncpfs/mmap.c */
int ncp_mmap(struct inode *inode, struct file *file, struct vm_area_struct *vma);
#endif /* __KERNEL__ */
#endif /* _LINUX_NCP_FS_H */

View File

@@ -1,38 +0,0 @@
/*
* ncp_fs_i.h
*
* Copyright (C) 1995 by Paal-Kr. Engstad and Volker Lendecke
*
*/
#ifndef _LINUX_NCP_FS_I
#define _LINUX_NCP_FS_I
#include <linux/ncp.h>
#ifdef __KERNEL__
enum ncp_inode_state
{
NCP_INODE_VALID = 19, /* Inode currently in use */
NCP_INODE_LOOKED_UP, /* directly before iget */
NCP_INODE_CACHED, /* in a path to an inode which is in use */
NCP_INODE_INVALID
};
/*
* ncp fs inode data (in memory only)
*/
struct ncp_inode_info
{
enum ncp_inode_state state;
int nused; /* for directories:
number of references in memory */
struct ncp_inode_info *dir;
struct ncp_inode_info *next, *prev;
struct inode *inode;
struct nw_file_info finfo;
};
#endif
#endif

View File

@@ -1,76 +0,0 @@
/*
* ncp_fs_sb.h
*
* Copyright (C) 1995 by Volker Lendecke
*
*/
#ifndef _NCP_FS_SB
#define _NCP_FS_SB
#include <linux/ncp_mount.h>
#include <linux/types.h>
#ifdef __KERNEL__
#define NCP_DEFAULT_BUFSIZE 1024
struct ncp_server
{
struct ncp_mount_data m; /* Nearly all of the mount data is of
interest for us later, so we store
it completely. */
__u8 name_space[NCP_NUMBER_OF_VOLUMES];
struct file *ncp_filp; /* File pointer to ncp socket */
struct file *wdog_filp; /* File pointer to wdog socket */
void *data_ready; /* The wdog socket gets a new
data_ready callback. We store the
old one for checking purposes and
to reset it on unmounting. */
u8 sequence;
u8 task;
u16 connection; /* Remote connection number */
u8 completion; /* Status message from server */
u8 conn_status; /* Bit 4 = 1 ==> Server going down, no
requests allowed anymore.
Bit 0 = 1 ==> Server is down. */
int buffer_size; /* Negotiated bufsize */
int reply_size; /* Size of last reply */
int packet_size;
unsigned char *packet; /* Here we prepare requests and
receive replies */
int lock; /* To prevent mismatch in protocols. */
struct wait_queue *wait;
int current_size; /* for packet preparation */
int has_subfunction;
int ncp_reply_size;
struct ncp_inode_info root;
char root_path; /* '\0' */
};
static inline int
ncp_conn_valid(struct ncp_server *server)
{
return ((server->conn_status & 0x11) == 0);
}
static inline void
ncp_invalidate_conn(struct ncp_server *server)
{
server->conn_status |= 0x01;
}
#endif /* __KERNEL__ */
#endif

View File

@@ -1,50 +0,0 @@
/*
* ncp_mount.h
*
* Copyright (C) 1995 by Volker Lendecke
*
*/
#ifndef _LINUX_NCP_MOUNT_H
#define _LINUX_NCP_MOUNT_H
#include <linux/types.h>
#include <linux/ipx.h>
#include <linux/ncp.h>
#include <linux/ncp_fs_i.h>
#define NCP_MOUNT_VERSION 2
#define NCP_USERNAME_LEN (NCP_BINDERY_NAME_LEN)
#define NCP_PASSWORD_LEN 20
/* Values for flags */
#define NCP_MOUNT_SOFT 0x0001
#define NCP_MOUNT_INTR 0x0002
struct ncp_mount_data
{
int version;
unsigned int ncp_fd; /* The socket to the ncp port */
unsigned int wdog_fd; /* Watchdog packets come here */
unsigned int message_fd; /* Message notifications come here */
uid_t mounted_uid; /* Who may umount() this filesystem? */
struct sockaddr_ipx serv_addr;
unsigned char server_name[NCP_BINDERY_NAME_LEN];
unsigned char mount_point[PATH_MAX + 1];
unsigned char mounted_vol[NCP_VOLNAME_LEN + 1];
unsigned int time_out; /* How long should I wait after
sending a NCP request? */
unsigned int retry_count; /* And how often should I retry? */
unsigned int flags;
uid_t uid;
gid_t gid;
mode_t file_mode;
mode_t dir_mode;
};
#endif

View File

@@ -1,65 +0,0 @@
#
# Makefile for the linux ncp-filesystem routines.
#
CFLAGS = -Wall -Wstrict-prototypes -O2 -DMODULE -fomit-frame-pointer \
$(INCLUDES) -DNCPFS_VERSION=\"$(VERSION)\"\
# -DDEBUG_NCP=1 -DDEBUG_NCP_MALLOC
# -DDEBUG_NCP_MALLOC
CC = gcc -D__KERNEL__ -I.
AS = as
ARCH = i386
.c.s:
$(CC) $(CFLAGS) -S $<
.c.o:
$(CC) $(CFLAGS) -c $<
.s.o:
$(AS) -o $*.o $<
OBJS= dir.o inode.o file.o sock.o ioctl.o ncplib_kernel.o mmap.o
all: $(INTERM_BINDIR)/ncpfs.o
$(INTERM_BINDIR)/ncpfs.o: $(OBJS)
$(LD) -r -o $@ $(OBJS)
ncplib_kernel.o: ncplib_kernel.c ncplib_kernel.h
$(CC) $(CFLAGS) -finline-functions -c $<
dep:
$(CPP) -M $(INCLUDES) *.c > .depend
clean:
rm -f *.o *~
realclean: clean
rm -f ncpmount ncptest .depend $(DISTFILE) *.out
modules: ncpfs.o
SRCPATH=$(shell pwd)
SRCDIR=$(shell basename $(SRCPATH))
DISTFILE=$(SRCDIR).tgz
BACKUPFILE=ncpfs01.tgz
HOME=/home/me
backup:
(rm -f $(DISTFILE); cd ..; tar cvf - $(SRCDIR) | gzip -1 \
> $(HOME)/tarz/backup/$(BACKUPFILE))
(cd $(HOME)/tarz/backup; ls -l $(BACKUPFILE); mcopy $(BACKUPFILE) a:)
dist: realclean
rm -fr mnt
(cd ..; \
tar cvf - $(SRCDIR) | \
gzip -9 > $(DISTFILE); \
mv $(DISTFILE) $(SRCDIR))
#
# include a dependency file if one exists
#
ifeq (.depend,$(wildcard .depend))
include .depend
endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,273 +0,0 @@
/*
* file.c
*
* Copyright (C) 1995 by Paal-Kr. Engstad and Volker Lendecke
*
*/
#include <linux/config.h>
#ifdef MODULE
#include <linux/module.h>
#include <linux/version.h>
#endif
#include <asm/segment.h>
#include <asm/system.h>
#include <linux/sched.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/fcntl.h>
#include <linux/stat.h>
#include <linux/mm.h>
#include <linux/ncp_fs.h>
#include <linux/locks.h>
#include "ncplib_kernel.h"
#include <linux/malloc.h>
static inline int
min(int a, int b)
{
return a < b ? a : b;
}
static int
ncp_fsync(struct inode *inode, struct file *file)
{
return 0;
}
int
ncp_make_open(struct inode *i, int right)
{
struct nw_file_info *finfo;
if (i == NULL)
{
printk("ncp_make_open: got NULL inode\n");
return -EINVAL;
}
finfo = NCP_FINFO(i);
DPRINTK("ncp_make_open: dirent->opened = %d\n", finfo->opened);
lock_super(i->i_sb);
if (finfo->opened == 0)
{
finfo->access = -1;
/* tries max. rights */
if (ncp_open_create_file_or_subdir(NCP_SERVER(i),
NULL, NULL,
OC_MODE_OPEN, 0,
AR_READ | AR_WRITE,
finfo) == 0)
{
finfo->access = O_RDWR;
} else if (ncp_open_create_file_or_subdir(NCP_SERVER(i),
NULL, NULL,
OC_MODE_OPEN, 0,
AR_READ,
finfo) == 0)
{
finfo->access = O_RDONLY;
}
}
unlock_super(i->i_sb);
if (((right == O_RDONLY) && ((finfo->access == O_RDONLY)
|| (finfo->access == O_RDWR)))
|| ((right == O_WRONLY) && ((finfo->access == O_WRONLY)
|| (finfo->access == O_RDWR)))
|| ((right == O_RDWR) && (finfo->access == O_RDWR)))
return 0;
return -EACCES;
}
static int
ncp_file_read(struct inode *inode, struct file *file, char *buf, int count)
{
int bufsize, already_read;
off_t pos;
int errno;
DPRINTK("ncp_file_read: enter %s\n", NCP_ISTRUCT(inode)->entryName);
if (inode == NULL)
{
DPRINTK("ncp_file_read: inode = NULL\n");
return -EINVAL;
}
if (!ncp_conn_valid(NCP_SERVER(inode)))
{
return -EIO;
}
if (!S_ISREG(inode->i_mode))
{
DPRINTK("ncp_file_read: read from non-file, mode %07o\n",
inode->i_mode);
return -EINVAL;
}
pos = file->f_pos;
if (pos + count > inode->i_size)
{
count = inode->i_size - pos;
}
if (count <= 0)
{
return 0;
}
if ((errno = ncp_make_open(inode, O_RDONLY)) != 0)
{
return errno;
}
bufsize = NCP_SERVER(inode)->buffer_size;
already_read = 0;
/* First read in as much as possible for each bufsize. */
while (already_read < count)
{
int read_this_time;
int to_read = min(bufsize - (pos % bufsize),
count - already_read);
if (ncp_read(NCP_SERVER(inode), NCP_FINFO(inode)->file_handle,
pos, to_read, buf, &read_this_time) != 0)
{
return -EIO; /* This is not exact, i know.. */
}
pos += read_this_time;
buf += read_this_time;
already_read += read_this_time;
if (read_this_time < to_read)
{
break;
}
}
file->f_pos = pos;
if (!IS_RDONLY(inode))
{
inode->i_atime = CURRENT_TIME;
}
inode->i_dirt = 1;
DPRINTK("ncp_file_read: exit %s\n", NCP_ISTRUCT(inode)->entryName);
return already_read;
}
static int
ncp_file_write(struct inode *inode, struct file *file, char *buf,
int count)
{
int bufsize, already_written;
off_t pos;
int errno;
if (inode == NULL)
{
DPRINTK("ncp_file_write: inode = NULL\n");
return -EINVAL;
}
if (!ncp_conn_valid(NCP_SERVER(inode)))
{
return -EIO;
}
if (!S_ISREG(inode->i_mode))
{
DPRINTK("ncp_file_write: write to non-file, mode %07o\n",
inode->i_mode);
return -EINVAL;
}
DPRINTK("ncp_file_write: enter %s\n", NCP_ISTRUCT(inode)->entryName);
if (count <= 0)
{
return 0;
}
if ((errno = ncp_make_open(inode, O_RDWR)) != 0)
{
return errno;
}
pos = file->f_pos;
if (file->f_flags & O_APPEND)
{
pos = inode->i_size;
}
bufsize = NCP_SERVER(inode)->buffer_size;
already_written = 0;
while (already_written < count)
{
int written_this_time;
int to_write = min(bufsize - (pos % bufsize),
count - already_written);
if (ncp_write(NCP_SERVER(inode), NCP_FINFO(inode)->file_handle,
pos, to_write, buf, &written_this_time) != 0)
{
return -EIO;
}
pos += written_this_time;
buf += written_this_time;
already_written += written_this_time;
if (written_this_time < to_write)
{
break;
}
}
inode->i_mtime = inode->i_ctime = CURRENT_TIME;
inode->i_dirt = 1;
file->f_pos = pos;
if (pos > inode->i_size)
{
inode->i_size = pos;
ncp_invalid_dir_cache(NCP_INOP(inode)->dir->inode);
}
DPRINTK("ncp_file_write: exit %s\n", NCP_ISTRUCT(inode)->entryName);
return already_written;
}
static struct file_operations ncp_file_operations =
{
NULL, /* lseek - default */
ncp_file_read, /* read */
ncp_file_write, /* write */
NULL, /* readdir - bad */
NULL, /* select - default */
ncp_ioctl, /* ioctl */
ncp_mmap, /* mmap */
NULL, /* open */
NULL, /* release */
ncp_fsync, /* fsync */
};
struct inode_operations ncp_file_inode_operations =
{
&ncp_file_operations, /* default file operations */
NULL, /* create */
NULL, /* lookup */
NULL, /* link */
NULL, /* unlink */
NULL, /* symlink */
NULL, /* mkdir */
NULL, /* rmdir */
NULL, /* mknod */
NULL, /* rename */
NULL, /* readlink */
NULL, /* follow_link */
NULL, /* bmap */
NULL /* truncate */
};

View File

@@ -1,493 +0,0 @@
/*
* inode.c
*
* Copyright (C) 1995 by Volker Lendecke
*
*/
#include <linux/config.h>
#ifdef MODULE
#include <linux/module.h>
#include <linux/version.h>
#else
#define MOD_INC_USE_COUNT
#define MOD_DEC_USE_COUNT
#endif
#include <asm/system.h>
#include <asm/segment.h>
#include <linux/sched.h>
#include <linux/ncp_fs.h>
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/string.h>
#include <linux/stat.h>
#include <linux/errno.h>
#include <linux/locks.h>
#include <linux/fcntl.h>
#include <linux/malloc.h>
#include "ncplib_kernel.h"
extern int close_fp(struct file *filp);
static void ncp_put_inode(struct inode *);
static void ncp_read_inode(struct inode *);
static void ncp_put_super(struct super_block *);
static void ncp_statfs(struct super_block *sb, struct statfs *stat);
static int ncp_notify_change(struct inode *inode, struct iattr *attr);
static struct super_operations ncp_sops =
{
ncp_read_inode, /* read inode */
ncp_notify_change, /* notify change */
NULL, /* write inode */
ncp_put_inode, /* put inode */
ncp_put_super, /* put superblock */
NULL, /* write superblock */
ncp_statfs, /* stat filesystem */
NULL
};
/* ncp_read_inode: Called from iget, it only traverses the allocated
ncp_inode_info's and initializes the inode from the data found
there. It does not allocate or deallocate anything. */
static void
ncp_read_inode(struct inode *inode)
{
/* Our task should be extremely simple here. We only have to
look up the infomation somebody else (ncp_iget) put into
the inode tree. The address of this information is the
inode->i_ino. Just to make sure everything went well, we
check it's there. */
struct ncp_inode_info *inode_info = ncp_find_inode(inode);
if (inode_info == NULL)
{
/* Ok, now we're in trouble. The inode info is not there. What
should we do now??? */
printk("ncp_read_inode: inode info not found\n");
return;
}
inode_info->state = NCP_INODE_VALID;
NCP_INOP(inode) = inode_info;
inode_info->inode = inode;
if (NCP_ISTRUCT(inode)->attributes & aDIR)
{
inode->i_mode = NCP_SERVER(inode)->m.dir_mode;
/* for directories dataStreamSize seems to be some
Object ID ??? */
inode->i_size = 512;
} else
{
inode->i_mode = NCP_SERVER(inode)->m.file_mode;
inode->i_size = NCP_ISTRUCT(inode)->dataStreamSize;
}
DDPRINTK("ncp_read_inode: inode->i_mode = %u\n", inode->i_mode);
inode->i_nlink = 1;
inode->i_uid = NCP_SERVER(inode)->m.uid;
inode->i_gid = NCP_SERVER(inode)->m.gid;
inode->i_blksize = 512;
inode->i_rdev = 0;
if ((inode->i_blksize != 0) && (inode->i_size != 0))
{
inode->i_blocks =
(inode->i_size - 1) / inode->i_blksize + 1;
} else
{
inode->i_blocks = 0;
}
inode->i_mtime = ncp_date_dos2unix(NCP_ISTRUCT(inode)->modifyTime,
NCP_ISTRUCT(inode)->modifyDate);
inode->i_ctime = ncp_date_dos2unix(NCP_ISTRUCT(inode)->creationTime,
NCP_ISTRUCT(inode)->creationDate);
inode->i_atime = ncp_date_dos2unix(0,
NCP_ISTRUCT(inode)->lastAccessDate);
if (S_ISREG(inode->i_mode))
{
inode->i_op = &ncp_file_inode_operations;
} else if (S_ISDIR(inode->i_mode))
{
inode->i_op = &ncp_dir_inode_operations;
} else
{
inode->i_op = NULL;
}
}
static void
ncp_put_inode(struct inode *inode)
{
struct nw_file_info *finfo = NCP_FINFO(inode);
struct super_block *sb = inode->i_sb;
lock_super(sb);
if (finfo->opened != 0)
{
if (ncp_close_file(NCP_SERVER(inode), finfo->file_handle) != 0)
{
/* We can't do anything but complain. */
printk("ncp_put_inode: could not close\n");
}
}
DDPRINTK("ncp_put_inode: put %s\n",
finfo->i.entryName);
ncp_free_inode_info(NCP_INOP(inode));
if (S_ISDIR(inode->i_mode))
{
DDPRINTK("ncp_put_inode: put directory %ld\n",
inode->i_ino);
ncp_invalid_dir_cache(inode);
}
clear_inode(inode);
unlock_super(sb);
}
struct super_block *
ncp_read_super(struct super_block *sb, void *raw_data, int silent)
{
struct ncp_mount_data *data = (struct ncp_mount_data *) raw_data;
struct ncp_server *server;
struct file *ncp_filp;
struct file *wdog_filp;
dev_t dev = sb->s_dev;
int error;
if (data == NULL)
{
printk("ncp_read_super: missing data argument\n");
sb->s_dev = 0;
return NULL;
}
if (data->version != NCP_MOUNT_VERSION)
{
printk("ncp warning: mount version %s than kernel\n",
(data->version < NCP_MOUNT_VERSION) ?
"older" : "newer");
sb->s_dev = 0;
return NULL;
}
if ((data->ncp_fd >= NR_OPEN)
|| ((ncp_filp = current->files->fd[data->ncp_fd]) == NULL)
|| (!S_ISSOCK(ncp_filp->f_inode->i_mode)))
{
printk("ncp_read_super: invalid ncp socket\n");
sb->s_dev = 0;
return NULL;
}
if ((data->wdog_fd >= NR_OPEN)
|| ((wdog_filp = current->files->fd[data->wdog_fd]) == NULL)
|| (!S_ISSOCK(wdog_filp->f_inode->i_mode)))
{
printk("ncp_read_super: invalid wdog socket\n");
sb->s_dev = 0;
return NULL;
}
/* We must malloc our own super-block info */
server = (struct ncp_server *) ncp_kmalloc(sizeof(struct ncp_server),
GFP_KERNEL);
if (server == NULL)
{
printk("ncp_read_super: could not alloc ncp_server\n");
return NULL;
}
ncp_filp->f_count += 1;
wdog_filp->f_count += 1;
lock_super(sb);
NCP_SBP(sb) = server;
sb->s_blocksize = 1024; /* Eh... Is this correct? */
sb->s_blocksize_bits = 10;
sb->s_magic = NCP_SUPER_MAGIC;
sb->s_dev = dev;
sb->s_op = &ncp_sops;
server->ncp_filp = ncp_filp;
server->wdog_filp = wdog_filp;
server->lock = 0;
server->wait = NULL;
server->packet = NULL;
server->buffer_size = 0;
server->conn_status = 0;
server->m = *data;
server->m.file_mode = (server->m.file_mode &
(S_IRWXU | S_IRWXG | S_IRWXO)) | S_IFREG;
server->m.dir_mode = (server->m.dir_mode &
(S_IRWXU | S_IRWXG | S_IRWXO)) | S_IFDIR;
server->packet_size = NCP_PACKET_SIZE;
server->packet = ncp_kmalloc(NCP_PACKET_SIZE, GFP_KERNEL);
if (server->packet == NULL)
{
printk("ncpfs: could not alloc packet\n");
error = -ENOMEM;
unlock_super(sb);
goto fail;
}
ncp_init_root(server);
/*
* Make the connection to the server
*/
if (ncp_catch_watchdog(server) != 0)
{
printk("ncp_read_super: Could not catch watchdog\n");
error = -EINVAL;
unlock_super(sb);
goto fail;
}
ncp_lock_server(server);
error = ncp_connect(server);
ncp_unlock_server(server);
unlock_super(sb);
if (error < 0)
{
sb->s_dev = 0;
printk("ncp_read_super: Failed connection, bailing out "
"(error = %d).\n", -error);
ncp_kfree_s(server->packet, server->packet_size);
ncp_dont_catch_watchdog(server);
goto fail;
}
DPRINTK("ncp_read_super: NCP_SBP(sb) = %x\n", (int) NCP_SBP(sb));
if (!(sb->s_mounted = iget(sb, ncp_info_ino(server, &(server->root)))))
{
sb->s_dev = 0;
printk("ncp_read_super: get root inode failed\n");
goto disconnect;
}
if (ncp_negotiate_buffersize(server, NCP_DEFAULT_BUFSIZE,
&(server->buffer_size)) != 0)
{
sb->s_dev = 0;
printk("ncp_read_super: could not get bufsize\n");
goto disconnect;
}
DPRINTK("ncpfs: bufsize = %d\n", server->buffer_size);
MOD_INC_USE_COUNT;
return sb;
disconnect:
ncp_lock_server(server);
ncp_disconnect(server);
ncp_unlock_server(server);
ncp_kfree_s(server->packet, server->packet_size);
ncp_dont_catch_watchdog(server);
fail:
ncp_filp->f_count -= 1;
wdog_filp->f_count -= 1;
ncp_kfree_s(NCP_SBP(sb), sizeof(struct ncp_server));
return NULL;
}
static void
ncp_put_super(struct super_block *sb)
{
struct ncp_server *server = NCP_SBP(sb);
lock_super(sb);
ncp_lock_server(server);
ncp_disconnect(server);
ncp_unlock_server(server);
close_fp(server->ncp_filp);
ncp_dont_catch_watchdog(server);
close_fp(server->wdog_filp);
ncp_free_all_inodes(server);
ncp_kfree_s(server->packet, server->packet_size);
sb->s_dev = 0;
ncp_kfree_s(NCP_SBP(sb), sizeof(struct ncp_server));
NCP_SBP(sb) = NULL;
unlock_super(sb);
MOD_DEC_USE_COUNT;
}
static void
ncp_statfs(struct super_block *sb, struct statfs *stat)
{
struct statfs tmp;
/* We cannot say how much disk space is left on a mounted
NetWare Server, because free space is distributed over
volumes, and the current user might have disk quotas. So
free space is not that simple to determine. Our decision
here is to err conservatively. */
tmp.f_type = NCP_SUPER_MAGIC;
tmp.f_bsize = 512;
tmp.f_blocks = 0;
tmp.f_bfree = 0;
tmp.f_bavail = 0;
tmp.f_files = -1;
tmp.f_ffree = -1;
tmp.f_namelen = 12;
memcpy_tofs(stat, &tmp, sizeof(tmp));
}
static int
ncp_notify_change(struct inode *inode, struct iattr *attr)
{
int result = 0;
int info_mask;
struct nw_modify_dos_info info;
if (!ncp_conn_valid(NCP_SERVER(inode)))
{
return -EIO;
}
if ((result = inode_change_ok(inode, attr)) < 0)
return result;
if (((attr->ia_valid & ATTR_UID) &&
(attr->ia_uid != NCP_SERVER(inode)->m.uid)))
return -EPERM;
if (((attr->ia_valid & ATTR_GID) &&
(attr->ia_uid != NCP_SERVER(inode)->m.gid)))
return -EPERM;
if (((attr->ia_valid & ATTR_MODE) &&
(attr->ia_mode &
~(S_IFREG | S_IFDIR | S_IRWXU | S_IRWXG | S_IRWXO))))
return -EPERM;
info_mask = 0;
memset(&info, 0, sizeof(info));
if ((attr->ia_valid & ATTR_CTIME) != 0)
{
info_mask |= (DM_CREATE_TIME | DM_CREATE_DATE);
ncp_date_unix2dos(attr->ia_ctime,
&(info.creationTime), &(info.creationDate));
}
if ((attr->ia_valid & ATTR_MTIME) != 0)
{
info_mask |= (DM_MODIFY_TIME | DM_MODIFY_DATE);
ncp_date_unix2dos(attr->ia_mtime,
&(info.modifyTime), &(info.modifyDate));
}
if ((attr->ia_valid & ATTR_ATIME) != 0)
{
__u16 dummy;
info_mask |= (DM_LAST_ACCESS_DATE);
ncp_date_unix2dos(attr->ia_ctime,
&(dummy), &(info.lastAccessDate));
}
if (info_mask != 0)
{
if ((result =
ncp_modify_file_or_subdir_dos_info(NCP_SERVER(inode),
NCP_ISTRUCT(inode),
info_mask,
&info)) != 0)
{
result = -EACCES;
if (info_mask == (DM_CREATE_TIME | DM_CREATE_DATE))
{
/* NetWare seems not to allow this. I
do not know why. So, just tell the
user everything went fine. This is
a terrible hack, but I do not know
how to do this correctly. */
result = 0;
}
}
}
if ((attr->ia_valid & ATTR_SIZE) != 0)
{
int written;
DPRINTK("ncpfs: trying to change size of %s to %ld\n",
NCP_ISTRUCT(inode)->entryName, attr->ia_size);
if ((result = ncp_make_open(inode, O_RDWR)) < 0)
{
return -EACCES;
}
ncp_write(NCP_SERVER(inode), NCP_FINFO(inode)->file_handle,
attr->ia_size, 0, "", &written);
/* According to ndir, the changes only take effect after
closing the file */
ncp_close_file(NCP_SERVER(inode),
NCP_FINFO(inode)->file_handle);
NCP_FINFO(inode)->opened = 0;
result = 0;
}
ncp_invalid_dir_cache(NCP_INOP(inode)->dir->inode);
return result;
}
#ifdef DEBUG_NCP_MALLOC
int ncp_malloced;
int ncp_current_malloced;
#endif
#ifdef MODULE
char kernel_version[] = UTS_RELEASE;
static struct file_system_type ncp_fs_type =
{
ncp_read_super, "ncpfs", 0, NULL
};
int
init_module(void)
{
DPRINTK("ncpfs: init_module called\n");
#ifdef DEBUG_NCP_MALLOC
ncp_malloced = 0;
ncp_current_malloced = 0;
#endif
ncp_init_dir_cache();
register_filesystem(&ncp_fs_type);
printk("ncpfs version %s loaded\n", NCPFS_VERSION);
return 0;
}
void
cleanup_module(void)
{
DPRINTK("ncpfs: cleanup_module called\n");
ncp_free_dir_cache();
unregister_filesystem(&ncp_fs_type);
#ifdef DEBUG_NCP_MALLOC
printk("ncp_malloced: %d\n", ncp_malloced);
printk("ncp_current_malloced: %d\n", ncp_current_malloced);
#endif
}
#endif

View File

@@ -1,159 +0,0 @@
/*
* ioctl.c
*
* Copyright (C) 1995 by Volker Lendecke
*
*/
#include <linux/config.h>
#ifdef MODULE
#include <linux/module.h>
#include <linux/version.h>
#endif
#include <asm/segment.h>
#include <linux/errno.h>
#include <linux/fs.h>
#include <linux/ncp_fs.h>
#include <linux/ioctl.h>
#include <linux/sched.h>
#include <linux/mm.h>
#include <linux/ncp.h>
int
ncp_ioctl(struct inode *inode, struct file *filp,
unsigned int cmd, unsigned long arg)
{
int result;
struct ncp_ioctl_request request;
struct ncp_fs_info info;
struct ncp_server *server = NCP_SERVER(inode);
/*
* Binary compatible with 1.3.XX releases.
* Take this out in 2.1.0 development series.
* <mec@duracef.shout.net> 12 Mar 1996
*/
switch (cmd)
{
case _IOR('n', 1, unsigned char *):
cmd = NCP_IOC_NCPREQUEST;
break;
case _IOR('u', 1, uid_t):
cmd = NCP_IOC_GETMOUNTUID;
break;
case _IO('l', 1):
cmd = NCP_IOC_CONN_LOGGED_IN;
break;
case _IOWR('i', 1, unsigned char *):
cmd = NCP_IOC_GET_FS_INFO;
break;
}
switch (cmd)
{
case NCP_IOC_NCPREQUEST:
if ((permission(inode, MAY_WRITE) != 0)
&& (current->uid != server->m.mounted_uid))
{
return -EACCES;
}
if ((result = verify_area(VERIFY_READ, (char *) arg,
sizeof(request))) != 0)
{
return result;
}
memcpy_fromfs(&request, (struct ncp_ioctl_request *) arg,
sizeof(request));
if ((request.function > 255)
|| (request.size >
NCP_PACKET_SIZE - sizeof(struct ncp_request_header)))
{
return -EINVAL;
}
if ((result = verify_area(VERIFY_WRITE, (char *) request.data,
NCP_PACKET_SIZE)) != 0)
{
return result;
}
ncp_lock_server(server);
/* FIXME: We hack around in the server's structures
here to be able to use ncp_request */
server->has_subfunction = 0;
server->current_size = request.size;
memcpy_fromfs(server->packet, request.data, request.size);
ncp_request(server, request.function);
DPRINTK("ncp_ioctl: copy %d bytes\n",
server->reply_size);
memcpy_tofs(request.data, server->packet, server->reply_size);
ncp_unlock_server(server);
return server->reply_size;
case NCP_IOC_CONN_LOGGED_IN:
if ((permission(inode, MAY_WRITE) != 0)
&& (current->uid != server->m.mounted_uid))
{
return -EACCES;
}
return ncp_conn_logged_in(server);
case NCP_IOC_GET_FS_INFO:
if ((permission(inode, MAY_WRITE) != 0)
&& (current->uid != server->m.mounted_uid))
{
return -EACCES;
}
if ((result = verify_area(VERIFY_WRITE, (char *) arg,
sizeof(info))) != 0)
{
return result;
}
memcpy_fromfs(&info, (struct ncp_fs_info *) arg,
sizeof(info));
if (info.version != NCP_GET_FS_INFO_VERSION)
{
DPRINTK("info.version invalid: %d\n", info.version);
return -EINVAL;
}
info.addr = server->m.serv_addr;
info.mounted_uid = server->m.mounted_uid;
info.connection = server->connection;
info.buffer_size = server->buffer_size;
info.volume_number = NCP_ISTRUCT(inode)->volNumber;
info.directory_id = NCP_ISTRUCT(inode)->DosDirNum;
memcpy_tofs((struct ncp_fs_info *) arg, &info, sizeof(info));
return 0;
case NCP_IOC_GETMOUNTUID:
if ((permission(inode, MAY_READ) != 0)
&& (current->uid != server->m.mounted_uid))
{
return -EACCES;
}
if ((result = verify_area(VERIFY_WRITE, (uid_t *) arg,
sizeof(uid_t))) != 0)
{
return result;
}
put_fs_word(server->m.mounted_uid, (uid_t *) arg);
return 0;
default:
return -EINVAL;
}
return -EINVAL;
}

View File

@@ -1,155 +0,0 @@
/*
* mmap.c
*
* Copyright (C) 1995 by Volker Lendecke
*
*/
#include <linux/config.h>
#ifdef MODULE
#include <linux/module.h>
#include <linux/version.h>
#endif
#include <linux/stat.h>
#include <linux/sched.h>
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/shm.h>
#include <linux/errno.h>
#include <linux/mman.h>
#include <linux/string.h>
#include <linux/malloc.h>
#include <linux/fcntl.h>
#include <linux/ncp_fs.h>
#include "ncplib_kernel.h"
#include <asm/segment.h>
#include <asm/system.h>
static inline int
min(int a, int b)
{
return a < b ? a : b;
}
/*
* Fill in the supplied page for mmap
*/
static unsigned long
ncp_file_mmap_nopage(struct vm_area_struct *area,
unsigned long address, unsigned long page, int no_share)
{
struct inode *inode = area->vm_inode;
unsigned int clear;
unsigned long tmp;
int bufsize;
int pos;
unsigned short fs;
address &= PAGE_MASK;
pos = address - area->vm_start + area->vm_offset;
clear = 0;
if (address + PAGE_SIZE > area->vm_end)
{
clear = address + PAGE_SIZE - area->vm_end;
}
/* what we can read in one go */
bufsize = NCP_SERVER(inode)->buffer_size;
fs = get_fs();
set_fs(get_ds());
if (ncp_make_open(inode, O_RDONLY) < 0)
{
clear = PAGE_SIZE;
} else
{
int already_read = 0;
int count = PAGE_SIZE - clear;
int to_read;
while (already_read < count)
{
int read_this_time;
if ((pos % bufsize) != 0)
{
to_read = bufsize - (pos % bufsize);
} else
{
to_read = bufsize;
}
to_read = min(to_read, count - already_read);
if (ncp_read(NCP_SERVER(inode),
NCP_FINFO(inode)->file_handle,
pos, to_read,
(char *) (page + already_read),
&read_this_time) != 0)
{
read_this_time = 0;
}
pos += read_this_time;
already_read += read_this_time;
if (read_this_time < to_read)
{
break;
}
}
}
set_fs(fs);
tmp = page + PAGE_SIZE;
while (clear--)
{
*(char *) --tmp = 0;
}
return page;
}
struct vm_operations_struct ncp_file_mmap =
{
NULL, /* open */
NULL, /* close */
NULL, /* unmap */
NULL, /* protect */
NULL, /* sync */
NULL, /* advise */
ncp_file_mmap_nopage, /* nopage */
NULL, /* wppage */
NULL, /* swapout */
NULL, /* swapin */
};
/* This is used for a general mmap of a ncp file */
int
ncp_mmap(struct inode *inode, struct file *file, struct vm_area_struct *vma)
{
DPRINTK("ncp_mmap: called\n");
if (!ncp_conn_valid(NCP_SERVER(inode)))
{
return -EIO;
}
/* only PAGE_COW or read-only supported now */
if (vma->vm_flags & VM_SHARED)
return -EINVAL;
if (!inode->i_sb || !S_ISREG(inode->i_mode))
return -EACCES;
if (!IS_RDONLY(inode))
{
inode->i_atime = CURRENT_TIME;
inode->i_dirt = 1;
}
vma->vm_inode = inode;
inode->i_count++;
vma->vm_ops = &ncp_file_mmap;
return 0;
}

View File

@@ -1,622 +0,0 @@
#include <linux/config.h>
#ifdef MODULE
#include <linux/module.h>
#include <linux/version.h>
#endif
#include "ncplib_kernel.h"
typedef __u8 byte;
typedef __u16 word;
typedef __u32 dword;
static inline int
min(int a, int b)
{
return a < b ? a : b;
}
static void
assert_server_locked(struct ncp_server *server)
{
if (server->lock == 0)
{
DPRINTK("ncpfs: server not locked!\n");
}
}
static void
ncp_add_byte(struct ncp_server *server, byte x)
{
assert_server_locked(server);
*(byte *) (&(server->packet[server->current_size])) = x;
server->current_size += 1;
return;
}
static void
ncp_add_word(struct ncp_server *server, word x)
{
assert_server_locked(server);
*(word *) (&(server->packet[server->current_size])) = x;
server->current_size += 2;
return;
}
static void
ncp_add_dword(struct ncp_server *server, dword x)
{
assert_server_locked(server);
*(dword *) (&(server->packet[server->current_size])) = x;
server->current_size += 4;
return;
}
static void
ncp_add_mem(struct ncp_server *server, const void *source, int size)
{
assert_server_locked(server);
memcpy(&(server->packet[server->current_size]), source, size);
server->current_size += size;
return;
}
static void
ncp_add_mem_fromfs(struct ncp_server *server, const char *source, int size)
{
assert_server_locked(server);
memcpy_fromfs(&(server->packet[server->current_size]), source, size);
server->current_size += size;
return;
}
static void
ncp_add_pstring(struct ncp_server *server, const char *s)
{
int len = strlen(s);
assert_server_locked(server);
if (len > 255)
{
DPRINTK("ncpfs: string too long: %s\n", s);
len = 255;
}
ncp_add_byte(server, len);
ncp_add_mem(server, s, len);
return;
}
static void
ncp_init_request(struct ncp_server *server)
{
ncp_lock_server(server);
server->current_size = sizeof(struct ncp_request_header);
server->has_subfunction = 0;
}
static void
ncp_init_request_s(struct ncp_server *server, int subfunction)
{
ncp_init_request(server);
ncp_add_word(server, 0); /* preliminary size */
ncp_add_byte(server, subfunction);
server->has_subfunction = 1;
}
static char *
ncp_reply_data(struct ncp_server *server, int offset)
{
return &(server->packet[sizeof(struct ncp_reply_header) + offset]);
}
static byte
ncp_reply_byte(struct ncp_server *server, int offset)
{
return *(byte *) (ncp_reply_data(server, offset));
}
static word
ncp_reply_word(struct ncp_server *server, int offset)
{
return *(word *) (ncp_reply_data(server, offset));
}
static dword
ncp_reply_dword(struct ncp_server *server, int offset)
{
return *(dword *) (ncp_reply_data(server, offset));
}
int
ncp_negotiate_buffersize(struct ncp_server *server,
int size, int *target)
{
int result;
ncp_init_request(server);
ncp_add_word(server, htons(size));
if ((result = ncp_request(server, 33)) != 0)
{
ncp_unlock_server(server);
return result;
}
*target = min(ntohs(ncp_reply_word(server, 0)), size);
ncp_unlock_server(server);
return 0;
}
int
ncp_get_volume_info_with_number(struct ncp_server *server, int n,
struct ncp_volume_info *target)
{
int result;
int len;
ncp_init_request_s(server, 44);
ncp_add_byte(server, n);
if ((result = ncp_request(server, 22)) != 0)
{
ncp_unlock_server(server);
return result;
}
target->total_blocks = ncp_reply_dword(server, 0);
target->free_blocks = ncp_reply_dword(server, 4);
target->purgeable_blocks = ncp_reply_dword(server, 8);
target->not_yet_purgeable_blocks = ncp_reply_dword(server, 12);
target->total_dir_entries = ncp_reply_dword(server, 16);
target->available_dir_entries = ncp_reply_dword(server, 20);
target->sectors_per_block = ncp_reply_byte(server, 28);
memset(&(target->volume_name), 0, sizeof(target->volume_name));
len = ncp_reply_byte(server, 29);
if (len > NCP_VOLNAME_LEN)
{
DPRINTK("ncpfs: volume name too long: %d\n", len);
ncp_unlock_server(server);
return -EIO;
}
memcpy(&(target->volume_name), ncp_reply_data(server, 30), len);
ncp_unlock_server(server);
return 0;
}
int
ncp_close_file(struct ncp_server *server, const char *file_id)
{
int result;
ncp_init_request(server);
ncp_add_byte(server, 0);
ncp_add_mem(server, file_id, 6);
if ((result = ncp_request(server, 66)) != 0)
{
ncp_unlock_server(server);
return result;
}
ncp_unlock_server(server);
return 0;
}
static void
ncp_add_handle_path(struct ncp_server *server,
__u8 vol_num,
__u32 dir_base, int have_dir_base,
char *path)
{
ncp_add_byte(server, vol_num);
ncp_add_dword(server, dir_base);
if (have_dir_base != 0)
{
ncp_add_byte(server, 1); /* dir_base */
} else
{
ncp_add_byte(server, 0xff); /* no handle */
}
if (path != NULL)
{
ncp_add_byte(server, 1); /* 1 component */
ncp_add_pstring(server, path);
} else
{
ncp_add_byte(server, 0);
}
}
static void
ncp_extract_file_info(void *structure, struct nw_info_struct *target)
{
__u8 *name_len;
const int info_struct_size = sizeof(struct nw_info_struct) - 257;
memcpy(target, structure, info_struct_size);
name_len = structure + info_struct_size;
target->nameLen = *name_len;
strncpy(target->entryName, name_len + 1, *name_len);
target->entryName[*name_len] = '\0';
return;
}
int
ncp_obtain_info(struct ncp_server *server,
__u8 vol_num, __u32 dir_base,
char *path, /* At most 1 component */
struct nw_info_struct *target)
{
int result;
if (target == NULL)
{
return -EINVAL;
}
ncp_init_request(server);
ncp_add_byte(server, 6); /* subfunction */
ncp_add_byte(server, server->name_space[vol_num]);
ncp_add_byte(server, server->name_space[vol_num]);
ncp_add_word(server, 0xff); /* get all */
ncp_add_dword(server, RIM_ALL);
ncp_add_handle_path(server, vol_num, dir_base, 1, path);
if ((result = ncp_request(server, 87)) != 0)
{
ncp_unlock_server(server);
return result;
}
ncp_extract_file_info(ncp_reply_data(server, 0), target);
ncp_unlock_server(server);
return 0;
}
static inline int
ncp_has_os2_namespace(struct ncp_server *server, __u8 volume)
{
int result;
__u8 *namespace;
__u16 no_namespaces;
ncp_init_request(server);
ncp_add_byte(server, 24); /* Subfunction: Get Name Spaces Loaded */
ncp_add_word(server, 0);
ncp_add_byte(server, volume);
if ((result = ncp_request(server, 87)) != 0)
{
ncp_unlock_server(server);
return 0;
}
no_namespaces = ncp_reply_word(server, 0);
namespace = ncp_reply_data(server, 2);
while (no_namespaces > 0)
{
DPRINTK("get_namespaces: found %d on %d\n", *namespace, volume);
if (*namespace == 4)
{
DPRINTK("get_namespaces: found OS2\n");
ncp_unlock_server(server);
return 1;
}
namespace += 1;
no_namespaces -= 1;
}
ncp_unlock_server(server);
return 0;
}
int
ncp_lookup_volume(struct ncp_server *server,
char *volname,
struct nw_info_struct *target)
{
int result;
int volnum;
DPRINTK("ncp_lookup_volume: looking up vol %s\n", volname);
ncp_init_request(server);
ncp_add_byte(server, 22); /* Subfunction: Generate dir handle */
ncp_add_byte(server, 0); /* DOS namespace */
ncp_add_byte(server, 0); /* reserved */
ncp_add_byte(server, 0); /* reserved */
ncp_add_byte(server, 0); /* reserved */
ncp_add_byte(server, 0); /* faked volume number */
ncp_add_dword(server, 0); /* faked dir_base */
ncp_add_byte(server, 0xff); /* Don't have a dir_base */
ncp_add_byte(server, 1); /* 1 path component */
ncp_add_pstring(server, volname);
if ((result = ncp_request(server, 87)) != 0)
{
ncp_unlock_server(server);
return result;
}
memset(target, 0, sizeof(*target));
target->DosDirNum = target->dirEntNum = ncp_reply_dword(server, 4);
target->volNumber = volnum = ncp_reply_byte(server, 8);
ncp_unlock_server(server);
server->name_space[volnum] = ncp_has_os2_namespace(server, volnum) ? 4 : 0;
DPRINTK("lookup_vol: namespace[%d] = %d\n",
volnum, server->name_space[volnum]);
target->nameLen = strlen(volname);
strcpy(target->entryName, volname);
target->attributes = aDIR;
return 0;
}
int
ncp_modify_file_or_subdir_dos_info(struct ncp_server *server,
struct nw_info_struct *file,
__u32 info_mask,
struct nw_modify_dos_info *info)
{
int result;
ncp_init_request(server);
ncp_add_byte(server, 7); /* subfunction */
ncp_add_byte(server, server->name_space[file->volNumber]);
ncp_add_byte(server, 0); /* reserved */
ncp_add_word(server, 0x8006); /* search attribs: all */
ncp_add_dword(server, info_mask);
ncp_add_mem(server, info, sizeof(*info));
ncp_add_handle_path(server, file->volNumber,
file->dirEntNum, 1, NULL);
if ((result = ncp_request(server, 87)) != 0)
{
ncp_unlock_server(server);
return result;
}
ncp_unlock_server(server);
return 0;
}
int
ncp_del_file_or_subdir(struct ncp_server *server,
struct nw_info_struct *dir, char *name)
{
int result;
ncp_init_request(server);
ncp_add_byte(server, 8); /* subfunction */
ncp_add_byte(server, server->name_space[dir->volNumber]);
ncp_add_byte(server, 0); /* reserved */
ncp_add_word(server, 0x8006); /* search attribs: all */
ncp_add_handle_path(server, dir->volNumber,
dir->dirEntNum, 1, name);
if ((result = ncp_request(server, 87)) != 0)
{
ncp_unlock_server(server);
return result;
}
ncp_unlock_server(server);
return 0;
}
static inline void
ConvertToNWfromDWORD(__u32 sfd, __u8 ret[6])
{
__u16 *dest = (__u16 *) ret;
memcpy(&(dest[1]), &sfd, 4);
dest[0] = dest[1] + 1;
return;
}
/* If both dir and name are NULL, then in target there's already a
looked-up entry that wants to be opened. */
int
ncp_open_create_file_or_subdir(struct ncp_server *server,
struct nw_info_struct *dir, char *name,
int open_create_mode,
__u32 create_attributes,
int desired_acc_rights,
struct nw_file_info *target)
{
int result;
__u16 search_attribs = 0x0006;
__u8 volume = (dir != NULL) ? dir->volNumber : target->i.volNumber;
if ((create_attributes & aDIR) != 0)
{
search_attribs |= 0x8000;
}
ncp_init_request(server);
ncp_add_byte(server, 1); /* subfunction */
ncp_add_byte(server, server->name_space[volume]);
ncp_add_byte(server, open_create_mode);
ncp_add_word(server, search_attribs);
ncp_add_dword(server, RIM_ALL);
ncp_add_dword(server, create_attributes);
/* The desired acc rights seem to be the inherited rights mask
for directories */
ncp_add_word(server, desired_acc_rights);
if (dir != NULL)
{
ncp_add_handle_path(server, volume, dir->dirEntNum, 1, name);
} else
{
ncp_add_handle_path(server, volume, target->i.dirEntNum,
1, NULL);
}
if ((result = ncp_request(server, 87)) != 0)
{
ncp_unlock_server(server);
return result;
}
target->opened = 1;
target->server_file_handle = ncp_reply_dword(server, 0);
target->open_create_action = ncp_reply_byte(server, 4);
if (dir != NULL)
{
/* in target there's a new finfo to fill */
ncp_extract_file_info(ncp_reply_data(server, 5), &(target->i));
}
ConvertToNWfromDWORD(target->server_file_handle, target->file_handle);
ncp_unlock_server(server);
return 0;
}
int
ncp_initialize_search(struct ncp_server *server,
struct nw_info_struct *dir,
struct nw_search_sequence *target)
{
int result;
ncp_init_request(server);
ncp_add_byte(server, 2); /* subfunction */
ncp_add_byte(server, server->name_space[dir->volNumber]);
ncp_add_byte(server, 0); /* reserved */
ncp_add_handle_path(server, dir->volNumber, dir->dirEntNum, 1, NULL);
if ((result = ncp_request(server, 87)) != 0)
{
ncp_unlock_server(server);
return result;
}
memcpy(target, ncp_reply_data(server, 0), sizeof(*target));
ncp_unlock_server(server);
return 0;
}
/* Search for everything */
int
ncp_search_for_file_or_subdir(struct ncp_server *server,
struct nw_search_sequence *seq,
struct nw_info_struct *target)
{
int result;
ncp_init_request(server);
ncp_add_byte(server, 3); /* subfunction */
ncp_add_byte(server, server->name_space[seq->volNumber]);
ncp_add_byte(server, 0); /* data stream (???) */
ncp_add_word(server, 0xffff); /* Search attribs */
ncp_add_dword(server, RIM_ALL); /* return info mask */
ncp_add_mem(server, seq, 9);
ncp_add_byte(server, 2); /* 2 byte pattern */
ncp_add_byte(server, 0xff); /* following is a wildcard */
ncp_add_byte(server, '*');
if ((result = ncp_request(server, 87)) != 0)
{
ncp_unlock_server(server);
return result;
}
memcpy(seq, ncp_reply_data(server, 0), sizeof(*seq));
ncp_extract_file_info(ncp_reply_data(server, 10), target);
ncp_unlock_server(server);
return 0;
}
int
ncp_ren_or_mov_file_or_subdir(struct ncp_server *server,
struct nw_info_struct *old_dir, char *old_name,
struct nw_info_struct *new_dir, char *new_name)
{
int result;
if ((old_dir == NULL) || (old_name == NULL)
|| (new_dir == NULL) || (new_name == NULL))
return -EINVAL;
ncp_init_request(server);
ncp_add_byte(server, 4); /* subfunction */
ncp_add_byte(server, server->name_space[old_dir->volNumber]);
ncp_add_byte(server, 1); /* rename flag */
ncp_add_word(server, 0x8006); /* search attributes */
/* source Handle Path */
ncp_add_byte(server, old_dir->volNumber);
ncp_add_dword(server, old_dir->dirEntNum);
ncp_add_byte(server, 1);
ncp_add_byte(server, 1); /* 1 source component */
/* dest Handle Path */
ncp_add_byte(server, new_dir->volNumber);
ncp_add_dword(server, new_dir->dirEntNum);
ncp_add_byte(server, 1);
ncp_add_byte(server, 1); /* 1 destination component */
/* source path string */
ncp_add_pstring(server, old_name);
/* dest path string */
ncp_add_pstring(server, new_name);
result = ncp_request(server, 87);
ncp_unlock_server(server);
return result;
}
/* We have to transfer to/from user space */
int
ncp_read(struct ncp_server *server, const char *file_id,
__u32 offset, __u16 to_read,
char *target, int *bytes_read)
{
int result;
ncp_init_request(server);
ncp_add_byte(server, 0);
ncp_add_mem(server, file_id, 6);
ncp_add_dword(server, htonl(offset));
ncp_add_word(server, htons(to_read));
if ((result = ncp_request(server, 72)) != 0)
{
ncp_unlock_server(server);
return result;
}
*bytes_read = ntohs(ncp_reply_word(server, 0));
memcpy_tofs(target, ncp_reply_data(server, 2 + (offset & 1)), *bytes_read);
ncp_unlock_server(server);
return 0;
}
int
ncp_write(struct ncp_server *server, const char *file_id,
__u32 offset, __u16 to_write,
const char *source, int *bytes_written)
{
int result;
ncp_init_request(server);
ncp_add_byte(server, 0);
ncp_add_mem(server, file_id, 6);
ncp_add_dword(server, htonl(offset));
ncp_add_word(server, htons(to_write));
ncp_add_mem_fromfs(server, source, to_write);
if ((result = ncp_request(server, 73)) != 0)
{
ncp_unlock_server(server);
return result;
}
*bytes_written = to_write;
ncp_unlock_server(server);
return 0;
}

View File

@@ -1,163 +0,0 @@
#ifndef _NCPLIB_H
#define _NCPLIB_H
#include <linux/fs.h>
#include <linux/ncp.h>
#include <linux/ncp_fs.h>
#include <linux/ncp_fs_sb.h>
#include <linux/types.h>
#include <linux/errno.h>
#include <linux/malloc.h>
#include <linux/stat.h>
#include <linux/fcntl.h>
#include <asm/segment.h>
#include <asm/string.h>
#include <linux/ncp.h>
int
ncp_negotiate_buffersize(struct ncp_server *server, int size,
int *target);
int
ncp_get_encryption_key(struct ncp_server *server,
char *target);
int
ncp_get_bindery_object_id(struct ncp_server *server,
int object_type, char *object_name,
struct ncp_bindery_object *target);
int
ncp_login_encrypted(struct ncp_server *server,
struct ncp_bindery_object *object,
unsigned char *key,
unsigned char *passwd);
int
ncp_login_user(struct ncp_server *server,
unsigned char *username,
unsigned char *password);
int
ncp_get_volume_info_with_number(struct ncp_server *server, int n,
struct ncp_volume_info *target);
int
ncp_get_volume_number(struct ncp_server *server, const char *name,
int *target);
int
ncp_file_search_init(struct ncp_server *server,
int dir_handle, const char *path,
struct ncp_filesearch_info *target);
int
ncp_file_search_continue(struct ncp_server *server,
struct ncp_filesearch_info *fsinfo,
int attributes, const char *path,
struct ncp_file_info *target);
int
ncp_get_finfo(struct ncp_server *server,
int dir_handle, const char *path, const char *name,
struct ncp_file_info *target);
int
ncp_open_file(struct ncp_server *server,
int dir_handle, const char *path,
int attr, int access,
struct ncp_file_info *target);
int
ncp_close_file(struct ncp_server *server, const char *file_id);
int
ncp_create_newfile(struct ncp_server *server,
int dir_handle, const char *path,
int attr,
struct ncp_file_info *target);
int
ncp_create_file(struct ncp_server *server,
int dir_handle, const char *path,
int attr,
struct ncp_file_info *target);
int
ncp_erase_file(struct ncp_server *server,
int dir_handle, const char *path,
int attr);
int
ncp_rename_file(struct ncp_server *server,
int old_handle, const char *old_path,
int attr,
int new_handle, const char *new_path);
int
ncp_create_directory(struct ncp_server *server,
int dir_handle, const char *path,
int inherit_mask);
int
ncp_delete_directory(struct ncp_server *server,
int dir_handle, const char *path);
int
ncp_rename_directory(struct ncp_server *server,
int dir_handle,
const char *old_path, const char *new_path);
int
ncp_read(struct ncp_server *server, const char *file_id,
__u32 offset, __u16 to_read,
char *target, int *bytes_read);
int
ncp_write(struct ncp_server *server, const char *file_id,
__u32 offset, __u16 to_write,
const char *source, int *bytes_written);
int
ncp_obtain_info(struct ncp_server *server,
__u8 vol_num, __u32 dir_base,
char *path, /* At most 1 component */
struct nw_info_struct *target);
int
ncp_lookup_volume(struct ncp_server *server,
char *volname,
struct nw_info_struct *target);
int
ncp_modify_file_or_subdir_dos_info(struct ncp_server *server,
struct nw_info_struct *file,
__u32 info_mask,
struct nw_modify_dos_info *info);
int
ncp_del_file_or_subdir(struct ncp_server *server,
struct nw_info_struct *dir, char *name);
int
ncp_open_create_file_or_subdir(struct ncp_server *server,
struct nw_info_struct *dir, char *name,
int open_create_mode,
__u32 create_attributes,
int desired_acc_rights,
struct nw_file_info *target);
int
ncp_initialize_search(struct ncp_server *server,
struct nw_info_struct *dir,
struct nw_search_sequence *target);
int
ncp_search_for_file_or_subdir(struct ncp_server *server,
struct nw_search_sequence *seq,
struct nw_info_struct *target);
int
ncp_ren_or_mov_file_or_subdir(struct ncp_server *server,
struct nw_info_struct *old_dir, char *old_name,
struct nw_info_struct *new_dir, char *new_name);
#endif /* _NCPLIB_H */

View File

@@ -1,555 +0,0 @@
/*
* linux/fs/ncp/sock.c
*
* Copyright (C) 1992, 1993 Rick Sladkey
*
* Modified 1995 by Volker Lendecke to be usable for ncp
*
*/
#include <linux/config.h>
#ifdef MODULE
#include <linux/module.h>
#include <linux/version.h>
#endif
#include <linux/sched.h>
#include <linux/ncp_fs.h>
#include <linux/errno.h>
#include <linux/socket.h>
#include <linux/fcntl.h>
#include <linux/stat.h>
#include <asm/segment.h>
#include <linux/in.h>
#include <linux/net.h>
#include <linux/mm.h>
#include <linux/netdevice.h>
#include <linux/ipx.h>
#include <linux/ncp.h>
#include <linux/ncp_fs.h>
#include <linux/ncp_fs_sb.h>
#include "/usr/src/linux/net/inet/sock.h"
#define _S(nr) (1<<((nr)-1))
static void
ncp_wdog_data_ready(struct sock *sk, int len)
{
struct socket *sock = sk->socket;
if (!sk->dead)
{
unsigned char packet_buf[2];
struct sockaddr_ipx sender;
int addr_len = sizeof(struct sockaddr_ipx);
int result;
unsigned short fs;
fs = get_fs();
set_fs(get_ds());
result = sock->ops->recvfrom(sock, (void *) packet_buf, 2, 1, 0,
(struct sockaddr *) &sender,
&addr_len);
if ((result != 2)
|| (packet_buf[1] != '?')
/* How to check connection number here? */
)
{
/* Error, throw away the complete packet */
sock->ops->recvfrom(sock, (void *) packet_buf, 2, 1, 0,
(struct sockaddr *) &sender,
&addr_len);
printk("ncpfs: got strange packet on watchdog "
"socket\n");
} else
{
int result;
DDPRINTK("ncpfs: got watchdog from:\n");
DDPRINTK("ncpfs: %08lX:%02X%02X%02X%02X%02X%02X:%04X,"
" conn:%02X,type:%c\n",
htonl(sender.sipx_network),
sender.sipx_node[0], sender.sipx_node[1],
sender.sipx_node[2], sender.sipx_node[3],
sender.sipx_node[4], sender.sipx_node[5],
ntohs(sender.sipx_port),
packet_buf[0], packet_buf[1]);
packet_buf[1] = 'Y';
result = sock->ops->sendto(sock, (void *) packet_buf,
2, 1, 0,
(struct sockaddr *) &sender,
sizeof(sender));
DDPRINTK("send result: %d\n", result);
}
set_fs(fs);
}
}
int
ncp_catch_watchdog(struct ncp_server *server)
{
struct file *file;
struct inode *inode;
struct socket *sock;
struct sock *sk;
if ((server == NULL)
|| ((file = server->wdog_filp) == NULL)
|| ((inode = file->f_inode) == NULL)
|| (!S_ISSOCK(inode->i_mode)))
{
printk("ncp_catch_watchdog: did not get valid server!\n");
server->data_ready = NULL;
return -EINVAL;
}
sock = &(inode->u.socket_i);
if (sock->type != SOCK_DGRAM)
{
printk("ncp_catch_watchdog: did not get SOCK_STREAM\n");
server->data_ready = NULL;
return -EINVAL;
}
sk = (struct sock *) (sock->data);
if (sk == NULL)
{
printk("ncp_catch_watchdog: sk == NULL");
server->data_ready = NULL;
return -EINVAL;
}
DDPRINTK("ncp_catch_watchdog.: sk->d_r = %x, server->d_r = %x\n",
(unsigned int) (sk->data_ready),
(unsigned int) (server->data_ready));
if (sk->data_ready == ncp_wdog_data_ready)
{
printk("ncp_catch_watchdog: already done\n");
return -EINVAL;
}
server->data_ready = sk->data_ready;
sk->data_ready = ncp_wdog_data_ready;
return 0;
}
int
ncp_dont_catch_watchdog(struct ncp_server *server)
{
struct file *file;
struct inode *inode;
struct socket *sock;
struct sock *sk;
if ((server == NULL)
|| ((file = server->wdog_filp) == NULL)
|| ((inode = file->f_inode) == NULL)
|| (!S_ISSOCK(inode->i_mode)))
{
printk("ncp_dont_catch_watchdog: "
"did not get valid server!\n");
return -EINVAL;
}
sock = &(inode->u.socket_i);
if (sock->type != SOCK_DGRAM)
{
printk("ncp_dont_catch_watchdog: did not get SOCK_STREAM\n");
return -EINVAL;
}
sk = (struct sock *) (sock->data);
if (sk == NULL)
{
printk("ncp_dont_catch_watchdog: sk == NULL");
return -EINVAL;
}
if (server->data_ready == NULL)
{
printk("ncp_dont_catch_watchdog: "
"server->data_ready == NULL\n");
return -EINVAL;
}
if (sk->data_ready != ncp_wdog_data_ready)
{
printk("ncp_dont_catch_watchdog: "
"sk->data_callback != ncp_data_callback\n");
return -EINVAL;
}
DDPRINTK("ncp_dont_catch_watchdog: sk->d_r = %x, server->d_r = %x\n",
(unsigned int) (sk->data_ready),
(unsigned int) (server->data_ready));
sk->data_ready = server->data_ready;
server->data_ready = NULL;
return 0;
}
#define NCP_SLACK_SPACE 1024
#define _S(nr) (1<<((nr)-1))
static int
do_ncp_rpc_call(struct ncp_server *server, int size)
{
struct file *file;
struct inode *inode;
struct socket *sock;
unsigned short fs;
int result;
char *start = server->packet;
select_table wait_table;
struct select_table_entry entry;
int (*select) (struct inode *, struct file *, int, select_table *);
int init_timeout, max_timeout;
int timeout;
int retrans;
int major_timeout_seen;
int acknowledge_seen;
int n;
int addrlen;
unsigned long old_mask;
/* We have to check the result, so store the complete header */
struct ncp_request_header request =
*((struct ncp_request_header *) (server->packet));
struct ncp_reply_header reply;
file = server->ncp_filp;
inode = file->f_inode;
select = file->f_op->select;
sock = &inode->u.socket_i;
if (!sock)
{
printk("ncp_rpc_call: socki_lookup failed\n");
return -EBADF;
}
init_timeout = server->m.time_out;
max_timeout = NCP_MAX_RPC_TIMEOUT;
acknowledge_seen = 0;
retrans = server->m.retry_count;
major_timeout_seen = 0;
old_mask = current->blocked;
current->blocked |= ~(_S(SIGKILL)
#if 0
| _S(SIGSTOP)
#endif
| ((server->m.flags & NCP_MOUNT_INTR)
? ((current->sigaction[SIGINT - 1].sa_handler == SIG_DFL
? _S(SIGINT) : 0)
| (current->sigaction[SIGQUIT - 1].sa_handler == SIG_DFL
? _S(SIGQUIT) : 0))
: 0));
fs = get_fs();
set_fs(get_ds());
for (n = 0, timeout = init_timeout;; n++, timeout <<= 1)
{
DDPRINTK("ncpfs: %08lX:%02X%02X%02X%02X%02X%02X:%04X\n",
htonl(server->m.serv_addr.sipx_network),
server->m.serv_addr.sipx_node[0],
server->m.serv_addr.sipx_node[1],
server->m.serv_addr.sipx_node[2],
server->m.serv_addr.sipx_node[3],
server->m.serv_addr.sipx_node[4],
server->m.serv_addr.sipx_node[5],
ntohs(server->m.serv_addr.sipx_port));
DDPRINTK("ncpfs: req.typ: %04X, con: %d, "
"seq: %d",
request.type,
(request.conn_high << 8) + request.conn_low,
request.sequence);
DDPRINTK(" func: %d\n",
request.function);
result = sock->ops->sendto(sock, (void *) start, size, 0, 0,
(struct sockaddr *)
&(server->m.serv_addr),
sizeof(server->m.serv_addr));
if (result < 0)
{
printk("ncp_rpc_call: send error = %d\n", result);
break;
}
re_select:
wait_table.nr = 0;
wait_table.entry = &entry;
current->state = TASK_INTERRUPTIBLE;
if (!select(inode, file, SEL_IN, &wait_table)
&& !select(inode, file, SEL_IN, NULL))
{
if (timeout > max_timeout)
{
/* JEJB/JSP 2/7/94
* This is useful to see if the system is
* hanging */
if (acknowledge_seen == 0)
{
printk("NCP max timeout reached\n");
}
timeout = max_timeout;
}
current->timeout = jiffies + timeout;
schedule();
remove_wait_queue(entry.wait_address, &entry.wait);
current->state = TASK_RUNNING;
if (current->signal & ~current->blocked)
{
current->timeout = 0;
result = -ERESTARTSYS;
break;
}
if (!current->timeout)
{
if (n < retrans)
continue;
if (server->m.flags & NCP_MOUNT_SOFT)
{
printk("NCP server not responding\n");
result = -EIO;
break;
}
n = 0;
timeout = init_timeout;
init_timeout <<= 1;
if (!major_timeout_seen)
{
printk("NCP server not responding\n");
}
major_timeout_seen = 1;
continue;
} else
current->timeout = 0;
} else if (wait_table.nr)
remove_wait_queue(entry.wait_address, &entry.wait);
current->state = TASK_RUNNING;
addrlen = 0;
/* Get the header from the next packet using a peek, so keep it
* on the recv queue. If it is wrong, it will be some reply
* we don't now need, so discard it */
result = sock->ops->recvfrom(sock, (void *) &reply,
sizeof(reply), 1, MSG_PEEK,
NULL, &addrlen);
if (result < 0)
{
if (result == -EAGAIN)
{
DPRINTK("ncp_rpc_call: bad select ready\n");
goto re_select;
}
if (result == -ECONNREFUSED)
{
DPRINTK("ncp_rpc_call: server playing coy\n");
goto re_select;
}
if (result != -ERESTARTSYS)
{
printk("ncp_rpc_call: recv error = %d\n",
-result);
}
break;
}
if ((result == sizeof(reply))
&& (reply.type == NCP_POSITIVE_ACK))
{
/* Throw away the packet */
DPRINTK("ncp_rpc_call: got positive acknowledge\n");
sock->ops->recvfrom(sock, (void *) &reply,
sizeof(reply), 1, 0,
NULL, &addrlen);
n = 0;
timeout = max_timeout;
acknowledge_seen = 1;
goto re_select;
}
DDPRINTK("ncpfs: rep.typ: %04X, con: %d, tsk: %d,"
"seq: %d\n",
reply.type,
(reply.conn_high << 8) + reply.conn_low,
reply.task,
reply.sequence);
if ((result >= sizeof(reply))
&& (reply.type == NCP_REPLY)
&& ((request.type == NCP_ALLOC_SLOT_REQUEST)
|| ((reply.sequence == request.sequence)
&& (reply.conn_low == request.conn_low)
/* seem to get wrong task from NW311 && (reply.task == request.task) */
&& (reply.conn_high == request.conn_high))))
{
if (major_timeout_seen)
printk("NCP server OK\n");
break;
}
/* JEJB/JSP 2/7/94
* we have xid mismatch, so discard the packet and start
* again. What a hack! but I can't call recvfrom with
* a null buffer yet. */
sock->ops->recvfrom(sock, (void *) &reply, sizeof(reply), 1, 0,
NULL, &addrlen);
DPRINTK("ncp_rpc_call: reply mismatch\n");
goto re_select;
}
/*
* we have the correct reply, so read into the correct place and
* return it
*/
result = sock->ops->recvfrom(sock, (void *) start, server->packet_size,
1, 0, NULL, &addrlen);
if (result < 0)
{
printk("NCP: notice message: result=%d\n", result);
} else if (result < sizeof(struct ncp_reply_header))
{
printk("NCP: just caught a too small read memory size..., "
"email to NET channel\n");
printk("NCP: result=%d,addrlen=%d\n", result, addrlen);
result = -EIO;
}
current->blocked = old_mask;
set_fs(fs);
return result;
}
/*
* We need the server to be locked here, so check!
*/
static int
ncp_do_request(struct ncp_server *server, int size)
{
if (server->lock == 0)
{
printk("ncpfs: Server not locked!\n");
return -EIO;
}
return do_ncp_rpc_call(server, size);
}
/* ncp_do_request assures that at least a complete reply header is
* received. It assumes that server->current_size contains the ncp
* request size */
int
ncp_request(struct ncp_server *server, int function)
{
struct ncp_request_header *h
= (struct ncp_request_header *) (server->packet);
struct ncp_reply_header *reply
= (struct ncp_reply_header *) (server->packet);
int request_size = server->current_size
- sizeof(struct ncp_request_header);
int result;
if (server->has_subfunction != 0)
{
*(__u16 *) & (h->data[0]) = request_size - 2;
}
h->type = NCP_REQUEST;
server->sequence += 1;
h->sequence = server->sequence;
h->conn_low = (server->connection) & 0xff;
h->conn_high = ((server->connection) & 0xff00) >> 8;
h->task = (current->pid) & 0xff;
h->function = function;
if ((result = ncp_do_request(server, request_size + sizeof(*h))) < 0)
{
DPRINTK("ncp_request_error: %d\n", result);
return result;
}
server->completion = reply->completion_code;
server->conn_status = reply->connection_state;
server->reply_size = result;
server->ncp_reply_size = result - sizeof(struct ncp_reply_header);
result = reply->completion_code;
if (result != 0)
{
DPRINTK("ncp_completion_code: %x\n", result);
}
return result;
}
int
ncp_connect(struct ncp_server *server)
{
struct ncp_request_header *h
= (struct ncp_request_header *) (server->packet);
int result;
h->type = NCP_ALLOC_SLOT_REQUEST;
server->sequence = 0;
h->sequence = server->sequence;
h->conn_low = 0xff;
h->conn_high = 0xff;
h->task = (current->pid) & 0xff;
h->function = 0;
if ((result = ncp_do_request(server, sizeof(*h))) < 0)
{
return result;
}
server->sequence = 0;
server->connection = h->conn_low + (h->conn_high * 256);
return 0;
}
int
ncp_disconnect(struct ncp_server *server)
{
struct ncp_request_header *h
= (struct ncp_request_header *) (server->packet);
h->type = NCP_DEALLOC_SLOT_REQUEST;
server->sequence += 1;
h->sequence = server->sequence;
h->conn_low = (server->connection) & 0xff;
h->conn_high = ((server->connection) & 0xff00) >> 8;
h->task = (current->pid) & 0xff;
h->function = 0;
return ncp_do_request(server, sizeof(*h));
}
void
ncp_lock_server(struct ncp_server *server)
{
#if 0
/* For testing, only 1 process */
if (server->lock != 0)
{
DPRINTK("ncpfs: server locked!!!\n");
}
#endif
while (server->lock)
sleep_on(&server->wait);
server->lock = 1;
}
void
ncp_unlock_server(struct ncp_server *server)
{
if (server->lock != 1)
{
printk("ncp_unlock_server: was not locked!\n");
}
server->lock = 0;
wake_up(&server->wait);
}

View File

@@ -17,28 +17,25 @@
static void
#ifdef __STDC__
default_com_err_proc(const char *whoami, errcode_t code, const
char *fmt, va_list args)
default_com_err_proc(const char *whoami, errcode_t code, const
char *fmt, va_list args)
#else
default_com_err_proc(whoami, code, fmt, args)
default_com_err_proc(whoami, code, fmt, args)
const char *whoami;
errcode_t code;
const char *fmt;
va_list args;
#endif
{
if (whoami)
{
if (whoami) {
fputs(whoami, stderr);
fputs(": ", stderr);
}
if (code)
{
if (code) {
fputs(error_message(code), stderr);
fputs(" ", stderr);
}
if (fmt)
{
if (fmt) {
vfprintf(stderr, fmt, args);
}
/* should do this only on a tty in raw mode */
@@ -56,12 +53,10 @@ typedef void (*errf) ();
errf com_err_hook = default_com_err_proc;
#ifdef __STDC__
void
com_err_va(const char *whoami, errcode_t code, const char *fmt,
va_list args)
void com_err_va(const char *whoami, errcode_t code, const char *fmt,
va_list args)
#else
void
com_err_va(whoami, code, fmt, args)
void com_err_va(whoami, code, fmt, args)
const char *whoami;
errcode_t code;
const char *fmt;
@@ -72,14 +67,12 @@ va_list args;
}
#ifndef VARARGS
void
com_err(const char *whoami,
errcode_t code,
const char *fmt,...)
void com_err(const char *whoami,
errcode_t code,
const char *fmt,...)
{
#else
void
com_err(va_alist)
void com_err(va_alist)
va_dcl
{
const char *whoami, *fmt;

View File

@@ -24,10 +24,10 @@ struct et_list *_et_list = (struct et_list *) NULL;
#ifdef __STDC__
const char *
error_message(errcode_t code)
error_message(errcode_t code)
#else
const char *
error_message(code)
error_message(code)
errcode_t code;
#endif
{
@@ -39,8 +39,7 @@ errcode_t code;
offset = code & ((1 << ERRCODE_RANGE) - 1);
table_num = code - offset;
if (!table_num)
{
if (!table_num) {
#ifdef HAS_SYS_ERRLIST
if (offset < sys_nerr)
return (sys_errlist[offset]);
@@ -54,10 +53,8 @@ errcode_t code;
goto oops;
#endif
}
for (et = _et_list; et; et = et->next)
{
if (et->table->base == table_num)
{
for (et = _et_list; et; et = et->next) {
if (et->table->base == table_num) {
/* This is the right table */
if (et->table->n_msgs <= offset)
goto oops;
@@ -66,21 +63,17 @@ errcode_t code;
}
oops:
strcpy(buffer, "Unknown code ");
if (table_num)
{
if (table_num) {
strcat(buffer, error_table_name(table_num));
strcat(buffer, " ");
}
for (cp = buffer; *cp; cp++)
;
if (offset >= 100)
{
for (cp = buffer; *cp; cp++);
if (offset >= 100) {
*cp++ = '0' + offset / 100;
offset %= 100;
started++;
}
if (started || offset >= 10)
{
if (started || offset >= 10) {
*cp++ = '0' + offset / 10;
offset %= 10;
}

View File

@@ -11,14 +11,12 @@
#define const
#endif
struct error_table
{
struct error_table {
char const *const *msgs;
long base;
int n_msgs;
};
struct et_list
{
struct et_list {
struct et_list *next;
const struct error_table *table;
};

View File

@@ -14,7 +14,7 @@ static const char char_set[] =
static char buf[6];
const char *
error_table_name(num)
error_table_name(num)
int num;
{
int ch;
@@ -27,8 +27,7 @@ int num;
/* num = ?? ??? ??? aaa aaa bbb bbb ccc ccc ddd ddd */
num &= 077777777;
/* num = 00 000 000 aaa aaa bbb bbb ccc ccc ddd ddd */
for (i = 4; i >= 0; i--)
{
for (i = 4; i >= 0; i--) {
ch = (num >> BITS_PER_CHAR * i) & ((1 << BITS_PER_CHAR) - 1);
if (ch != 0)
*p++ = char_set[ch - 1];

View File

@@ -23,8 +23,7 @@
#define const
#endif
struct foobar
{
struct foobar {
struct et_list etl;
struct error_table et;
};
@@ -32,11 +31,9 @@ struct foobar
extern struct et_list *_et_list;
#ifdef __STDC__
int
init_error_table(const char *const *msgs, int base, int count)
int init_error_table(const char *const *msgs, int base, int count)
#else
int
init_error_table(msgs, base, count)
int init_error_table(msgs, base, count)
const char *const *msgs;
int base;
int count;

File diff suppressed because it is too large Load Diff

View File

@@ -92,20 +92,20 @@ typedef unsigned char buf4[4];
static unsigned char encrypttable[256] =
{0x7, 0x8, 0x0, 0x8, 0x6, 0x4, 0xE, 0x4, 0x5, 0xC, 0x1, 0x7, 0xB, 0xF, 0xA, 0x8,
0xF, 0x8, 0xC, 0xC, 0x9, 0x4, 0x1, 0xE, 0x4, 0x6, 0x2, 0x4, 0x0, 0xA, 0xB, 0x9,
0x2, 0xF, 0xB, 0x1, 0xD, 0x2, 0x1, 0x9, 0x5, 0xE, 0x7, 0x0, 0x0, 0x2, 0x6, 0x6,
0x0, 0x7, 0x3, 0x8, 0x2, 0x9, 0x3, 0xF, 0x7, 0xF, 0xC, 0xF, 0x6, 0x4, 0xA, 0x0,
0x2, 0x3, 0xA, 0xB, 0xD, 0x8, 0x3, 0xA, 0x1, 0x7, 0xC, 0xF, 0x1, 0x8, 0x9, 0xD,
0x9, 0x1, 0x9, 0x4, 0xE, 0x4, 0xC, 0x5, 0x5, 0xC, 0x8, 0xB, 0x2, 0x3, 0x9, 0xE,
0x7, 0x7, 0x6, 0x9, 0xE, 0xF, 0xC, 0x8, 0xD, 0x1, 0xA, 0x6, 0xE, 0xD, 0x0, 0x7,
0x7, 0xA, 0x0, 0x1, 0xF, 0x5, 0x4, 0xB, 0x7, 0xB, 0xE, 0xC, 0x9, 0x5, 0xD, 0x1,
0xB, 0xD, 0x1, 0x3, 0x5, 0xD, 0xE, 0x6, 0x3, 0x0, 0xB, 0xB, 0xF, 0x3, 0x6, 0x4,
0x9, 0xD, 0xA, 0x3, 0x1, 0x4, 0x9, 0x4, 0x8, 0x3, 0xB, 0xE, 0x5, 0x0, 0x5, 0x2,
0xC, 0xB, 0xD, 0x5, 0xD, 0x5, 0xD, 0x2, 0xD, 0x9, 0xA, 0xC, 0xA, 0x0, 0xB, 0x3,
0x5, 0x3, 0x6, 0x9, 0x5, 0x1, 0xE, 0xE, 0x0, 0xE, 0x8, 0x2, 0xD, 0x2, 0x2, 0x0,
0x4, 0xF, 0x8, 0x5, 0x9, 0x6, 0x8, 0x6, 0xB, 0xA, 0xB, 0xF, 0x0, 0x7, 0x2, 0x8,
0xC, 0x7, 0x3, 0xA, 0x1, 0x4, 0x2, 0x5, 0xF, 0x7, 0xA, 0xC, 0xE, 0x5, 0x9, 0x3,
0xE, 0x7, 0x1, 0x2, 0xE, 0x1, 0xF, 0x4, 0xA, 0x6, 0xC, 0x6, 0xF, 0x4, 0x3, 0x0,
0xF, 0x8, 0xC, 0xC, 0x9, 0x4, 0x1, 0xE, 0x4, 0x6, 0x2, 0x4, 0x0, 0xA, 0xB, 0x9,
0x2, 0xF, 0xB, 0x1, 0xD, 0x2, 0x1, 0x9, 0x5, 0xE, 0x7, 0x0, 0x0, 0x2, 0x6, 0x6,
0x0, 0x7, 0x3, 0x8, 0x2, 0x9, 0x3, 0xF, 0x7, 0xF, 0xC, 0xF, 0x6, 0x4, 0xA, 0x0,
0x2, 0x3, 0xA, 0xB, 0xD, 0x8, 0x3, 0xA, 0x1, 0x7, 0xC, 0xF, 0x1, 0x8, 0x9, 0xD,
0x9, 0x1, 0x9, 0x4, 0xE, 0x4, 0xC, 0x5, 0x5, 0xC, 0x8, 0xB, 0x2, 0x3, 0x9, 0xE,
0x7, 0x7, 0x6, 0x9, 0xE, 0xF, 0xC, 0x8, 0xD, 0x1, 0xA, 0x6, 0xE, 0xD, 0x0, 0x7,
0x7, 0xA, 0x0, 0x1, 0xF, 0x5, 0x4, 0xB, 0x7, 0xB, 0xE, 0xC, 0x9, 0x5, 0xD, 0x1,
0xB, 0xD, 0x1, 0x3, 0x5, 0xD, 0xE, 0x6, 0x3, 0x0, 0xB, 0xB, 0xF, 0x3, 0x6, 0x4,
0x9, 0xD, 0xA, 0x3, 0x1, 0x4, 0x9, 0x4, 0x8, 0x3, 0xB, 0xE, 0x5, 0x0, 0x5, 0x2,
0xC, 0xB, 0xD, 0x5, 0xD, 0x5, 0xD, 0x2, 0xD, 0x9, 0xA, 0xC, 0xA, 0x0, 0xB, 0x3,
0x5, 0x3, 0x6, 0x9, 0x5, 0x1, 0xE, 0xE, 0x0, 0xE, 0x8, 0x2, 0xD, 0x2, 0x2, 0x0,
0x4, 0xF, 0x8, 0x5, 0x9, 0x6, 0x8, 0x6, 0xB, 0xA, 0xB, 0xF, 0x0, 0x7, 0x2, 0x8,
0xC, 0x7, 0x3, 0xA, 0x1, 0x4, 0x2, 0x5, 0xF, 0x7, 0xA, 0xC, 0xE, 0x5, 0x9, 0x3,
0xE, 0x7, 0x1, 0x2, 0xE, 0x1, 0xF, 0x4, 0xA, 0x6, 0xC, 0x6, 0xF, 0x4, 0x3, 0x0,
0xC, 0x0, 0x3, 0x6, 0xF, 0x8, 0x7, 0xB, 0x2, 0xD, 0xC, 0x6, 0xA, 0xA, 0x8, 0xD};
static buf32 encryptkeys =
@@ -115,8 +115,7 @@ static buf32 encryptkeys =
0xF4, 0x47, 0xDC, 0xA7, 0xEC, 0xCF, 0x50, 0xC0};
static void
shuffle1(buf32 temp, unsigned char *target)
static void shuffle1(buf32 temp, unsigned char *target)
{
short b4;
unsigned char b3;
@@ -124,63 +123,51 @@ shuffle1(buf32 temp, unsigned char *target)
b4 = 0;
for (b2 = 0; b2 <= 1; ++b2)
{
for (s = 0; s <= 31; ++s)
{
for (b2 = 0; b2 <= 1; ++b2) {
for (s = 0; s <= 31; ++s) {
b3 = (temp[s] + b4) ^ (temp[(s + b4) & 31] - encryptkeys[s]);
b4 = b4 + b3;
temp[s] = b3;
}
}
for (i = 0; i <= 15; ++i)
{
for (i = 0; i <= 15; ++i) {
target[i] = encrypttable[temp[2 * i]]
| (encrypttable[temp[2 * i + 1]] << 4);
}
}
static void
shuffle(const unsigned char *lon, const unsigned char *buf, int buflen,
unsigned char *target)
static void shuffle(const unsigned char *lon, const unsigned char *buf, int buflen,
unsigned char *target)
{
int b2, d, s;
buf32 temp;
while ((buflen > 0)
&& (buf[buflen - 1] == 0))
{
&& (buf[buflen - 1] == 0)) {
buflen = buflen - 1;
}
for (s = 0; s < 32; s++)
{
for (s = 0; s < 32; s++) {
temp[s] = 0;
}
d = 0;
while (buflen >= 32)
{
for (s = 0; s <= 31; ++s)
{
while (buflen >= 32) {
for (s = 0; s <= 31; ++s) {
temp[s] = temp[s] ^ buf[d];
d = d + 1;
}
buflen = buflen - 32;
}
b2 = d;
if (buflen > 0)
{
for (s = 0; s <= 31; ++s)
{
if (d + buflen == b2)
{
if (buflen > 0) {
for (s = 0; s <= 31; ++s) {
if (d + buflen == b2) {
b2 = d;
temp[s] = temp[s] ^ encryptkeys[s];
} else
{
} else {
temp[s] = temp[s] ^ buf[b2];
b2 = b2 + 1;
}
@@ -193,10 +180,9 @@ shuffle(const unsigned char *lon, const unsigned char *buf, int buflen,
}
static void
nw_encrypt(const unsigned char *fra,
const unsigned char *buf,
unsigned char *til)
static void nw_encrypt(const unsigned char *fra,
const unsigned char *buf,
unsigned char *til)
{
buf32 k;
int s;
@@ -302,8 +288,7 @@ static char
* in ncplib.c.
*/
static void
newpassencrypt(char *old, char *new, char *out)
static void newpassencrypt(char *old, char *new, char *out)
{
char *p, *bx;
char copy[8];
@@ -312,26 +297,22 @@ newpassencrypt(char *old, char *new, char *out)
memcpy(copy, new, 8);
for (i = 0; i < 16; i++)
{
for (di = 0, ax = 0, p = old; di < 8; di++, ax += 0x20, p++)
{
for (i = 0; i < 16; i++) {
for (di = 0, ax = 0, p = old; di < 8; di++, ax += 0x20, p++) {
cl = newshuffle[(((copy[di] ^ *p) >> 4) & 0x0f) + ax + 0x10] << 4;
dl = newshuffle[((copy[di] ^ *p) & 0xf) + ax];
copy[di] = cl | dl;
}
ch = old[7];
for (bx = old + 7; bx > old; bx--)
{
for (bx = old + 7; bx > old; bx--) {
*bx = ((bx[-1] >> 4) & 0x0f) | ((*bx) << 4);
}
*old = ((ch >> 4) & 0x0f) | (*old) << 4;
memset(out, '\0', 8);
for (di = 0; di < 16; di++)
{
for (di = 0; di < 16; di++) {
if (newshuffle[di + 0x100] & 1)
ch = ((copy[newshuffle[di + 0x100] / 2] >> 4) & 0x0f);
else

View File

@@ -1,33 +0,0 @@
.TH NWMSG 8 02/29/1996 nwmsg nwmsg
.SH NAME
nwmsg \- Deliver NetWare user broadcast messages
.SH SYNOPSIS
.B nwmsg
.I mount-point
.SH DESCRIPTION
.B nwmsg
is called by kerneld when a broadcast message arrives from a NetWare
server.
.B nwmsg
fetches this message via the mount point and delivers it to
the user using the same way write(1) uses.
Please note that
.I kerneld
must run when broadcast messages should be delivered to users.
NetWare servers can send asynchronous broadcast messages to users,
either on explicit request by another user, or when the server is
shutdown. The client workstation is informed about this event by an
IPX packet on a special socket, the message socket.
This can happen at any time, so the user has to be informed about this
event whenever it appears. I chose to use the kerneld feature of the
Linux kernel to call the program nwmsg. For nwmsg, I used the relevant
parts of the
.I write
program, so you can expect the NetWare broadcast
messages to appear where user messages would appear.
.SH SEE ALSO
ncpmount(8), kerneld(8), write(1)

View File

@@ -1,7 +1,7 @@
Begin3
Title: ncpfs
Version: 2.0.10
Entered-date: 23. February 1997
Version: 2.1.1
Entered-date: 23. March 1997
Description: With ncpfs you can mount volumes of your netware
server under Linux. You can also print to netware
print queues and spool netware print queues to the
@@ -13,7 +13,7 @@ Author: lendecke@namu01.Num.Math.Uni-Goettingen.de (Volker Lendecke)
Maintained-by: lendecke@namu01.Num.Math.Uni-Goettingen.de (Volker Lendecke)
Primary-site: ftp.gwdg.de:/pub/linux/misc/ncpfs
Alternate-site: sunsite.unc.edu:/pub/Linux/system/Filesystems/ncpfs
~158k ncpfs-2.0.10.tgz
~ 1k ncpfs-2.0.10.lsm
~177k ncpfs-2.1.1.tgz
~ 1k ncpfs-2.1.1.lsm
Copying-policy: GPL
End

View File

@@ -10,4 +10,4 @@ file. Please only apply it if you experience the problem. Should apply
to 2.0.28 and above in the 2.0.x series. NOT TESTED with 2.1.x.
linux-2.1.26.diff:
Little fix to make ncpfs work with 2.1.26. Sent to Linus.
Development version of ncpfs

5281
patches/linux-2.1.29.diff Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -33,14 +33,12 @@ typedef unsigned char IPXNode[IPX_NODE_LEN];
#define IPX_SAP_FILE_SERVER (0x0004)
struct sap_query
{
struct sap_query {
unsigned short query_type; /* net order */
unsigned short server_type; /* net order */
};
struct sap_server_ident
{
struct sap_server_ident {
unsigned short server_type __attribute__((packed));
char server_name[48] __attribute__((packed));
IPXNet server_network __attribute__((packed));
@@ -52,16 +50,13 @@ struct sap_server_ident
#define IPX_RIP_REQUEST (0x1)
#define IPX_RIP_RESPONSE (0x2)
struct ipx_rip_packet
{
struct ipx_rip_packet {
__u16 operation __attribute__((packed));
struct ipx_rt_def
{
struct ipx_rt_def {
__u32 network __attribute__((packed));
__u16 hops __attribute__((packed));
__u16 ticks __attribute__((packed));
}
rt[1] __attribute__((packed));
} rt[1] __attribute__((packed));
};
#define IPX_BROADCAST_NODE ("\xff\xff\xff\xff\xff\xff")

File diff suppressed because it is too large Load Diff

View File

@@ -1,3 +1,5 @@
/*
* ncplib.h
*
@@ -9,9 +11,8 @@
#define _NCPLIB_H
#include <linux/types.h>
#include <linux/ncp.h>
#include "ncp.h"
#include <linux/ncp_fs.h>
#include <linux/ipx.h>
#include <sys/param.h>
#include <stdio.h>
#include <time.h>
@@ -33,23 +34,21 @@ typedef __u32 dword;
#define BSET(buf,pos,val) (BVAL(buf,pos) = (val))
static inline word
WVAL_HL(__u8 * buf, int pos)
WVAL_HL(__u8 * buf, int pos)
{
return PVAL(buf, pos) << 8 | PVAL(buf, pos + 1);
}
static inline dword
DVAL_HL(__u8 * buf, int pos)
DVAL_HL(__u8 * buf, int pos)
{
return WVAL_HL(buf, pos) << 16 | WVAL_HL(buf, pos + 2);
}
static inline void
WSET_HL(__u8 * buf, int pos, word val)
static inline void WSET_HL(__u8 * buf, int pos, word val)
{
BSET(buf, pos, val >> 8);
BSET(buf, pos + 1, val & 0xff);
}
static inline void
DSET_HL(__u8 * buf, int pos, dword val)
static inline void DSET_HL(__u8 * buf, int pos, dword val)
{
WSET_HL(buf, pos, val >> 16);
WSET_HL(buf, pos + 2, val & 0xffff);
@@ -61,22 +60,20 @@ DSET_HL(__u8 * buf, int pos, dword val)
#if defined(__i386__)
static inline word
WVAL_LH(__u8 * buf, int pos)
WVAL_LH(__u8 * buf, int pos)
{
return *((word *) (buf + pos));
}
static inline dword
DVAL_LH(__u8 * buf, int pos)
DVAL_LH(__u8 * buf, int pos)
{
return *((dword *) (buf + pos));
}
static inline void
WSET_LH(__u8 * buf, int pos, word val)
static inline void WSET_LH(__u8 * buf, int pos, word val)
{
*((word *) (buf + pos)) = val;
}
static inline void
DSET_LH(__u8 * buf, int pos, dword val)
static inline void DSET_LH(__u8 * buf, int pos, dword val)
{
*((dword *) (buf + pos)) = val;
}
@@ -84,23 +81,21 @@ DSET_LH(__u8 * buf, int pos, dword val)
#else
static inline word
WVAL_LH(__u8 * buf, int pos)
WVAL_LH(__u8 * buf, int pos)
{
return PVAL(buf, pos) | PVAL(buf, pos + 1) << 8;
}
static inline dword
DVAL_LH(__u8 * buf, int pos)
DVAL_LH(__u8 * buf, int pos)
{
return WVAL_LH(buf, pos) | WVAL_LH(buf, pos + 2) << 16;
}
static inline void
WSET_LH(__u8 * buf, int pos, word val)
static inline void WSET_LH(__u8 * buf, int pos, word val)
{
BSET(buf, pos, val & 0xff);
BSET(buf, pos + 1, val >> 8);
}
static inline void
DSET_LH(__u8 * buf, int pos, dword val)
static inline void DSET_LH(__u8 * buf, int pos, dword val)
{
WSET_LH(buf, pos, val & 0xffff);
WSET_LH(buf, pos + 2, val >> 16);
@@ -111,15 +106,13 @@ DSET_LH(__u8 * buf, int pos, dword val)
void
str_upper(char *name);
enum connect_state
{
enum connect_state {
NOT_CONNECTED = 0,
CONN_PERMANENT,
CONN_TEMPORARY
};
struct ncp_conn
{
struct ncp_conn {
enum connect_state is_connected;
@@ -152,8 +145,7 @@ struct ncp_conn
char packet[NCP_PACKET_SIZE];
};
struct ncp_conn_spec
{
struct ncp_conn_spec {
char server[NCP_BINDERY_NAME_LEN];
char user[NCP_BINDERY_NAME_LEN];
uid_t uid;
@@ -161,8 +153,7 @@ struct ncp_conn_spec
char password[NCP_BINDERY_NAME_LEN];
};
struct ncp_property_info
{
struct ncp_property_info {
__u8 property_name[16];
__u8 property_flags;
__u8 property_security;
@@ -216,8 +207,7 @@ long
/* like getmntent, get_ncp_conn_ent scans /etc/mtab for usable
connections */
struct ncp_conn_ent
{
struct ncp_conn_ent {
char server[NCP_BINDERY_NAME_LEN];
char user[NCP_BINDERY_NAME_LEN];
uid_t uid;
@@ -240,15 +230,13 @@ long
ncp_get_encryption_key(struct ncp_conn *conn,
char *target);
struct ncp_station_addr
{
struct ncp_station_addr {
__u32 NetWork __attribute__((packed));
__u8 Node[6] __attribute__((packed));
__u16 Socket __attribute__((packed));
};
struct ncp_prop_login_control
{
struct ncp_prop_login_control {
__u8 AccountExpireDate[3] __attribute__((packed));
__u8 Disabled __attribute__((packed));
__u8 PasswordExpireDate[3] __attribute__((packed));
@@ -286,4 +274,7 @@ long
const unsigned char *username,
const unsigned char *password);
long
ncp_get_broadcast_message(struct ncp_conn *conn, char message[256]);
#endif /* _NCPLIB_H */

View File

@@ -1,7 +1,7 @@
/*
* nwmount.c
* ncpmount.c
*
* Copyright (C) 1995 by Volker Lendecke
* Copyright (C) 1995, 1997 by Volker Lendecke
*
* 1/20/96 - Steven N. Hirsch (hirsch@emba.uvm.edu)
*
@@ -26,7 +26,6 @@
#include <netdb.h>
#include <sys/stat.h>
#include <sys/types.h>
/* #include <sys/wait.h> *//* generates a warning here */
extern pid_t waitpid(pid_t, int *, int);
#include <sys/errno.h>
#include <sys/time.h>
@@ -39,6 +38,8 @@ extern pid_t waitpid(pid_t, int *, int);
#include <mntent.h>
#include <linux/ipx.h>
#include <sys/ioctl.h>
#include <utmp.h>
#include <syslog.h>
#include <linux/fs.h>
#include <linux/ncp.h>
@@ -48,105 +49,65 @@ extern pid_t waitpid(pid_t, int *, int);
#include "com_err.h"
static char *progname;
static char mount_point[MAXPATHLEN + 1];
static void usage(void);
static void help(void);
#ifndef HAVE_KERNELD
/* Returns 0 if the filesystem is in the kernel after this routine
completes */
static int
load_ncpfs(void)
{
FILE *ffs;
char s[1024];
char *p, *p1;
pid_t pid;
int status;
/* Check if ncpfs is in the kernel */
ffs = fopen("/proc/filesystems", "r");
if (ffs == NULL)
{
perror("Error: \"/proc/filesystems\" could not be read:");
return -1;
}
p = NULL;
while (!feof(ffs))
{
p1 = fgets(s, sizeof(s), ffs);
if (p1)
{
p = strstr(s, "ncpfs");
if (p)
{
break;
}
}
}
fclose(ffs);
if (p)
{
return 0;
}
/* system() function without signal handling, from Stevens */
if ((pid = fork()) < 0)
{
return 1;
} else if (pid == 0)
{
/* child */
execl("/sbin/modprobe", "modprobe", "ncpfs", NULL);
_exit(127); /* execl error */
} else
{
/* parent */
while (waitpid(pid, &status, 0) < 0)
{
if (errno != EINTR)
{
status = -1;
break;
}
}
}
return status;
}
#endif /* HAVE_KERNELD */
static int process_connection(int wdog_fd, int msg_fd);
/* Check whether user is allowed to mount on the specified mount point */
static int
mount_ok(struct stat *st)
static int mount_ok(struct stat *st)
{
if (!S_ISDIR(st->st_mode))
{
if (!S_ISDIR(st->st_mode)) {
errno = ENOTDIR;
return -1;
}
if ((getuid() != 0)
&& ((getuid() != st->st_uid)
|| ((st->st_mode & S_IRWXU) != S_IRWXU)))
{
|| ((st->st_mode & S_IRWXU) != S_IRWXU))) {
errno = EPERM;
return -1;
}
return 0;
}
/*
* This function changes the processes name as shown by the system.
* Stolen from Marcin Dalecki's modald :-)
*/
static void inststr(char *dst[], int argc, char *src)
{
/* stolen from the source to perl 4.036 (assigning to $0) */
char *ptr, *ptr2;
int count;
ptr = dst[0] + strlen(dst[0]);
for (count = 1; count < argc; count++) {
if (dst[count] == ptr + 1)
ptr += strlen(++ptr);
}
if (environ[0] == ptr + 1) {
for (count = 0; environ[count]; count++)
if (environ[count] == ptr + 1)
ptr += strlen(++ptr);
}
count = 0;
for (ptr2 = dst[0]; ptr2 <= ptr; ptr2++) {
*ptr2 = '\0';
count++;
}
strncpy(dst[0], src, count);
for (count = 1; count < argc; count++) {
dst[count] = NULL;
}
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
struct ncp_mount_data data;
struct stat st;
char mount_name[256];
int fd, result;
int wdog_fd, msg_fd;
struct sockaddr_ipx addr;
struct sockaddr_ipx *server_addr;
int addrlen;
@@ -157,10 +118,8 @@ main(int argc, char *argv[])
int um;
unsigned int flags;
char mount_point[MAXPATHLEN];
struct mntent ment;
FILE *mtab;
char *tmp_mount;
char *server = NULL;
char *user = NULL;
@@ -178,8 +137,7 @@ main(int argc, char *argv[])
memzero(data);
memzero(spec);
if (geteuid() != 0)
{
if (geteuid() != 0) {
fprintf(stderr, "%s must be installed suid root\n", progname);
exit(1);
}
@@ -196,16 +154,13 @@ main(int argc, char *argv[])
upcase_password = 1;
while ((opt = getopt(argc, argv, "CS:U:c:u:g:f:d:P:nh?vV:t:r:"))
!= EOF)
{
switch (opt)
{
!= EOF) {
switch (opt) {
case 'C':
upcase_password = 0;
break;
case 'S':
if (strlen(optarg) >= sizeof(spec->server))
{
if (strlen(optarg) >= sizeof(spec->server)) {
fprintf(stderr, "Servername too long:%s\n",
optarg);
return 1;
@@ -213,8 +168,7 @@ main(int argc, char *argv[])
server = optarg;
break;
case 'U':
if (strlen(optarg) >= sizeof(spec->user))
{
if (strlen(optarg) >= sizeof(spec->user)) {
fprintf(stderr, "Username too long: %s\n",
optarg);
return 1;
@@ -222,30 +176,24 @@ main(int argc, char *argv[])
user = optarg;
break;
case 'c':
if (isdigit(optarg[0]))
{
if (isdigit(optarg[0])) {
conn_uid = atoi(optarg);
} else
{
} else {
struct passwd *pwd = getpwnam(optarg);
if (pwd == NULL)
{
if (pwd == NULL) {
fprintf(stderr, "Unknown user: %s\n",
optarg);
return 1;
}
conn_uid = pwd->pw_uid;
data.uid = pwd->pw_uid;
}
break;
case 'u':
if (isdigit(optarg[0]))
{
if (isdigit(optarg[0])) {
data.uid = atoi(optarg);
} else
{
} else {
struct passwd *pwd = getpwnam(optarg);
if (pwd == NULL)
{
if (pwd == NULL) {
fprintf(stderr, "Unknown user: %s\n",
optarg);
return 1;
@@ -254,14 +202,11 @@ main(int argc, char *argv[])
}
break;
case 'g':
if (isdigit(optarg[0]))
{
if (isdigit(optarg[0])) {
data.gid = atoi(optarg);
} else
{
} else {
struct group *grp = getgrnam(optarg);
if (grp == NULL)
{
if (grp == NULL) {
fprintf(stderr, "Unknown group: %s\n",
optarg);
return 1;
@@ -276,16 +221,14 @@ main(int argc, char *argv[])
data.dir_mode = strtol(optarg, NULL, 8);
break;
case 'P':
if (strlen(optarg) >= sizeof(spec->password))
{
if (strlen(optarg) >= sizeof(spec->password)) {
printf("password too long\n");
exit(1);
}
password = optarg;
break;
case 'V':
if (strlen(optarg) >= sizeof(data.mounted_vol))
{
if (strlen(optarg) >= sizeof(data.mounted_vol)) {
printf("Volume too long: %s\n", optarg);
exit(1);
}
@@ -313,51 +256,39 @@ main(int argc, char *argv[])
}
}
if ((spec = ncp_find_conn_spec(server, user, password, 1, data.uid, &err))
== NULL)
{
if ((spec = ncp_find_conn_spec(server, user, password,
1, data.uid, &err))
== NULL) {
com_err(progname, err, "in find_conn_spec");
exit(1);
}
if (upcase_password != 0)
{
if (upcase_password != 0) {
str_upper(spec->password);
}
if (optind != argc - 1)
{
if (optind != argc - 1) {
usage();
return -1;
}
realpath(argv[optind], mount_point);
if (stat(mount_point, &st) == -1)
{
if (stat(mount_point, &st) == -1) {
fprintf(stderr, "could not find mount point %s: %s\n",
mount_point, strerror(errno));
exit(1);
}
if (mount_ok(&st) != 0)
{
if (mount_ok(&st) != 0) {
fprintf(stderr, "cannot to mount on %s: %s\n",
mount_point, strerror(errno));
exit(1);
}
#ifndef HAVE_KERNELD
/* Check if the ncpfs filesystem is in the kernel. If not, attempt
* to load the ncpfs module */
if (load_ncpfs() != 0)
{
fprintf(stderr, "Error: Unable to load ncpfs, exiting...\n");
exit(1);
}
#if NCP_MOUNT_VERSION < 3
#error "Use Linux 2.1.29 with patch applied !!!"
#endif
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)
{
if (data.dir_mode == 0) {
data.dir_mode = data.file_mode;
if ((data.dir_mode & S_IRUSR) != 0)
data.dir_mode |= S_IXUSR;
@@ -366,32 +297,18 @@ main(int argc, char *argv[])
if ((data.dir_mode & S_IROTH) != 0)
data.dir_mode |= S_IXOTH;
}
if ((tmp_mount = ncp_find_permanent(spec)) != NULL)
{
fprintf(stderr,
"You already have mounted server %s\nas user "
"%s\non mount point %s\n", spec->server, spec->user,
tmp_mount);
exit(1);
}
if ((server_addr = ncp_find_fileserver(spec->server, &err)) == NULL)
{
if ((server_addr = ncp_find_fileserver(spec->server, &err)) == NULL) {
com_err("ncpmount", err, "when trying to find %s",
spec->server);
exit(1);
}
data.serv_addr = *server_addr;
data.ncp_fd = socket(AF_IPX, SOCK_DGRAM, PF_IPX);
if (data.ncp_fd == -1)
{
if (data.ncp_fd == -1) {
com_err("ncpmount", err, "opening ncp_socket");
exit(1);
}
data.wdog_fd = socket(AF_IPX, SOCK_DGRAM, PF_IPX);
if (data.wdog_fd == -1)
{
wdog_fd = socket(AF_IPX, SOCK_DGRAM, PF_IPX);
if (wdog_fd == -1) {
fprintf(stderr, "could not open wdog socket: %s\n",
strerror(errno));
exit(1);
@@ -399,55 +316,46 @@ main(int argc, char *argv[])
memzero(addr);
addr.sipx_type = NCP_PTYPE;
if (bind(data.ncp_fd, (struct sockaddr *) &addr, sizeof(addr)) == -1)
{
if (bind(data.ncp_fd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {
fprintf(stderr, "\nbind: %s\n",
strerror(errno));
fprintf(stderr,
"\nMaybe you want to use \n"
"ipx_configure --auto_interface=on --auto_primary=on\n"
"ipx_configure --auto_interface=on --auto_primary=on\n"
"and try again after waiting a minute.\n\n");
exit(1);
}
addrlen = sizeof(addr);
if (getsockname(data.ncp_fd, (struct sockaddr *) &addr, &addrlen) == -1)
{
if (getsockname(data.ncp_fd,
(struct sockaddr *) &addr, &addrlen) == -1) {
perror("getsockname ncp socket");
close(data.ncp_fd);
close(data.wdog_fd);
close(wdog_fd);
exit(1);
}
addr.sipx_port = htons(ntohs(addr.sipx_port) + 1);
if (bind(data.wdog_fd, (struct sockaddr *) &addr, sizeof(addr)) == -1)
{
if (bind(wdog_fd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {
fprintf(stderr, "bind(wdog_sock, ): %s\n",
strerror(errno));
exit(1);
}
#if NCP_MOUNT_VERSION>1
data.message_fd = socket(AF_IPX, SOCK_DGRAM, PF_IPX);
if (data.message_fd == -1)
{
msg_fd = socket(AF_IPX, SOCK_DGRAM, PF_IPX);
if (msg_fd == -1) {
fprintf(stderr, "could not open message socket: %s\n",
strerror(errno));
exit(1);
}
addr.sipx_port = htons(ntohs(addr.sipx_port) + 1);
if (bind(data.message_fd, (struct sockaddr *) &addr, sizeof(addr)) == -1)
{
if (bind(msg_fd, (struct sockaddr *) &addr, sizeof(addr)) == -1) {
fprintf(stderr, "bind(message_sock, ): %s\n",
strerror(errno));
exit(1);
}
if (strlen(mount_point) < sizeof(data.mount_point))
{
strcpy(data.mount_point, mount_point);
}
#endif
connect(data.ncp_fd,
(struct sockaddr *) server_addr, sizeof(*server_addr));
flags = MS_MGC_VAL;
@@ -455,27 +363,33 @@ main(int argc, char *argv[])
strcat(mount_name, "/");
strcat(mount_name, spec->user);
data.wdog_pid = fork();
if (data.wdog_pid < 0) {
fprintf(stderr, "could not fork: %s\n", strerror(errno));
exit(1);
}
if (data.wdog_pid == 0) {
/* Child */
inststr(argv, argc, "ncpd");
process_connection(wdog_fd, msg_fd);
}
result = mount(mount_name, mount_point, "ncpfs", flags, (char *) &data);
if (result < 0)
{
if (result < 0) {
printf("mount failed\n");
exit(1);
}
if ((conn = ncp_open_mount(mount_point, &err)) == NULL)
{
if ((conn = ncp_open_mount(mount_point, &err)) == NULL) {
com_err("ncpmount", err, "attempt to open mount point");
umount(mount_point);
exit(1);
}
if ((err = ncp_login_user(conn, spec->user, spec->password)) != 0)
{
if ((err = ncp_login_user(conn, spec->user, spec->password)) != 0) {
struct nw_property p;
struct ncp_prop_login_control *l
= (struct ncp_prop_login_control *) &p;
if (conn->completion != NCP_GRACE_PERIOD)
{
if (conn->completion != NCP_GRACE_PERIOD) {
com_err("ncpmount", err, "in login");
fprintf(stderr, "Login denied\n");
ncp_close(conn);
@@ -486,14 +400,12 @@ main(int argc, char *argv[])
if ((err = ncp_read_property_value(conn, NCP_BINDERY_USER,
spec->user, 1,
"LOGIN_CONTROL", &p)) == 0)
{
"LOGIN_CONTROL", &p)) == 0) {
fprintf(stderr, "You have %d login attempts left\n",
l->GraceLogins);
}
}
if ((err = ioctl(conn->mount_fid, NCP_IOC_CONN_LOGGED_IN, NULL)) != 0)
{
if ((err = ioctl(conn->mount_fid, NCP_IOC_CONN_LOGGED_IN, NULL)) != 0) {
com_err("ncpmount", err, "in logged_indication");
ncp_close(conn);
umount(mount_point);
@@ -508,47 +420,40 @@ main(int argc, char *argv[])
ment.mnt_freq = 0;
ment.mnt_passno = 0;
if ((fd = open(MOUNTED "~", O_RDWR | O_CREAT | O_EXCL, 0600)) == -1)
{
if ((fd = open(MOUNTED "~", O_RDWR | O_CREAT | O_EXCL, 0600)) == -1) {
fprintf(stderr, "Can't get " MOUNTED "~ lock file");
exit(1);
}
close(fd);
if ((mtab = setmntent(MOUNTED, "a+")) == NULL)
{
if ((mtab = setmntent(MOUNTED, "a+")) == NULL) {
fprintf(stderr, "Can't open " MOUNTED);
exit(1);
}
if (addmntent(mtab, &ment) == 1)
{
if (addmntent(mtab, &ment) == 1) {
fprintf(stderr, "Can't write mount entry");
exit(1);
}
if (fchmod(fileno(mtab), 0644) == -1)
{
if (fchmod(fileno(mtab), 0644) == -1) {
fprintf(stderr, "Can't set perms on " MOUNTED);
exit(1);
}
endmntent(mtab);
if (unlink(MOUNTED "~") == -1)
{
if (unlink(MOUNTED "~") == -1) {
fprintf(stderr, "Can't remove " MOUNTED "~");
exit(1);
}
return 0;
}
static void
usage(void)
static void usage(void)
{
printf("usage: %s [options] mount-point\n", progname);
printf("Try `%s -h' for more information\n", progname);
}
static void
help(void)
static void help(void)
{
printf("\n");
printf("usage: %s [options] mount-point\n", progname);
@@ -558,9 +463,9 @@ help(void)
"-V volume Volume to mount, for NFS re-export\n"
"-u uid uid the mounted files get\n"
"-g gid gid the mounted files get\n"
"-f mode permission the files get (octal notation)\n"
"-f mode permission the files get (octal notation)\n"
"-d mode permission the dirs get (octal notation)\n"
"-c uid uid to identify the connection to mount on\n"
"-c uid uid to identify the connection to mount on\n"
" Only makes sense for root\n"
"-t time_out Waiting time (in 1/100s) to wait for\n"
" an answer from the server. Default: 60\n"
@@ -574,3 +479,219 @@ help(void)
"-v print ncpfs version number\n"
"\n");
}
/* 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;
}
static void msg_received(void)
{
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;
long err;
openlog("nwmsg", LOG_PID, LOG_LPR);
if ((conn = ncp_open_mount(mount_point, &err)) == NULL) {
return;
}
if (ncp_get_broadcast_message(conn, message) != 0) {
ncp_close(conn);
return;
}
if (strlen(message) == 0) {
syslog(LOG_DEBUG, "no message");
ncp_close(conn);
return;
}
syslog(LOG_DEBUG, "message: %s", message);
info.version = NCP_GET_FS_INFO_VERSION;
if (ioctl(conn->mount_fid, NCP_IOC_GET_FS_INFO, &info) < 0) {
ncp_close(conn);
return;
}
ncp_close(conn);
if ((pwd = getpwuid(info.mounted_uid)) == NULL) {
fprintf(stderr, "%s: user %d not known\n",
progname, info.mounted_uid);
return;
}
if ((mtab = fopen(MOUNTED, "r")) == NULL) {
fprintf(stderr, "%s: can't open %s\n",
progname, MOUNTED);
return;
}
while ((mnt = getmntent(mtab)) != NULL) {
if (strcmp(mnt->mnt_dir, mount_point) == 0) {
break;
}
}
if (mnt == NULL) {
syslog(LOG_DEBUG, "cannot find mtab entry\n");
}
if (search_utmp(pwd->pw_name, tty) != 0) {
return;
}
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));
return;
}
fprintf(tty_file, "\r\n\007\007\007Message from NetWare Server: %s\r\n",
mnt->mnt_fsname);
fprintf(tty_file, "%s\r\n", message);
fclose(tty_file);
fclose(mtab);
return;
}
static void process_msg_packet(int msg_fd)
{
struct sockaddr_ipx sender;
int addrlen = sizeof(sender);
char buf[1024];
if (recvfrom(msg_fd, buf, sizeof(buf), MSG_DONTWAIT,
(struct sockaddr *) &sender, &addrlen) <= 0) {
return;
}
msg_received();
}
static void process_wdog_packet(int wdog_fd)
{
struct sockaddr_ipx sender;
int addrlen = sizeof(sender);
char buf[2];
if (recvfrom(wdog_fd, buf, sizeof(buf), MSG_DONTWAIT,
(struct sockaddr *) &sender, &addrlen) < sizeof(buf)) {
return;
}
if (buf[1] != '?') {
return;
}
buf[1] = 'Y';
sendto(wdog_fd, buf, 2, 0, (struct sockaddr *) &sender, addrlen);
}
static int process_connection(int wdog_fd, int msg_fd)
{
int i;
int result;
int max;
chdir("/");
setsid();
for (i = 0; i < NR_OPEN; i++) {
if ((i == wdog_fd) || (i == msg_fd)) {
continue;
}
close(i);
}
max = (wdog_fd > msg_fd ? wdog_fd : msg_fd) + 1;
while (1) {
fd_set rd;
FD_ZERO(&rd);
FD_SET(wdog_fd, &rd);
FD_SET(msg_fd, &rd);
if ((result = select(max, &rd, NULL, NULL, NULL)) == -1) {
exit(0);
}
if (FD_ISSET(wdog_fd, &rd)) {
process_wdog_packet(wdog_fd);
}
if (FD_ISSET(msg_fd, &rd)) {
process_msg_packet(msg_fd);
}
}
}

View File

@@ -16,7 +16,7 @@
#include <netdb.h>
#include <sys/stat.h>
#include <sys/types.h>
/* #include <sys/wait.h> *//* generates a warning here */
/* #include <sys/wait.h> *//* generates a warning here */
extern pid_t waitpid(pid_t, int *, int);
#include <sys/errno.h>
#include <unistd.h>
@@ -35,33 +35,28 @@ extern pid_t waitpid(pid_t, int *, int);
static char *progname;
static void
usage(void)
static void usage(void)
{
printf("usage: %s mount-point\n", progname);
}
static int
umount_ok(const char *mount_point)
static int umount_ok(const char *mount_point)
{
int fid = open(mount_point, O_RDONLY, 0);
uid_t mount_uid;
if (fid == -1)
{
if (fid == -1) {
fprintf(stderr, "Could not open %s: %s\n",
mount_point, strerror(errno));
return -1;
}
if (ioctl(fid, NCP_IOC_GETMOUNTUID, &mount_uid) != 0)
{
if (ioctl(fid, NCP_IOC_GETMOUNTUID, &mount_uid) != 0) {
fprintf(stderr, "%s probably not ncp-filesystem\n",
mount_point);
return -1;
}
if ((getuid() != 0)
&& (mount_uid != getuid()))
{
&& (mount_uid != getuid())) {
fprintf(stderr, "You are not allowed to umount %s\n",
mount_point);
return -1;
@@ -76,7 +71,7 @@ umount_ok(const char *mount_point)
is not a legal pathname for ``/dev/fd0.'' Anything we cannot parse
we return unmodified. */
char *
canonicalize(const char *path)
canonicalize(const char *path)
{
char *canonical = malloc(PATH_MAX + 1);
@@ -86,8 +81,7 @@ canonicalize(const char *path)
if (realpath(path, canonical))
return canonical;
if (strlen(path) > PATH_MAX)
{
if (strlen(path) > PATH_MAX) {
return NULL;
}
strcpy(canonical, path);
@@ -95,8 +89,7 @@ canonicalize(const char *path)
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
int fd;
@@ -108,83 +101,70 @@ main(int argc, char *argv[])
progname = argv[0];
if (geteuid() != 0)
{
if (geteuid() != 0) {
fprintf(stderr, "%s must be installed suid root\n", progname);
exit(1);
}
if (argc != 2)
{
if (argc != 2) {
usage();
exit(1);
}
mount_point = canonicalize(argv[1]);
if (mount_point == NULL)
{
if (mount_point == NULL) {
fprintf(stderr, "Invalid mount point: %s\n", argv[1]);
exit(1);
}
if (umount_ok(mount_point) != 0)
{
if (umount_ok(mount_point) != 0) {
fprintf(stderr, "You are not allowed to umount %s\n",
mount_point);
exit(1);
}
if (umount(mount_point) != 0)
{
if (umount(mount_point) != 0) {
fprintf(stderr, "Could not umount %s: %s\n",
mount_point, strerror(errno));
exit(1);
}
if ((fd = open(MOUNTED "~", O_RDWR | O_CREAT | O_EXCL, 0600)) == -1)
{
if ((fd = open(MOUNTED "~", O_RDWR | O_CREAT | O_EXCL, 0600)) == -1) {
fprintf(stderr, "Can't get " MOUNTED "~ lock file");
return 1;
}
close(fd);
if ((mtab = setmntent(MOUNTED, "r")) == NULL)
{
if ((mtab = setmntent(MOUNTED, "r")) == NULL) {
fprintf(stderr, "Can't open " MOUNTED ": %s\n",
strerror(errno));
return 1;
}
#define MOUNTED_TMP MOUNTED".tmp"
if ((new_mtab = setmntent(MOUNTED_TMP, "w")) == NULL)
{
if ((new_mtab = setmntent(MOUNTED_TMP, "w")) == NULL) {
fprintf(stderr, "Can't open " MOUNTED_TMP ": %s\n",
strerror(errno));
endmntent(mtab);
return 1;
}
while ((mnt = getmntent(mtab)) != NULL)
{
if (strcmp(mnt->mnt_dir, mount_point) != 0)
{
while ((mnt = getmntent(mtab)) != NULL) {
if (strcmp(mnt->mnt_dir, mount_point) != 0) {
addmntent(new_mtab, mnt);
}
}
endmntent(mtab);
if (fchmod(fileno(new_mtab), S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) < 0)
{
if (fchmod(fileno(new_mtab), S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) < 0) {
fprintf(stderr, "Error changing mode of %s: %s\n",
MOUNTED_TMP, strerror(errno));
exit(1);
}
endmntent(new_mtab);
if (rename(MOUNTED_TMP, MOUNTED) < 0)
{
if (rename(MOUNTED_TMP, MOUNTED) < 0) {
fprintf(stderr, "Cannot rename %s to %s: %s\n",
MOUNTED, MOUNTED_TMP, strerror(errno));
exit(1);
}
if (unlink(MOUNTED "~") == -1)
{
if (unlink(MOUNTED "~") == -1) {
fprintf(stderr, "Can't remove " MOUNTED "~");
return 1;
}

View File

@@ -92,20 +92,20 @@ typedef unsigned char buf4[4];
static unsigned char encrypttable[256] =
{0x7, 0x8, 0x0, 0x8, 0x6, 0x4, 0xE, 0x4, 0x5, 0xC, 0x1, 0x7, 0xB, 0xF, 0xA, 0x8,
0xF, 0x8, 0xC, 0xC, 0x9, 0x4, 0x1, 0xE, 0x4, 0x6, 0x2, 0x4, 0x0, 0xA, 0xB, 0x9,
0x2, 0xF, 0xB, 0x1, 0xD, 0x2, 0x1, 0x9, 0x5, 0xE, 0x7, 0x0, 0x0, 0x2, 0x6, 0x6,
0x0, 0x7, 0x3, 0x8, 0x2, 0x9, 0x3, 0xF, 0x7, 0xF, 0xC, 0xF, 0x6, 0x4, 0xA, 0x0,
0x2, 0x3, 0xA, 0xB, 0xD, 0x8, 0x3, 0xA, 0x1, 0x7, 0xC, 0xF, 0x1, 0x8, 0x9, 0xD,
0x9, 0x1, 0x9, 0x4, 0xE, 0x4, 0xC, 0x5, 0x5, 0xC, 0x8, 0xB, 0x2, 0x3, 0x9, 0xE,
0x7, 0x7, 0x6, 0x9, 0xE, 0xF, 0xC, 0x8, 0xD, 0x1, 0xA, 0x6, 0xE, 0xD, 0x0, 0x7,
0x7, 0xA, 0x0, 0x1, 0xF, 0x5, 0x4, 0xB, 0x7, 0xB, 0xE, 0xC, 0x9, 0x5, 0xD, 0x1,
0xB, 0xD, 0x1, 0x3, 0x5, 0xD, 0xE, 0x6, 0x3, 0x0, 0xB, 0xB, 0xF, 0x3, 0x6, 0x4,
0x9, 0xD, 0xA, 0x3, 0x1, 0x4, 0x9, 0x4, 0x8, 0x3, 0xB, 0xE, 0x5, 0x0, 0x5, 0x2,
0xC, 0xB, 0xD, 0x5, 0xD, 0x5, 0xD, 0x2, 0xD, 0x9, 0xA, 0xC, 0xA, 0x0, 0xB, 0x3,
0x5, 0x3, 0x6, 0x9, 0x5, 0x1, 0xE, 0xE, 0x0, 0xE, 0x8, 0x2, 0xD, 0x2, 0x2, 0x0,
0x4, 0xF, 0x8, 0x5, 0x9, 0x6, 0x8, 0x6, 0xB, 0xA, 0xB, 0xF, 0x0, 0x7, 0x2, 0x8,
0xC, 0x7, 0x3, 0xA, 0x1, 0x4, 0x2, 0x5, 0xF, 0x7, 0xA, 0xC, 0xE, 0x5, 0x9, 0x3,
0xE, 0x7, 0x1, 0x2, 0xE, 0x1, 0xF, 0x4, 0xA, 0x6, 0xC, 0x6, 0xF, 0x4, 0x3, 0x0,
0xF, 0x8, 0xC, 0xC, 0x9, 0x4, 0x1, 0xE, 0x4, 0x6, 0x2, 0x4, 0x0, 0xA, 0xB, 0x9,
0x2, 0xF, 0xB, 0x1, 0xD, 0x2, 0x1, 0x9, 0x5, 0xE, 0x7, 0x0, 0x0, 0x2, 0x6, 0x6,
0x0, 0x7, 0x3, 0x8, 0x2, 0x9, 0x3, 0xF, 0x7, 0xF, 0xC, 0xF, 0x6, 0x4, 0xA, 0x0,
0x2, 0x3, 0xA, 0xB, 0xD, 0x8, 0x3, 0xA, 0x1, 0x7, 0xC, 0xF, 0x1, 0x8, 0x9, 0xD,
0x9, 0x1, 0x9, 0x4, 0xE, 0x4, 0xC, 0x5, 0x5, 0xC, 0x8, 0xB, 0x2, 0x3, 0x9, 0xE,
0x7, 0x7, 0x6, 0x9, 0xE, 0xF, 0xC, 0x8, 0xD, 0x1, 0xA, 0x6, 0xE, 0xD, 0x0, 0x7,
0x7, 0xA, 0x0, 0x1, 0xF, 0x5, 0x4, 0xB, 0x7, 0xB, 0xE, 0xC, 0x9, 0x5, 0xD, 0x1,
0xB, 0xD, 0x1, 0x3, 0x5, 0xD, 0xE, 0x6, 0x3, 0x0, 0xB, 0xB, 0xF, 0x3, 0x6, 0x4,
0x9, 0xD, 0xA, 0x3, 0x1, 0x4, 0x9, 0x4, 0x8, 0x3, 0xB, 0xE, 0x5, 0x0, 0x5, 0x2,
0xC, 0xB, 0xD, 0x5, 0xD, 0x5, 0xD, 0x2, 0xD, 0x9, 0xA, 0xC, 0xA, 0x0, 0xB, 0x3,
0x5, 0x3, 0x6, 0x9, 0x5, 0x1, 0xE, 0xE, 0x0, 0xE, 0x8, 0x2, 0xD, 0x2, 0x2, 0x0,
0x4, 0xF, 0x8, 0x5, 0x9, 0x6, 0x8, 0x6, 0xB, 0xA, 0xB, 0xF, 0x0, 0x7, 0x2, 0x8,
0xC, 0x7, 0x3, 0xA, 0x1, 0x4, 0x2, 0x5, 0xF, 0x7, 0xA, 0xC, 0xE, 0x5, 0x9, 0x3,
0xE, 0x7, 0x1, 0x2, 0xE, 0x1, 0xF, 0x4, 0xA, 0x6, 0xC, 0x6, 0xF, 0x4, 0x3, 0x0,
0xC, 0x0, 0x3, 0x6, 0xF, 0x8, 0x7, 0xB, 0x2, 0xD, 0xC, 0x6, 0xA, 0xA, 0x8, 0xD};
static buf32 encryptkeys =
@@ -115,8 +115,7 @@ static buf32 encryptkeys =
0xF4, 0x47, 0xDC, 0xA7, 0xEC, 0xCF, 0x50, 0xC0};
static void
shuffle1(buf32 temp, unsigned char *target)
static void shuffle1(buf32 temp, unsigned char *target)
{
short b4;
unsigned char b3;
@@ -124,63 +123,51 @@ shuffle1(buf32 temp, unsigned char *target)
b4 = 0;
for (b2 = 0; b2 <= 1; ++b2)
{
for (s = 0; s <= 31; ++s)
{
for (b2 = 0; b2 <= 1; ++b2) {
for (s = 0; s <= 31; ++s) {
b3 = (temp[s] + b4) ^ (temp[(s + b4) & 31] - encryptkeys[s]);
b4 = b4 + b3;
temp[s] = b3;
}
}
for (i = 0; i <= 15; ++i)
{
for (i = 0; i <= 15; ++i) {
target[i] = encrypttable[temp[2 * i]]
| (encrypttable[temp[2 * i + 1]] << 4);
}
}
static void
shuffle(const unsigned char *lon, const unsigned char *buf, int buflen,
unsigned char *target)
static void shuffle(const unsigned char *lon, const unsigned char *buf, int buflen,
unsigned char *target)
{
int b2, d, s;
buf32 temp;
while ((buflen > 0)
&& (buf[buflen - 1] == 0))
{
&& (buf[buflen - 1] == 0)) {
buflen = buflen - 1;
}
for (s = 0; s < 32; s++)
{
for (s = 0; s < 32; s++) {
temp[s] = 0;
}
d = 0;
while (buflen >= 32)
{
for (s = 0; s <= 31; ++s)
{
while (buflen >= 32) {
for (s = 0; s <= 31; ++s) {
temp[s] = temp[s] ^ buf[d];
d = d + 1;
}
buflen = buflen - 32;
}
b2 = d;
if (buflen > 0)
{
for (s = 0; s <= 31; ++s)
{
if (d + buflen == b2)
{
if (buflen > 0) {
for (s = 0; s <= 31; ++s) {
if (d + buflen == b2) {
b2 = d;
temp[s] = temp[s] ^ encryptkeys[s];
} else
{
} else {
temp[s] = temp[s] ^ buf[b2];
b2 = b2 + 1;
}
@@ -193,10 +180,9 @@ shuffle(const unsigned char *lon, const unsigned char *buf, int buflen,
}
static void
nw_encrypt(const unsigned char *fra,
const unsigned char *buf,
unsigned char *til)
static void nw_encrypt(const unsigned char *fra,
const unsigned char *buf,
unsigned char *til)
{
buf32 k;
int s;

View File

@@ -16,14 +16,12 @@
static char *progname;
static void
usage(void)
static void usage(void)
{
fprintf(stderr, "usage: %s [server]\n", progname);
}
static void
help(void)
static void help(void)
{
printf("\n");
printf("usage: %s [server]\n", progname);
@@ -33,8 +31,7 @@ help(void)
"\n");
}
static void
swallow_error(const char *name, long code, const char *format, va_list arg)
static void swallow_error(const char *name, long code, const char *format, va_list arg)
{
printf("%s ", error_message(code));
vfprintf(stdout, format, arg);
@@ -42,8 +39,7 @@ swallow_error(const char *name, long code, const char *format, va_list arg)
return;
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
char *server = NULL;
int object_type = NCP_BINDERY_FSERVER;
@@ -56,10 +52,8 @@ main(int argc, char *argv[])
set_com_err_hook(swallow_error);
while ((opt = getopt(argc, argv, "t:")) != EOF)
{
switch (opt)
{
while ((opt = getopt(argc, argv, "t:")) != EOF) {
switch (opt) {
case 't':
object_type = atoi(optarg);
break;
@@ -73,24 +67,20 @@ main(int argc, char *argv[])
}
}
if (optind < argc - 1)
{
if (optind < argc - 1) {
usage();
exit(1);
}
if (optind == argc - 1)
{
if (optind == argc - 1) {
server = argv[optind];
if (strlen(server) >= NCP_BINDERY_NAME_LEN)
{
if (strlen(server) >= NCP_BINDERY_NAME_LEN) {
com_err(argv[0], ENAMETOOLONG, "server name too long");
exit(1);
}
}
result = ncp_find_server(&server, object_type, &err);
if (result == NULL)
{
if (result == NULL) {
com_err(argv[0], err, "when trying to find server");
exit(1);
}

View File

@@ -7,7 +7,6 @@ USERUTILS += nwbols nwbocreate nwborm nwboprops
USERUTILS += nwbpcreate nwbprm nwbpvalues nwbpadd nwbpset
USERUTILS += nwgrant nwrevoke nwuserlist nwrights nwauth
USERUTILS += nwfstime nwvolinfo nwtrustee
SBINUTILS = nwmsg
UTILS = $(USERUTILS) $(SBINUTILS) ncptest
@@ -23,7 +22,7 @@ endif
default:
make -C ..
all: $(UTILS) ncptest
all: $(UTILS) ncptest # ipx_probe
install: all
for i in $(USERUTILS); \
@@ -34,6 +33,9 @@ install: all
$(UTILS): %: %.o $(LIBDEP)
$(CC) -o $@ $(addsuffix .o,$@) -L../lib -lncp
ipx_probe: ipx_probe.c
$(CC) $(CFLAGS) -o ipx_probe ipx_probe.c
dep:
$(CPP) -M $(INCLUDES) *.c > .depend

BIN
util/ipx_probe Executable file

Binary file not shown.

407
util/ipx_probe.c Normal file
View File

@@ -0,0 +1,407 @@
/*
* ipx_probe.c
*
* Check the network for frames currently active
*
* Copyright (C) 1996 by Volker Lendecke
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <linux/ipx.h>
#include <linux/if.h>
#include <unistd.h>
#include <string.h>
#include <netinet/in.h>
static char *progname;
int verbose = 0;
static void usage()
{
fprintf(stderr, "usage: %s [options]\n", progname);
fprintf(stderr, "type '%s -h' for help\n", progname);
}
static void help()
{
printf("\n"
"Probe an interface for ipx networks\n"
"\n");
printf("usage: %s [options]\n", progname);
printf("\n"
"-v Verbose output\n"
"-i interface Interface to probe, default: eth0\n"
"-t timeout Seconds to wait for answer, default: 3\n"
"-h Print this help text\n\n");
}
#define IPX_SAP_PTYPE (0x04)
#define IPX_SAP_NEAREST_QUERY (0x0003)
#define IPX_SAP_PORT (0x0452)
#define IPX_BROADCAST_NODE ("\xff\xff\xff\xff\xff\xff")
#define BVAL(buf,pos) (((__u8 *)(buf))[pos])
#define BSET(buf,pos,val) (BVAL(buf,pos) = (val))
static inline void WSET_HL(__u8 * buf, int pos, __u16 val)
{
BSET(buf, pos, val >> 8);
BSET(buf, pos + 1, val & 0xff);
}
struct frame_type {
char *ft_name;
unsigned char ft_val;
};
static struct frame_type frame_types[] =
{
{
"802.2", IPX_FRAME_8022
}
,
#ifdef IPX_FRAME_TR_8022
{
"802.2TR", IPX_FRAME_TR_8022
}
,
#endif
{
"802.3", IPX_FRAME_8023
}
,
{
"SNAP", IPX_FRAME_SNAP
}
,
{
"EtherII", IPX_FRAME_ETHERII
}
};
#define NFTYPES (sizeof(frame_types)/sizeof(struct frame_type))
static char *
frame_name(int frame_type)
{
int i;
for (i = 0; i < NFTYPES; i++) {
if (frame_types[i].ft_val == frame_type) {
return frame_types[i].ft_name;
}
}
return NULL;
}
static int ipx_recvfrom(int sock, void *buf, int len, unsigned int flags,
struct sockaddr_ipx *sender, int *addrlen, int timeout,
long *err)
{
fd_set rd, wr, ex;
struct timeval tv;
int result;
FD_ZERO(&rd);
FD_ZERO(&wr);
FD_ZERO(&ex);
FD_SET(sock, &rd);
tv.tv_sec = timeout;
tv.tv_usec = 0;
if ((result = select(sock + 1, &rd, &wr, &ex, &tv)) == -1) {
*err = errno;
return -1;
}
if (FD_ISSET(sock, &rd)) {
result = recvfrom(sock, buf, len, flags,
(struct sockaddr *) sender, addrlen);
} else {
result = -1;
errno = ETIMEDOUT;
}
if (result < 0) {
*err = errno;
}
return result;
}
static int ipx_recv(int sock, void *buf, int len, unsigned int flags, int timeout,
long *err)
{
struct sockaddr_ipx sender;
int addrlen = sizeof(sender);
return ipx_recvfrom(sock, buf, len, flags, &sender, &addrlen,
timeout, err);
}
static int probe_frame(char *interface, int frame_type, int timeout, unsigned long *net)
{
int i, sock, opt;
int result;
long err;
char errmsg[strlen(progname) + 20];
char data[1024];
static struct ifreq id;
struct sockaddr_ipx *sipx = (struct sockaddr_ipx *) &id.ifr_addr;
if (verbose != 0) {
printf("probing %s on %s -- ", frame_name(frame_type),
interface);
fflush(stdout);
}
sock = socket(AF_IPX, SOCK_DGRAM, AF_IPX);
if (sock < 0) {
int old_errno = errno;
sprintf(errmsg, "%s: socket", progname);
perror(errmsg);
if (old_errno == -EINVAL) {
fprintf(stderr, "Probably you have no IPX support in "
"your kernel\n");
}
close(sock);
return -1;
}
memset(&id, 0, sizeof(id));
strncpy(id.ifr_name, interface, sizeof(id.ifr_name) - 1);
sipx->sipx_family = AF_IPX;
sipx->sipx_action = IPX_CRTITF;
sipx->sipx_special = IPX_PRIMARY;
sipx->sipx_network = 0L;
sipx->sipx_type = frame_type;
i = 0;
do {
result = ioctl(sock, SIOCSIFADDR, &id);
i++;
}
while ((i < 5) && (result < 0) && (errno == EAGAIN));
if (result < 0) {
int old_errno = errno;
close(sock);
errno = old_errno;
return result;
}
/* We do a GNS request on the new socket. If something comes
back, we assume that the frame type is valid. */
opt = 1;
if ((result = setsockopt(sock, SOL_SOCKET,
SO_BROADCAST, &opt, sizeof(opt))) < 0) {
int old_errno = errno;
close(sock);
errno = old_errno;
return result;
}
memset(&id, 0, sizeof(id));
sipx->sipx_family = AF_IPX;
sipx->sipx_network = htonl(0x0);
sipx->sipx_port = htons(0x0);
sipx->sipx_type = IPX_SAP_PTYPE;
if ((result = bind(sock, (struct sockaddr *) sipx,
sizeof(*sipx))) < 0 - 1) {
int old_errno = errno;
close(sock);
errno = old_errno;
return result;
}
WSET_HL(data, 0, IPX_SAP_NEAREST_QUERY);
WSET_HL(data, 2, 4);
memset(&id, 0, sizeof(id));
sipx->sipx_family = AF_IPX;
sipx->sipx_port = htons(IPX_SAP_PORT);
sipx->sipx_type = IPX_SAP_PTYPE;
sipx->sipx_network = htonl(0x0);
memcpy(sipx->sipx_node, IPX_BROADCAST_NODE, 6);
if ((result = sendto(sock, data, 4, 0, (struct sockaddr *) sipx,
sizeof(*sipx))) < 0) {
int old_errno = errno;
close(sock);
errno = old_errno;
return result;
}
result = ipx_recv(sock, data, 1024, 0, timeout, &err);
if (result > 0) {
struct sockaddr_ipx sipx;
int namelen = sizeof(sipx);
if (getsockname(sock, (struct sockaddr *) &sipx,
&namelen) < 0) {
fprintf(stderr, "%s: Could not find socket address\n",
progname);
exit(1);
}
*net = ntohl(sipx.sipx_network);
}
memset(&id, 0, sizeof(id));
strncpy(id.ifr_name, interface, sizeof(id.ifr_name) - 1);
sipx->sipx_family = AF_IPX;
sipx->sipx_action = IPX_DLTITF;
sipx->sipx_network = 0L;
sipx->sipx_type = frame_type;
result = ioctl(sock, SIOCSIFADDR, &id);
close(sock);
if (result < 0) {
fprintf(stderr, "%s: could not delete interface\n",
progname);
exit(1);
}
if (err == ETIMEDOUT) {
if (verbose != 0) {
printf("no network found\n");
}
return -1;
}
if (verbose != 0) {
printf("found IPX network %8.8lX\n", *net);
}
return 0;
}
static int file_lines(char *name)
{
FILE *f = fopen(name, "r");
char buf[100];
int lines = 0;
if (f == NULL) {
return -errno;
}
while (fgets(buf, sizeof(buf), f) != NULL) {
lines += 1;
}
fclose(f);
return lines;
}
static int ipx_interfaces(void)
{
int result = file_lines("/proc/net/ipx_interface");
if (result == 0) {
result = -EIO;
}
return result - 1;
}
static int ipx_auto_off(void)
{
int s;
char errmsg[strlen(progname) + 20];
int val = 0;
s = socket(AF_IPX, SOCK_DGRAM, AF_IPX);
if (s < 0) {
int old_errno = errno;
sprintf(errmsg, "%s: socket", progname);
perror(errmsg);
if (old_errno == -EINVAL) {
fprintf(stderr, "Probably you have no IPX support in "
"your kernel\n");
}
close(s);
return -1;
}
sprintf(errmsg, "%s: ioctl", progname);
if (ioctl(s, SIOCAIPXPRISLT, &val) < 0) {
perror(errmsg);
close(s);
return -1;
}
if (ioctl(s, SIOCAIPXITFCRT, &val) < 0) {
perror(errmsg);
close(s);
return -1;
}
close(s);
return 0;
}
int main(int argc, char *argv[])
{
int interfaces;
char *interface = "eth0";
int opt;
int timeout = 3;
unsigned long network[5] =
{0,};
progname = argv[0];
while ((opt = getopt(argc, argv, "vi:ht:")) != EOF) {
switch (opt) {
case 'v':
verbose = 1;
break;
case 'i':
interface = optarg;
break;
case 't':
timeout = atoi(optarg);
break;
case 'h':
help();
exit(1);
default:
usage();
exit(1);
}
}
if (ipx_auto_off() < 0) {
exit(1);
}
interfaces = ipx_interfaces();
if (interfaces > 0) {
fprintf(stderr, "%s must be run with no interfaces configured."
" Found %d interface%s.\n",
progname, interfaces,
interfaces == 1 ? "" : "s");
exit(1);
}
if (interfaces < 0) {
fprintf(stderr, "%s: %s\n", progname, strerror(interfaces));
exit(1);
}
probe_frame(interface, IPX_FRAME_8022, timeout, &(network[0]));
probe_frame(interface, IPX_FRAME_8023, timeout, &(network[1]));
probe_frame(interface, IPX_FRAME_SNAP, timeout, &(network[2]));
probe_frame(interface, IPX_FRAME_ETHERII, timeout, &(network[3]));
if (verbose == 0) {
if (network[0] != 0) {
printf("%s %8.8lX\n",
frame_name(IPX_FRAME_8022), network[0]);
}
if (network[1] != 0) {
printf("%s %8.8lX\n",
frame_name(IPX_FRAME_8023), network[1]);
}
if (network[2] != 0) {
printf("%s %8.8lX\n",
frame_name(IPX_FRAME_SNAP), network[2]);
}
if (network[3] != 0) {
printf("%s %8.8lX\n",
frame_name(IPX_FRAME_ETHERII), network[3]);
}
}
return 0;
}

View File

@@ -25,8 +25,7 @@
#include "ncplib.h"
struct NCPMountRec
{
struct NCPMountRec {
char *mountDir;
char *server;
struct ncp_conn *conn;
@@ -71,8 +70,7 @@ static struct sigaction sTermSig;
/****************************************************************************
*
*/
static void
usage()
static void usage()
{
fprintf(stderr, "usage: %s [-V]\n", ProgramName);
fprintf(stderr, " %s [-vn] [-s amt] sourcefile destinationfile|directory\n", ProgramName);
@@ -86,19 +84,17 @@ usage()
* Return pointer to original string if no "/" in string. (except at end)
*/
static const char *
myBaseName(const char *path)
myBaseName(const char *path)
{
const char *p;
for (p = &path[strlen(path)]; p != path; p--)
{ /* skip ENDING "/" chars */
for (p = &path[strlen(path)]; p != path; p--) { /* skip ENDING "/" chars */
if (*p && *p != '/')
break;
}
if (p == path)
return p;
for (; p != path || *p == '/'; p--)
{
for (; p != path || *p == '/'; p--) {
if (*p == '/')
return ++p;
}
@@ -109,7 +105,7 @@ myBaseName(const char *path)
*
*/
static const char *
notDir(const char *path)
notDir(const char *path)
{
struct stat buf;
static const char *notDirectory = "not a directory";
@@ -124,15 +120,12 @@ notDir(const char *path)
/****************************************************************************
*
*/
static int
handleOptions(const int argc, char *const argv[])
static int handleOptions(const int argc, char *const argv[])
{
int opt;
while ((opt = getopt(argc, argv, "vVns:")) != EOF)
{
switch (opt)
{
while ((opt = getopt(argc, argv, "vVns:")) != EOF) {
switch (opt) {
case 'V': /* Version */
optVersion = 1;
@@ -149,8 +142,7 @@ handleOptions(const int argc, char *const argv[])
case 's': /* Nice Factor */
optNiceFactorSel = 1;
optNiceFactor = atoi(optarg);
if (optNiceFactor < 1)
{
if (optNiceFactor < 1) {
fprintf(stderr, "%s: -s option requires positive numeric argument > 0\n",
ProgramName);
return 1;
@@ -168,22 +160,18 @@ handleOptions(const int argc, char *const argv[])
/****************************************************************************
* TODO: if recursive flag last MUST be a directory, even if only 2 args.
*/
static int
validateFileArgs(const int argc, char *const argv[])
static int validateFileArgs(const int argc, char *const argv[])
{
const char *p;
if (argc == 0)
{
if (argc == 0) {
fprintf(stderr, "%s: No arguments specified.\n", ProgramName);
return 1;
}
if (argc == 1)
{
if (argc == 1) {
fprintf(stderr, "%s: No destination specified.\n", ProgramName);
return 1;
}
if ((argc > 2) && (p = notDir(argv[argc - 1])))
{ /* last arg MUST be dir */
if ((argc > 2) && (p = notDir(argv[argc - 1]))) { /* last arg MUST be dir */
fprintf(stderr, "%s: %s: %s\n", ProgramName, argv[argc - 1], p);
return 1;
}
@@ -194,7 +182,7 @@ validateFileArgs(const int argc, char *const argv[])
* Duplicate a string.
*/
char *
duplicateStr(const char *InStr)
duplicateStr(const char *InStr)
{
char *dup;
if (!InStr)
@@ -208,38 +196,31 @@ duplicateStr(const char *InStr)
/****************************************************************************
* load a table of ncpfs mount points.
*/
int
loadMountTable()
int loadMountTable()
{
FILE *mountedFile;
struct mntent *mountEntry = NULL;
ncpCount = 0;
if ((mountedFile = fopen(MOUNTED, "r")) == NULL)
{
if ((mountedFile = fopen(MOUNTED, "r")) == NULL) {
fprintf(stderr, "ncopy: cannot open %s, %s\n", MOUNTED, strerror(errno));
return 1;
}
while ((mountEntry = getmntent(mountedFile)) != NULL)
{
while ((mountEntry = getmntent(mountedFile)) != NULL) {
if (!strcmp(mountEntry->mnt_type, "ncpfs"))
ncpCount++;
}
if (ncpCount)
{
if (ncpCount) {
NcpMountTable = (struct NCPMountRec *)
malloc(ncpCount * sizeof(struct NCPMountRec));
if (!NcpMountTable)
{
if (!NcpMountTable) {
fprintf(stderr, "Out of memory\n");
fclose(mountedFile);
return 1;
}
fseek(mountedFile, 0, SEEK_SET);
ncpCount = 0;
while ((mountEntry = getmntent(mountedFile)) != NULL)
{
if (!strcmp(mountEntry->mnt_type, "ncpfs"))
{
while ((mountEntry = getmntent(mountedFile)) != NULL) {
if (!strcmp(mountEntry->mnt_type, "ncpfs")) {
NcpMountTable[ncpCount].mountDir = duplicateStr(mountEntry->mnt_dir);
NcpMountTable[ncpCount].server =
duplicateStr(mountEntry->mnt_fsname);
@@ -255,16 +236,13 @@ loadMountTable()
/****************************************************************************
* Releases the table of ncpfs mount points.
*/
void
releaseMountTable()
void releaseMountTable()
{
int loop;
if (!ncpCount)
return;
for (loop = ncpCount; loop; loop--, ncpCount--)
{
if (NcpMountTable[loop - 1].conn)
{
for (loop = ncpCount; loop; loop--, ncpCount--) {
if (NcpMountTable[loop - 1].conn) {
ncp_close(NcpMountTable[loop - 1].conn);
NcpMountTable[loop - 1].conn = NULL;
}
@@ -279,16 +257,14 @@ releaseMountTable()
* the file.
* Returns -1 if the files do not reference the same server.
*/
int
ncpIndex(const char *InputFile, const char *OutputFile)
int ncpIndex(const char *InputFile, const char *OutputFile)
{
int loop;
char *mountDir;
if (!ncpCount)
return -1;
for (loop = 0; loop < ncpCount; loop++)
{
for (loop = 0; loop < ncpCount; loop++) {
mountDir = NcpMountTable[loop].mountDir;
if (!strncmp(mountDir, InputFile, strlen(mountDir)) &&
!strncmp(mountDir, OutputFile, strlen(mountDir)))
@@ -302,46 +278,40 @@ ncpIndex(const char *InputFile, const char *OutputFile)
* Does a regular buffered file copy.
* This is used if we cannot use the Netware file copy.
*/
int
normalFileCopy(const char *InputFile, const char *OutputFile,
char *Buffer, int BufferSize,
const char *paramInputFile,
const char *paramOutputFile)
int normalFileCopy(const char *InputFile, const char *OutputFile,
char *Buffer, int BufferSize,
const char *paramInputFile,
const char *paramOutputFile)
{
int fdIn, fdOut;
long fileSize, totalSize;
struct stat statBuf;
fdIn = open(InputFile, O_RDONLY);
if (fdIn == -1)
{
if (fdIn == -1) {
fprintf(stderr, "%s: Cannot open %s, %s\n", ProgramName, paramInputFile,
strerror(errno));
return 1;
}
if (fstat(fdIn, &statBuf))
{
if (fstat(fdIn, &statBuf)) {
fprintf(stderr, "%s: Cannot stat %s, %s\n", ProgramName, paramInputFile,
strerror(errno));
close(fdIn);
return 1;
}
if (S_ISDIR(statBuf.st_mode))
{
if (S_ISDIR(statBuf.st_mode)) {
close(fdIn);
fprintf(stderr, "%s: %s: omitting directory\n", ProgramName, paramInputFile);
return 0; /* At this point, don't consider this a fatal error */
}
fdOut = open(OutputFile, O_CREAT | O_TRUNC | O_WRONLY, statBuf.st_mode);
if (fdOut == -1)
{
if (fdOut == -1) {
fprintf(stderr, "%s: Cannot create %s, %s\n", ProgramName, paramOutputFile,
strerror(errno));
close(fdIn);
return 1;
}
fileSize = lseek(fdIn, 0, SEEK_END);
if (fileSize < 0)
{
if (fileSize < 0) {
fprintf(stderr, "%s: lseek error on %s, %s\n", ProgramName, paramInputFile,
strerror(errno));
close(fdOut);
@@ -349,19 +319,16 @@ normalFileCopy(const char *InputFile, const char *OutputFile,
return 1;
}
lseek(fdIn, 0, SEEK_SET);
if (optVerbose)
{
if (optVerbose) {
printf("Normal copy: %s -> %s 0%%", paramInputFile, paramOutputFile);
fflush(stdout);
}
totalSize = fileSize;
while (fileSize)
{
while (fileSize) {
int currentMove;
int writeAmt;
currentMove = (fileSize > BufferSize) ? BufferSize : fileSize;
if (read(fdIn, Buffer, currentMove) != currentMove)
{
if (read(fdIn, Buffer, currentMove) != currentMove) {
fprintf(stderr, "%s: Error reading %s, %s\n", ProgramName, paramInputFile,
strerror(errno));
close(fdIn);
@@ -369,15 +336,13 @@ normalFileCopy(const char *InputFile, const char *OutputFile,
return 1;
}
writeAmt = write(fdOut, Buffer, currentMove);
if (writeAmt < 0)
{
if (writeAmt < 0) {
fprintf(stderr, "%s: Error writing %s, %s\n", ProgramName, paramOutputFile,
strerror(errno));
close(fdIn);
close(fdOut);
return 1;
} else if (writeAmt == 0)
{
} else if (writeAmt == 0) {
fprintf(stderr, "%s: Out of space on destination device writing %s\n",
ProgramName, OutputFile);
close(fdIn);
@@ -385,8 +350,7 @@ normalFileCopy(const char *InputFile, const char *OutputFile,
return 1;
}
fileSize -= currentMove;
if (optVerbose)
{
if (optVerbose) {
printf("\rNormal copy: %s -> %s %ld%%", paramInputFile, paramOutputFile, (100 - (fileSize * 100 / totalSize)));
fflush(stdout);
}
@@ -403,11 +367,10 @@ normalFileCopy(const char *InputFile, const char *OutputFile,
* Netware file names need to be all upper case.
*/
char *
upString(char *str)
upString(char *str)
{
char *alias = str;
while (*alias)
{
while (*alias) {
*alias = toupper(*alias);
++alias;
}
@@ -418,12 +381,10 @@ upString(char *str)
* Locates the first occurrance of a single character in the input string.
* returns -1 if the character is not found.
*/
int
stringPosition(const char *str, char token)
int stringPosition(const char *str, char token)
{
const char *alias = str;
while (*alias)
{
while (*alias) {
if (*alias == token)
return alias - str;
alias++;
@@ -437,8 +398,7 @@ stringPosition(const char *str, char token)
* This will mangle the input "FileString", leaving just the file name
* component in it when it is finished.
*/
int
getDirHandle(struct ncp_conn *conn, char *FileString, __u8 * NewDirHandle)
int getDirHandle(struct ncp_conn *conn, char *FileString, __u8 * NewDirHandle)
{
struct nw_info_struct info1, info2;
int currentLevel = 0;
@@ -446,25 +406,20 @@ getDirHandle(struct ncp_conn *conn, char *FileString, __u8 * NewDirHandle)
struct nw_info_struct *parentInfo = NULL;
struct nw_info_struct *currentInfo = NULL;
while ((k = stringPosition(FileString, '/')) >= 0)
{
while ((k = stringPosition(FileString, '/')) >= 0) {
FileString[k] = 0;
if (!currentLevel)
{
if (!currentLevel) {
parentInfo = NULL;
currentInfo = &info1;
} else if (currentLevel % 2)
{
} else if (currentLevel % 2) {
parentInfo = &info1;
currentInfo = &info2;
} else
{
} else {
parentInfo = &info2;
currentInfo = &info1;
}
if (ncp_do_lookup(conn, parentInfo, FileString,
currentInfo) != 0)
{
currentInfo) != 0) {
fprintf(stderr, "%s: Ncp lookup failed on directory %s--%s\n",
ProgramName, FileString, strerror(errno));
return 1;
@@ -474,8 +429,7 @@ getDirHandle(struct ncp_conn *conn, char *FileString, __u8 * NewDirHandle)
}
if (ncp_alloc_short_dir_handle(conn, currentInfo, NCP_ALLOC_TEMPORARY,
NewDirHandle) != 0)
{
NewDirHandle) != 0) {
fprintf(stderr, "%s: Ncp alloc dir handle failed--%s\n",
ProgramName, strerror(errno));
return 1;
@@ -487,11 +441,10 @@ getDirHandle(struct ncp_conn *conn, char *FileString, __u8 * NewDirHandle)
/****************************************************************************
* Interfaces with the ncplib to do the netware copy of the file.
*/
int
netwareCopyFile(int ncpMountIndex, const char *sourcefile,
const char *destfile,
const char *paramInputFile,
const char *paramOutputFile)
int netwareCopyFile(int ncpMountIndex, const char *sourcefile,
const char *destfile,
const char *paramInputFile,
const char *paramOutputFile)
{
__u8 source_dir_handle;
__u8 dest_dir_handle;
@@ -512,12 +465,10 @@ netwareCopyFile(int ncpMountIndex, const char *sourcefile,
/* Establish a connection to a Netware mount point if
one is not already established. */
if (!NcpMountTable[ncpMountIndex].conn)
{
if (!NcpMountTable[ncpMountIndex].conn) {
NcpMountTable[ncpMountIndex].conn =
ncp_open_mount(NcpMountTable[ncpMountIndex].mountDir, &err);
if (err)
{
if (err) {
com_err(ProgramName, err, "opening ncp connection on mount point %s",
NcpMountTable[ncpMountIndex].mountDir);
return 2;
@@ -530,8 +481,7 @@ netwareCopyFile(int ncpMountIndex, const char *sourcefile,
stroffset = strlen(NcpMountTable[ncpMountIndex].mountDir) + 1;
sourceDup = duplicateStr(sourcefile + stroffset);
destDup = duplicateStr(destfile + stroffset);
if (!sourceDup || !destDup)
{
if (!sourceDup || !destDup) {
fprintf(stderr, "%s: Malloc failed duplicating file names\n",
ProgramName);
return 2;
@@ -541,16 +491,14 @@ netwareCopyFile(int ncpMountIndex, const char *sourcefile,
/* Get Handles to the input and output directories */
if (getDirHandle(sourceconn, sourceDup, &source_dir_handle) ||
getDirHandle(sourceconn, destDup, &dest_dir_handle))
{
getDirHandle(sourceconn, destDup, &dest_dir_handle)) {
free(sourceDup);
free(destDup);
return 1;
}
/* Open the input and output files. */
if (ncp_open_file(sourceconn, source_dir_handle, sourceDup, 0, AR_READ,
&source_file) != 0)
{
&source_file) != 0) {
fprintf(stderr, "%s: Cannot open %s--%s\n",
ProgramName, paramInputFile, strerror(errno));
free(sourceDup);
@@ -558,8 +506,7 @@ netwareCopyFile(int ncpMountIndex, const char *sourcefile,
return 1;
}
if (ncp_create_file(sourceconn, dest_dir_handle, destDup,
source_file.file_attributes, &dest_file) != 0)
{
source_file.file_attributes, &dest_file) != 0) {
fprintf(stderr, "%s: Cannot create %s--%s\n", ProgramName, paramOutputFile,
strerror(errno));
ncp_close_file(sourceconn, source_file.file_id);
@@ -576,8 +523,7 @@ netwareCopyFile(int ncpMountIndex, const char *sourcefile,
free(destDup);
retValue = 0;
if (optVerbose)
{
if (optVerbose) {
printf("NetWare copy: %s -> %s 0%%", paramInputFile, paramOutputFile);
fflush(stdout);
}
@@ -587,28 +533,24 @@ netwareCopyFile(int ncpMountIndex, const char *sourcefile,
sourceOff = 0;
retryCount = 0;
while (amtLeft && retryCount < MaxNcopyRetries)
{
while (amtLeft && retryCount < MaxNcopyRetries) {
int ncopyRetValue;
if (amtLeft > CopyBlockSize)
thisMove = CopyBlockSize;
else
thisMove = amtLeft;
/* If we are being nice and we've copied enough blocks, go to sleep */
if (optNice)
{
if (BlocksCopied == optNiceFactor)
{
if (optNice) {
if (BlocksCopied == optNiceFactor) {
sleep(NiceSleepTime);
BlocksCopied = 0;
} else
++BlocksCopied;
}
ncopyRetValue = ncp_copy_file(sourceconn, source_file.file_id,
dest_file.file_id, sourceOff, sourceOff,
dest_file.file_id, sourceOff, sourceOff,
thisMove, &amountCopied);
if (ncopyRetValue != 0)
{
if (ncopyRetValue != 0) {
/* In my testing this only happens when you run out of space
on the server.
Netware seems to wait a bit before reporting space recently
@@ -617,8 +559,7 @@ netwareCopyFile(int ncpMountIndex, const char *sourcefile,
retryCount++;
amountCopied = thisMove = 0;
}
if (amountCopied != thisMove)
{
if (amountCopied != thisMove) {
fprintf(stderr, "%s: Warning, amountCopied (%u) != thisMove (%u)\n",
ProgramName, (unsigned int) amountCopied, (unsigned int) thisMove);
}
@@ -628,8 +569,7 @@ netwareCopyFile(int ncpMountIndex, const char *sourcefile,
#endif
amtLeft -= amountCopied;
sourceOff += amountCopied;
if (optVerbose)
{
if (optVerbose) {
printf("\rNetWare copy: %s -> %s %ld%%", paramInputFile, paramOutputFile,
(100 - (long) ((float) amtLeft / (float) totalSize * 100.0)));
if (retryCount)
@@ -641,8 +581,7 @@ netwareCopyFile(int ncpMountIndex, const char *sourcefile,
retValue = 1;
if (optVerbose)
printf("\n");
if (ncp_close_file(sourceconn, dest_file.file_id) != 0)
{
if (ncp_close_file(sourceconn, dest_file.file_id) != 0) {
fprintf(stderr, "%s: Close failed for %s\n", ProgramName, paramOutputFile);
retValue = 1;
}
@@ -651,19 +590,16 @@ netwareCopyFile(int ncpMountIndex, const char *sourcefile,
CurrentConn = NULL;
CurrentFile = NULL;
if (ncp_close_file(sourceconn, source_file.file_id) != 0)
{
if (ncp_close_file(sourceconn, source_file.file_id) != 0) {
fprintf(stderr, "%s: Close failed for %s\n", ProgramName, paramInputFile);
retValue = 1;
}
if (ncp_dealloc_dir_handle(sourceconn, dest_dir_handle) != 0)
{
if (ncp_dealloc_dir_handle(sourceconn, dest_dir_handle) != 0) {
fprintf(stderr, "%s: Dealloc dir handle error for %s\n", ProgramName,
paramOutputFile);
retValue = 1;
}
if (ncp_dealloc_dir_handle(sourceconn, source_dir_handle) != 0)
{
if (ncp_dealloc_dir_handle(sourceconn, source_dir_handle) != 0) {
fprintf(stderr, "%s: Dealloc dir handle error for %s\n", ProgramName,
paramInputFile);
retValue = 1;
@@ -676,9 +612,8 @@ netwareCopyFile(int ncpMountIndex, const char *sourcefile,
* Decides whether to use the traditional file copy or the netware remote
* file copy.
*/
int
copyFiles(const char *realsource, const char *realdestination,
const char *paraminputfile, const char *paramoutputfile)
int copyFiles(const char *realsource, const char *realdestination,
const char *paraminputfile, const char *paramoutputfile)
{
int oldUMask;
char fileBuffer[24000];
@@ -688,7 +623,7 @@ copyFiles(const char *realsource, const char *realdestination,
printf("Real Source '%s'\n"
"Real Dest '%s'\n"
"Param Src '%s'\n"
"Param Dest '%s'\n", realsource, realdestination, paraminputfile,
"Param Dest '%s'\n", realsource, realdestination, paraminputfile,
paramoutputfile);
#endif
@@ -722,8 +657,7 @@ copyFiles(const char *realsource, const char *realdestination,
* Is it failure if destination fails?
* Do we Stay in the loop?
*/
static int
copyRealPaths(const char *source, const char *destination)
static int copyRealPaths(const char *source, const char *destination)
{
char realsource[MAXPATHLEN * 2];
char realdestination[MAXPATHLEN * 2];
@@ -731,21 +665,18 @@ copyRealPaths(const char *source, const char *destination)
char filePart[MAXPATHLEN + 1];
const char *p;
if (realpath(source, realsource) == 0)
{ /* the source must at least exist */
if (realpath(source, realsource) == 0) { /* the source must at least exist */
fprintf(stderr, "%s: %s: %s\n",
ProgramName, source, strerror(errno));
return 1; /* indicate a "source" problem */
}
if (realpath(destination, realdestination) == 0)
{ /* dest file missing? OK */
if (realpath(destination, realdestination) == 0) { /* dest file missing? OK */
strncpy(dirPart, destination, MAXPATHLEN); /* but "dirpart" must work */
dirPart[MAXPATHLEN] = 0;
p = myBaseName(dirPart);
strcpy(filePart, p);
dirPart[p - dirPart] = 0; /* isolates "directory" part from "file part" */
if (realpath(dirPart, realdestination) == 0)
{
if (realpath(dirPart, realdestination) == 0) {
fprintf(stderr, "%s: %s: %s\n",
ProgramName, dirPart, strerror(errno));
return 2; /* indicate a "destination" problem */
@@ -770,8 +701,7 @@ copyRealPaths(const char *source, const char *destination)
* if argc > 2 last parameter is a directory
* by validateFileArgs()
*/
static int
handleFileArgs(int argc, char *const argv[])
static int handleFileArgs(int argc, char *const argv[])
{
int loop;
const char *destination;
@@ -781,12 +711,10 @@ handleFileArgs(int argc, char *const argv[])
char destinationfile[MAXPATHLEN * 2];
destination = argv[argc - 1]; /* get LAST argument */
for (loop = 0; loop < (argc - 1); loop++)
{ /* all file arguments, but last */
for (loop = 0; loop < (argc - 1); loop++) { /* all file arguments, but last */
strncpy(destinationfile, destination, MAXPATHLEN);
destinationfile[MAXPATHLEN] = 0;
if ((argc > 2) || (!notDir(argv[argc - 1])))
{ /* destination is a dir */
if ((argc > 2) || (!notDir(argv[argc - 1]))) { /* destination is a dir */
if (*destinationfile != '/' || *(destinationfile + 1))
strcat(destinationfile, "/");
baseNamePtr = myBaseName(argv[loop]); /* get the file name */
@@ -803,48 +731,41 @@ handleFileArgs(int argc, char *const argv[])
/****************************************************************************
*
*/
static void
handleSignals(int sigNumber)
static void handleSignals(int sigNumber)
{
/* Ignore Signal Handling while cleaning up */
/* SIGHUP */
sHangupSig.sa_handler = SIG_IGN;
if (sigaction(SIGHUP, &sHangupSig, NULL) == -1)
{
if (sigaction(SIGHUP, &sHangupSig, NULL) == -1) {
fprintf(stderr, "%s: Reset to ignore SIGHUP signal failed: %s",
ProgramName, strerror(errno));
}
/* SIGINT */
sInterruptSig.sa_handler = SIG_IGN;
if (sigaction(SIGINT, &sInterruptSig, NULL) == -1)
{
if (sigaction(SIGINT, &sInterruptSig, NULL) == -1) {
fprintf(stderr, "%s: Reset to ignore SIGINT signal failed: %s",
ProgramName, strerror(errno));
}
/* SIGQUIT */
sQuitSig.sa_handler = SIG_IGN;
if (sigaction(SIGQUIT, &sQuitSig, NULL) == -1)
{
if (sigaction(SIGQUIT, &sQuitSig, NULL) == -1) {
fprintf(stderr, "%s: Reset to ignore SIGQUIT signal failed: %s",
ProgramName, strerror(errno));
}
/* SIGTERM */
sTermSig.sa_handler = SIG_IGN;
if (sigaction(SIGTERM, &sTermSig, NULL) == -1)
{
if (sigaction(SIGTERM, &sTermSig, NULL) == -1) {
fprintf(stderr, "%s: Reset to ignore SIGTERM signal failed: %s",
ProgramName, strerror(errno));
}
/* If we don't close the ncp output file, we have to ncpumount and
ncpmount before we can get rid of it. */
if (OutputOpen)
{
if (OutputOpen) {
/* Issue a warning if we cannot close the file */
/* If an error occurs we probably have to umount/mount to
remove the file */
if (ncp_close_file(CurrentConn, CurrentFile->file_id) != 0)
{
if (ncp_close_file(CurrentConn, CurrentFile->file_id) != 0) {
fprintf(stderr, "%s: unclean close of output file", ProgramName);
}
OutputOpen = 0;
@@ -855,57 +776,48 @@ handleSignals(int sigNumber)
/****************************************************************************
* We'll trap Hangup, Interrupt, Quit or Terminate
*/
static int
trapSignals()
static int trapSignals()
{
if (sigaction(SIGHUP, NULL, &sHangupSig))
{ /* init structure fields */
if (sigaction(SIGHUP, NULL, &sHangupSig)) { /* init structure fields */
fprintf(stderr, "%s: Get HANGUP signal action failed: %s",
ProgramName, strerror(errno));
return 1;
}
sHangupSig.sa_handler = handleSignals;
if (sigaction(SIGHUP, &sHangupSig, NULL) == -1)
{
if (sigaction(SIGHUP, &sHangupSig, NULL) == -1) {
fprintf(stderr, "%s: Reset HANGUP signal action failed: %s",
ProgramName, strerror(errno));
return 1;
}
if (sigaction(SIGINT, NULL, &sInterruptSig))
{ /* init structure fields */
if (sigaction(SIGINT, NULL, &sInterruptSig)) { /* init structure fields */
fprintf(stderr, "%s: Get INTERRUPT signal action failed: %s",
ProgramName, strerror(errno));
return 1;
}
sInterruptSig.sa_handler = handleSignals;
if (sigaction(SIGINT, &sInterruptSig, NULL) == -1)
{
if (sigaction(SIGINT, &sInterruptSig, NULL) == -1) {
fprintf(stderr, "%s: Reset INTERRUPT signal action failed: %s",
ProgramName, strerror(errno));
return 1;
}
if (sigaction(SIGQUIT, NULL, &sQuitSig))
{ /* init structure fields */
if (sigaction(SIGQUIT, NULL, &sQuitSig)) { /* init structure fields */
fprintf(stderr, "%s: Get QUIT signal action failed: %s",
ProgramName, strerror(errno));
return 1;
}
sQuitSig.sa_handler = handleSignals;
if (sigaction(SIGQUIT, &sQuitSig, NULL) == -1)
{
if (sigaction(SIGQUIT, &sQuitSig, NULL) == -1) {
fprintf(stderr, "%s: Reset QUIT signal action failed: %s",
ProgramName, strerror(errno));
return 1;
}
if (sigaction(SIGTERM, NULL, &sTermSig))
{ /* init structure fields */
if (sigaction(SIGTERM, NULL, &sTermSig)) { /* init structure fields */
fprintf(stderr, "%s: Get TERMINATE signal action failed: %s",
ProgramName, strerror(errno));
return 1;
}
sTermSig.sa_handler = handleSignals;
if (sigaction(SIGTERM, &sTermSig, NULL) == -1)
{
if (sigaction(SIGTERM, &sTermSig, NULL) == -1) {
fprintf(stderr, "%s: Reset TERMINATE signal action failed: %s",
ProgramName, strerror(errno));
return 1;
@@ -916,24 +828,20 @@ trapSignals()
/****************************************************************************
*
*/
int
main(int argc, char *const argv[])
int main(int argc, char *const argv[])
{
int returnCode;
ProgramName = argv[0];
if (handleOptions(argc, argv))
{ /* bad option, missing option parameter */
if (handleOptions(argc, argv)) { /* bad option, missing option parameter */
usage();
return 1;
}
if (optVersion)
{ /* only option not requiring any arguments */
if (optVersion) { /* only option not requiring any arguments */
printf("%s version %s\n", ProgramName, VersionStr);
return 0;
}
if (validateFileArgs(argc - optind, argv + optind))
{
if (validateFileArgs(argc - optind, argv + optind)) {
usage();
return 1;
}

View File

@@ -1,3 +1,4 @@
/*
* ncptest.c
*
@@ -19,7 +20,7 @@
#include <unistd.h>
#include <sys/types.h>
#include <sys/ioctl.h>
/* #include <sys/wait.h> *//* generates a warning here */
/* #include <sys/wait.h> *//* generates a warning here */
extern pid_t waitpid(pid_t, int *, int);
#include <sys/errno.h>
#include <unistd.h>
@@ -38,8 +39,7 @@ extern pid_t waitpid(pid_t, int *, int);
#include "ncplib.h"
void
test_connlist(struct ncp_conn *conn)
void test_connlist(struct ncp_conn *conn)
{
__u8 conn_list[256] =
{0,};
@@ -50,110 +50,92 @@ test_connlist(struct ncp_conn *conn)
return;
}
void
test_send(struct ncp_conn *conn)
void test_send(struct ncp_conn *conn)
{
__u8 conn_list[256] =
{0,};
int no;
if (ncp_get_connlist(conn, NCP_BINDERY_USER, "ME", &no,
conn_list) != 0)
{
conn_list) != 0) {
no = 0;
}
if (no > 0)
{
if (no > 0) {
ncp_send_broadcast(conn, no, conn_list, "Hallo");
}
return;
}
void
test_create(struct ncp_conn *conn)
void test_create(struct ncp_conn *conn)
{
struct nw_info_struct sys;
struct nw_info_struct me;
__u8 dir_handle;
struct ncp_file_info new_file;
if (ncp_do_lookup(conn, NULL, "SYS", &sys) != 0)
{
if (ncp_do_lookup(conn, NULL, "SYS", &sys) != 0) {
printf("lookup error\n");
return;
}
if (ncp_do_lookup(conn, &sys, "ME", &me) != 0)
{
if (ncp_do_lookup(conn, &sys, "ME", &me) != 0) {
printf("lookup public error\n");
return;
}
if (ncp_alloc_short_dir_handle(conn, &me, NCP_ALLOC_TEMPORARY,
&dir_handle) != 0)
{
&dir_handle) != 0) {
printf("alloc_dir_handle error\n");
return;
}
if (ncp_create_file(conn, dir_handle, "BLUB.TXT", 0,
&new_file) != 0)
{
&new_file) != 0) {
printf("create error\n");
return;
}
if (ncp_dealloc_dir_handle(conn, dir_handle) != 0)
{
if (ncp_dealloc_dir_handle(conn, dir_handle) != 0) {
printf("dealloc error\n");
return;
}
}
int
test_change(struct ncp_conn *conn)
int test_change(struct ncp_conn *conn)
{
long result;
unsigned char ncp_key[8];
struct ncp_bindery_object user;
if ((result = ncp_get_encryption_key(conn, ncp_key)) != 0)
{
if ((result = ncp_get_encryption_key(conn, ncp_key)) != 0) {
return result;
}
if ((result = ncp_get_bindery_object_id(conn, 1,
"ME", &user)) != 0)
{
"ME", &user)) != 0) {
return result;
}
if ((result = ncp_change_login_passwd(conn, &user, ncp_key,
"MEE", "ME")) != 0)
{
"MEE", "ME")) != 0) {
return result;
}
return 0;
}
void
test_readdir(struct ncp_conn *conn)
void test_readdir(struct ncp_conn *conn)
{
struct nw_info_struct sys;
struct nw_info_struct blub;
struct ncp_search_seq seq;
struct nw_info_struct entry;
if (ncp_do_lookup(conn, NULL, "SYS", &sys) != 0)
{
if (ncp_do_lookup(conn, NULL, "SYS", &sys) != 0) {
printf("lookup error\n");
return;
}
if (ncp_do_lookup(conn, &sys, "BLUB", &blub) != 0)
{
if (ncp_do_lookup(conn, &sys, "BLUB", &blub) != 0) {
printf("lookup blub error\n");
return;
}
if (ncp_initialize_search(conn, &sys, 0, &seq) != 0)
{
if (ncp_initialize_search(conn, &sys, 0, &seq) != 0) {
printf("init error\n");
return;
}
while (ncp_search_for_file_or_subdir(conn, &seq, &entry) == 0)
{
while (ncp_search_for_file_or_subdir(conn, &seq, &entry) == 0) {
struct nw_info_struct nfs;
printf("found: %s\n", entry.entryName);
if (ncp_obtain_file_or_subdir_info(conn, NW_NS_DOS, NW_NS_NFS,
@@ -161,8 +143,7 @@ test_readdir(struct ncp_conn *conn)
entry.volNumber,
entry.DosDirNum,
NULL,
&nfs) == 0)
{
&nfs) == 0) {
printf("nfs name: %s\n", nfs.entryName);
}
if (ncp_obtain_file_or_subdir_info(conn, NW_NS_DOS, NW_NS_OS2,
@@ -170,35 +151,30 @@ test_readdir(struct ncp_conn *conn)
entry.volNumber,
entry.DosDirNum,
NULL,
&nfs) == 0)
{
&nfs) == 0) {
printf("os2 name: %s\n", nfs.entryName);
}
}
}
void
test_rights(struct ncp_conn *conn)
void test_rights(struct ncp_conn *conn)
{
struct nw_info_struct sys;
struct nw_info_struct me;
__u16 rights;
if (ncp_do_lookup(conn, NULL, "SYS", &sys) != 0)
{
if (ncp_do_lookup(conn, NULL, "SYS", &sys) != 0) {
printf("lookup error\n");
return;
}
if (ncp_do_lookup(conn, &sys, "ME", &me) != 0)
{
if (ncp_do_lookup(conn, &sys, "ME", &me) != 0) {
printf("lookup me error\n");
return;
}
if (ncp_get_eff_directory_rights(conn, 0, 0, 0x8006,
sys.volNumber, sys.DosDirNum, NULL,
&rights) != 0)
{
sys.volNumber, sys.DosDirNum, NULL,
&rights) != 0) {
printf("get sys rights error\n");
return;
}
@@ -206,8 +182,7 @@ test_rights(struct ncp_conn *conn)
if (ncp_get_eff_directory_rights(conn, 0, 0, 0x8006,
me.volNumber, me.DosDirNum, NULL,
&rights) != 0)
{
&rights) != 0) {
printf("get me rights error\n");
return;
}
@@ -215,14 +190,12 @@ test_rights(struct ncp_conn *conn)
return;
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
struct ncp_conn *conn;
long err;
if ((conn = ncp_initialize(&argc, argv, 1, &err)) == NULL)
{
if ((conn = ncp_initialize(&argc, argv, 1, &err)) == NULL) {
com_err(argv[0], err, "in ncp_initialize");
return 1;
}

View File

@@ -22,8 +22,7 @@ static void
usage(void);
static void help(void);
void
main(int argc, char *argv[])
void main(int argc, char *argv[])
{
struct ncp_conn *conn;
@@ -51,13 +50,11 @@ main(int argc, char *argv[])
memzero(q);
if ((argc == 2)
&& (strcmp(argv[1], "-h") == 0))
{
&& (strcmp(argv[1], "-h") == 0)) {
help();
exit(0);
}
if ((conn = ncp_initialize(&argc, argv, 1, &err)) == NULL)
{
if ((conn = ncp_initialize(&argc, argv, 1, &err)) == NULL) {
com_err(argv[0], err, "when initializing connection");
exit(1);
}
@@ -78,10 +75,8 @@ main(int argc, char *argv[])
pj.Rows = htons(80);
strcpy(pj.FnameHeader, "stdin");
while ((opt = getopt(argc, argv, "h?q:d:p:b:f:l:r:c:t:F:TN")) != EOF)
{
switch (opt)
{
while ((opt = getopt(argc, argv, "h?q:d:p:b:f:l:r:c:t:F:TN")) != EOF) {
switch (opt) {
case 'h':
case '?':
help();
@@ -90,45 +85,38 @@ main(int argc, char *argv[])
case 'p':
/* Path */
pj.CtrlFlags |= PRINT_BANNER;
if (strlen(optarg) >= sizeof(pj.Path))
{
if (strlen(optarg) >= sizeof(pj.Path)) {
strncpy(pj.Path, optarg,
sizeof(pj.Path));
} else
{
} else {
strcpy(pj.Path, optarg);
}
break;
case 'b':
/* Banner Name */
pj.CtrlFlags |= PRINT_BANNER;
if (strlen(optarg) >= sizeof(pj.BannerName))
{
if (strlen(optarg) >= sizeof(pj.BannerName)) {
strncpy(pj.BannerName, optarg,
sizeof(pj.BannerName));
} else
{
} else {
strcpy(pj.BannerName, optarg);
}
break;
case 'f':
/* File Name in Banner */
pj.CtrlFlags |= PRINT_BANNER;
if (strlen(optarg) >= sizeof(pj.FnameBanner))
{
if (strlen(optarg) >= sizeof(pj.FnameBanner)) {
strncpy(pj.FnameBanner, optarg,
sizeof(pj.FnameBanner));
} else
{
} else {
strcpy(pj.FnameBanner, optarg);
}
break;
case 'l':
/* lines, default: 66 */
if ((atoi(optarg) < 0) || (atoi(optarg) > 65535))
{
if ((atoi(optarg) < 0) || (atoi(optarg) > 65535)) {
fprintf(stderr,
"invalid line number: %s\n", optarg);
"invalid line number: %s\n", optarg);
break;
}
pj.Lines = htons(atoi(optarg));
@@ -136,10 +124,9 @@ main(int argc, char *argv[])
break;
case 'r':
/* rows, default: 80 */
if ((atoi(optarg) < 0) || (atoi(optarg) > 65535))
{
if ((atoi(optarg) < 0) || (atoi(optarg) > 65535)) {
fprintf(stderr,
"invalid row number: %s\n", optarg);
"invalid row number: %s\n", optarg);
break;
}
pj.Rows = htons(atoi(optarg));
@@ -147,8 +134,7 @@ main(int argc, char *argv[])
break;
case 'c':
/* copies, default: 1 */
if ((atoi(optarg) < 0) || (atoi(optarg) > 65000))
{
if ((atoi(optarg) < 0) || (atoi(optarg) > 65000)) {
fprintf(stderr,
"invalid copies: %s\n", optarg);
break;
@@ -158,8 +144,7 @@ main(int argc, char *argv[])
break;
case 't':
/* tab size, default: 8 */
if ((atoi(optarg) < 0) || (atoi(optarg) > 255))
{
if ((atoi(optarg) < 0) || (atoi(optarg) > 255)) {
fprintf(stderr,
"invalid tab size: %s\n", optarg);
break;
@@ -177,18 +162,16 @@ main(int argc, char *argv[])
break;
case 'F':
/* Form number, default: 0 */
if ((atoi(optarg) < 0) || (atoi(optarg) > 255))
{
if ((atoi(optarg) < 0) || (atoi(optarg) > 255)) {
fprintf(stderr,
"invalid form number: %s\n", optarg);
"invalid form number: %s\n", optarg);
break;
}
j.j.JobType = htons(atoi(optarg));
break;
case 'q':
/* Queue name to print on, default: '*' */
if (strlen(optarg) >= NCP_BINDERY_NAME_LEN)
{
if (strlen(optarg) >= NCP_BINDERY_NAME_LEN) {
printf("queue name too long: %s\n",
optarg);
ncp_close(conn);
@@ -199,12 +182,10 @@ main(int argc, char *argv[])
case 'd':
/* Job Description */
pj.CtrlFlags |= PRINT_BANNER;
if (strlen(optarg) >= sizeof(j.j.JobTextDescription))
{
if (strlen(optarg) >= sizeof(j.j.JobTextDescription)) {
strncpy(j.j.JobTextDescription, optarg,
sizeof(j.j.JobTextDescription));
} else
{
} else {
strcpy(j.j.JobTextDescription, optarg);
}
break;
@@ -216,43 +197,34 @@ main(int argc, char *argv[])
}
}
if (optind != argc - 1)
{
if (optind != argc - 1) {
usage();
ncp_close(conn);
exit(1);
}
file_name = argv[optind];
if (strcmp(file_name, "-") == 0)
{
if (strcmp(file_name, "-") == 0) {
file = 0; /* stdin */
} else
{
} else {
file = open(file_name, O_RDONLY, 0);
if (file < 0)
{
if (file < 0) {
perror("could not open file");
ncp_close(conn);
exit(1);
}
if (strlen(file_name) >= sizeof(pj.FnameHeader))
{
if (strlen(file_name) >= sizeof(pj.FnameHeader)) {
strncpy(pj.FnameHeader, file_name,
sizeof(pj.FnameHeader));
} else
{
} else {
strcpy(pj.FnameHeader, file_name);
}
if (strlen(pj.FnameBanner) == 0)
{
if (strlen(file_name) >= sizeof(pj.FnameBanner))
{
if (strlen(pj.FnameBanner) == 0) {
if (strlen(file_name) >= sizeof(pj.FnameBanner)) {
strncpy(pj.FnameBanner, file_name,
sizeof(pj.FnameBanner));
} else
{
} else {
strcpy(pj.FnameBanner, file_name);
}
}
@@ -263,29 +235,24 @@ main(int argc, char *argv[])
str_upper(queue);
if (ncp_scan_bindery_object(conn, 0xffffffff, NCP_BINDERY_PQUEUE,
queue, &q) != 0)
{
queue, &q) != 0) {
printf("could not find queue %s\n", queue);
ncp_close(conn);
exit(1);
}
if (ncp_create_queue_job_and_file(conn, q.object_id, &j) != 0)
{
if (ncp_create_queue_job_and_file(conn, q.object_id, &j) != 0) {
printf("create error\n");
ncp_close(conn);
exit(1);
}
written = 0;
do
{
do {
read_this_time = read(file, buf, sizeof(buf));
if (read_this_time < 0)
{
if (read_this_time < 0) {
break;
}
if (ncp_write(conn, j.file_handle,
written, read_this_time, buf) < read_this_time)
{
written, read_this_time, buf) < read_this_time) {
break;
}
written += read_this_time;
@@ -294,22 +261,19 @@ main(int argc, char *argv[])
close(file);
if (ncp_close_file_and_start_job(conn, q.object_id, &j) != 0)
{
if (ncp_close_file_and_start_job(conn, q.object_id, &j) != 0) {
printf("close error\n");
}
ncp_close(conn);
return;
}
static void
usage(void)
static void usage(void)
{
fprintf(stderr, "usage: %s [options] file\n", progname);
}
static void
help(void)
static void help(void)
{
printf("\n");
printf("usage: %s [options] file\n", progname);

View File

@@ -12,8 +12,7 @@
#include <ctype.h>
#include "ncplib.h"
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
struct ncp_conn *conn;
__u8 conn_list[256] =
@@ -24,13 +23,11 @@ main(int argc, char **argv)
char *user = NULL;
long err;
if ((conn = ncp_initialize(&argc, argv, 1, &err)) == NULL)
{
if ((conn = ncp_initialize(&argc, argv, 1, &err)) == NULL) {
com_err(argv[0], err, "when initializing");
exit(1);
}
if (argc != 3)
{
if (argc != 3) {
fprintf(stderr, "usage: %s [options] user message\n", argv[0]);
ncp_close(conn);
exit(1);
@@ -39,20 +36,17 @@ main(int argc, char **argv)
message = argv[2];
if ((err = ncp_get_connlist(conn, NCP_BINDERY_USER, user, &no_conn,
conn_list)) != 0)
{
conn_list)) != 0) {
com_err(argv[0], err, "in get_connlist");
ncp_close(conn);
exit(1);
}
if (no_conn == 0)
{
if (no_conn == 0) {
fprintf(stderr, "No connection found for %s\n", user);
ncp_close(conn);
exit(1);
}
if ((err = ncp_send_broadcast(conn, no_conn, conn_list, message)) != 0)
{
if ((err = ncp_send_broadcast(conn, no_conn, conn_list, message)) != 0) {
com_err(argv[0], err, "in send_broadcast");
ncp_close(conn);
exit(1);

View File

@@ -14,14 +14,12 @@
static char *progname;
static void
usage(void)
static void usage(void)
{
fprintf(stderr, "usage: %s [options]\n", progname);
}
static void
help(void)
static void help(void)
{
printf("\n");
printf("usage: %s [options]\n", progname);
@@ -33,14 +31,12 @@ help(void)
"\n");
}
static void
swallow_error(const char *s, long x, const char *t, va_list arg)
static void swallow_error(const char *s, long x, const char *t, va_list arg)
{
return;
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
struct ncp_conn_spec *spec;
struct ncp_conn *conn;
@@ -55,14 +51,11 @@ main(int argc, char *argv[])
progname = argv[0];
if (!isatty(0))
{
if (!isatty(0)) {
set_com_err_hook(swallow_error);
}
while ((opt = getopt(argc, argv, "h?S:U:t:")) != EOF)
{
switch (opt)
{
while ((opt = getopt(argc, argv, "h?S:U:t:")) != EOF) {
switch (opt) {
case 'S':
server = optarg;
break;
@@ -85,37 +78,31 @@ main(int argc, char *argv[])
spec = ncp_find_conn_spec(server, object_name, "",
1, getuid(), &err);
if (spec == NULL)
{
if (spec == NULL) {
com_err(argv[0], err, "when trying to find server");
exit(1);
}
if (ncp_find_fileserver(spec->server, &err) == NULL)
{
if (ncp_find_fileserver(spec->server, &err) == NULL) {
com_err(argv[0], err, "when trying to find server");
exit(1);
}
spec->login_type = object_type;
memset(spec->password, 0, sizeof(spec->password));
if (isatty(0))
{
if (isatty(0)) {
str = getpass("Enter password: ");
if (strlen(str) >= sizeof(spec->password))
{
if (strlen(str) >= sizeof(spec->password)) {
printf("Password too long\n");
exit(1);
}
strcpy(spec->password, str);
} else
{
} else {
fgets(spec->password, sizeof(spec->password), stdin);
}
str_upper(spec->password);
if ((conn = ncp_open(spec, &err)) == NULL)
{
if ((conn = ncp_open(spec, &err)) == NULL) {
com_err(argv[0], err, "when trying to open connection");
exit(1);
}

View File

@@ -13,14 +13,12 @@
static char *progname;
static void
usage(void)
static void usage(void)
{
fprintf(stderr, "usage: %s [options]\n", progname);
}
static void
help(void)
static void help(void)
{
printf("\n");
printf("usage: %s [options]\n", progname);
@@ -39,34 +37,27 @@ help(void)
"\n");
}
static int
parse_security(const char *security)
static int parse_security(const char *security)
{
if (strcasecmp(security, "anyone") == 0)
{
if (strcasecmp(security, "anyone") == 0) {
return 0;
}
if (strcasecmp(security, "logged") == 0)
{
if (strcasecmp(security, "logged") == 0) {
return 1;
}
if (strcasecmp(security, "object") == 0)
{
if (strcasecmp(security, "object") == 0) {
return 2;
}
if (strcasecmp(security, "supervisor") == 0)
{
if (strcasecmp(security, "supervisor") == 0) {
return 3;
}
if (strcasecmp(security, "netware") == 0)
{
if (strcasecmp(security, "netware") == 0) {
return 4;
}
return -1;
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
struct ncp_conn *conn;
char *object_name = NULL;
@@ -81,15 +72,12 @@ main(int argc, char *argv[])
progname = argv[0];
if ((conn = ncp_initialize(&argc, argv, 1, &err)) == NULL)
{
if ((conn = ncp_initialize(&argc, argv, 1, &err)) == NULL) {
com_err(argv[0], err, "when initializing");
goto finished;
}
while ((opt = getopt(argc, argv, "h?o:t:r:w:")) != EOF)
{
switch (opt)
{
while ((opt = getopt(argc, argv, "h?o:t:r:w:")) != EOF) {
switch (opt) {
case 'o':
object_name = optarg;
str_upper(object_name);
@@ -99,8 +87,7 @@ main(int argc, char *argv[])
break;
case 'r':
read_sec = parse_security(optarg);
if (read_sec < 0)
{
if (read_sec < 0) {
fprintf(stderr,
"%s: Wrong read security\n"
"Must be one of anyone, logged, "
@@ -111,8 +98,7 @@ main(int argc, char *argv[])
break;
case 'w':
write_sec = parse_security(optarg);
if (write_sec < 0)
{
if (write_sec < 0) {
fprintf(stderr,
"%s: Wrong write security\n"
"Must be one of anyone, logged, "
@@ -131,24 +117,20 @@ main(int argc, char *argv[])
}
}
if (object_type < 0)
{
if (object_type < 0) {
fprintf(stderr, "%s: You must specify an object type\n",
argv[0]);
goto finished;
}
if (object_name == NULL)
{
if (object_name == NULL) {
fprintf(stderr, "%s: You must specify an object name\n",
argv[0]);
goto finished;
}
if (ncp_create_bindery_object(conn, object_type, object_name,
(write_sec << 4) + read_sec, 0) != 0)
{
(write_sec << 4) + read_sec, 0) != 0) {
fprintf(stderr, "%s: Could not create the object\n", argv[0]);
} else
{
} else {
result = 0;
}

View File

@@ -15,15 +15,13 @@
static char *progname;
static void
usage(void)
static void usage(void)
{
fprintf(stderr, "usage: %s [options] pattern\n", progname);
return;
}
static void
help(void)
static void help(void)
{
printf("\n");
printf("usage: %s [options]\n", progname);
@@ -41,8 +39,7 @@ help(void)
"\n");
}
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
struct ncp_conn *conn;
struct ncp_bindery_object o;
@@ -58,15 +55,12 @@ main(int argc, char **argv)
progname = argv[0];
if ((conn = ncp_initialize(&argc, argv, 1, &err)) == NULL)
{
if ((conn = ncp_initialize(&argc, argv, 1, &err)) == NULL) {
com_err(argv[0], err, "when initializing");
return 1;
}
while ((opt = getopt(argc, argv, "h?vt:o:")) != EOF)
{
switch (opt)
{
while ((opt = getopt(argc, argv, "h?vt:o:")) != EOF) {
switch (opt) {
case 'h':
case '?':
help();
@@ -86,31 +80,26 @@ main(int argc, char **argv)
}
}
if (optind < argc)
{
if (optind < argc) {
usage();
exit(1);
}
for (p = pattern; *p != '\0'; p++)
{
for (p = pattern; *p != '\0'; p++) {
*p = toupper(*p);
}
o.object_id = 0xffffffff;
while (ncp_scan_bindery_object(conn, o.object_id,
type, pattern, &o) == 0)
{
type, pattern, &o) == 0) {
found = 1;
if (verbose != 0)
{
if (verbose != 0) {
printf("%s %08X %04X %d %02X %d\n",
o.object_name, (unsigned int) o.object_id,
(unsigned int) o.object_type,
o.object_flags, o.object_security,
o.object_has_prop);
} else
{
} else {
printf("%s %08X %04X\n",
o.object_name, (unsigned int) o.object_id,
(unsigned int) o.object_type);

View File

@@ -13,14 +13,12 @@
static char *progname;
static void
usage(void)
static void usage(void)
{
fprintf(stderr, "usage: %s [options]\n", progname);
}
static void
help(void)
static void help(void)
{
printf("\n");
printf("usage: %s [options]\n", progname);
@@ -38,8 +36,7 @@ help(void)
"\n");
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
struct ncp_conn *conn;
char *object_name = NULL;
@@ -54,15 +51,12 @@ main(int argc, char *argv[])
progname = argv[0];
if ((conn = ncp_initialize(&argc, argv, 1, &err)) == NULL)
{
if ((conn = ncp_initialize(&argc, argv, 1, &err)) == NULL) {
com_err(argv[0], err, "when initializing");
goto finished;
}
while ((opt = getopt(argc, argv, "h?o:t:v")) != EOF)
{
switch (opt)
{
while ((opt = getopt(argc, argv, "h?o:t:v")) != EOF) {
switch (opt) {
case 'o':
object_name = optarg;
str_upper(object_name);
@@ -83,14 +77,12 @@ main(int argc, char *argv[])
}
}
if (object_type < 0)
{
if (object_type < 0) {
fprintf(stderr, "%s: You must specify an object type\n",
argv[0]);
goto finished;
}
if (object_name == NULL)
{
if (object_name == NULL) {
fprintf(stderr, "%s: You must specify an object name\n",
argv[0]);
goto finished;
@@ -98,16 +90,13 @@ main(int argc, char *argv[])
info.search_instance = 0xffffffff;
while (ncp_scan_property(conn, object_type, object_name,
info.search_instance, "*", &info) == 0)
{
if (verbose != 0)
{
info.search_instance, "*", &info) == 0) {
if (verbose != 0) {
printf("%s %d %02x %d\n",
info.property_name, info.property_flags,
info.property_security,
info.value_available_flag);
} else
{
} else {
printf("%s\n", info.property_name);
}
}

View File

@@ -13,14 +13,12 @@
static char *progname;
static void
usage(void)
static void usage(void)
{
fprintf(stderr, "usage: %s [options]\n", progname);
}
static void
help(void)
static void help(void)
{
printf("\n");
printf("usage: %s [options]\n", progname);
@@ -37,8 +35,7 @@ help(void)
"\n");
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
struct ncp_conn *conn;
char *object_name = NULL;
@@ -51,15 +48,12 @@ main(int argc, char *argv[])
progname = argv[0];
if ((conn = ncp_initialize(&argc, argv, 1, &err)) == NULL)
{
if ((conn = ncp_initialize(&argc, argv, 1, &err)) == NULL) {
com_err(argv[0], err, "when initializing");
goto finished;
}
while ((opt = getopt(argc, argv, "h?o:t:")) != EOF)
{
switch (opt)
{
while ((opt = getopt(argc, argv, "h?o:t:")) != EOF) {
switch (opt) {
case 'o':
object_name = optarg;
str_upper(object_name);
@@ -77,23 +71,19 @@ main(int argc, char *argv[])
}
}
if (object_type < 0)
{
if (object_type < 0) {
fprintf(stderr, "%s: You must specify an object type\n",
argv[0]);
goto finished;
}
if (object_name == NULL)
{
if (object_name == NULL) {
fprintf(stderr, "%s: You must specify an object name\n",
argv[0]);
goto finished;
}
if (ncp_delete_bindery_object(conn, object_type, object_name) != 0)
{
if (ncp_delete_bindery_object(conn, object_type, object_name) != 0) {
fprintf(stderr, "%s: Could not delete the object\n", argv[0]);
} else
{
} else {
result = 0;
}

View File

@@ -13,14 +13,12 @@
static char *progname;
static void
usage(void)
static void usage(void)
{
fprintf(stderr, "usage: %s [options]\n", progname);
}
static void
help(void)
static void help(void)
{
printf("\n");
printf("usage: %s [options] [values]\n", progname);
@@ -38,16 +36,15 @@ help(void)
"value value to be added\n"
"\n"
"If property is of type SET, value is an object id (hex)\n"
"Otherwise, value is either a string value to be written, or\n"
"a count of bytes to be written. The latter is assumed if\n"
"more than one value argument is given. The count is decimal,\n"
"Otherwise, value is either a string value to be written, or\n"
"a count of bytes to be written. The latter is assumed if\n"
"more than one value argument is given. The count is decimal,\n"
"and the following arguments are interpreted as bytes in\n"
"hexadecimal notation.\n"
"\n");
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
struct ncp_conn *conn;
char *object_name = NULL;
@@ -61,15 +58,12 @@ main(int argc, char *argv[])
progname = argv[0];
if ((conn = ncp_initialize(&argc, argv, 1, &err)) == NULL)
{
if ((conn = ncp_initialize(&argc, argv, 1, &err)) == NULL) {
com_err(argv[0], err, "when initializing");
goto finished;
}
while ((opt = getopt(argc, argv, "h?o:t:p:v:")) != EOF)
{
switch (opt)
{
while ((opt = getopt(argc, argv, "h?o:t:p:v:")) != EOF) {
switch (opt) {
case 'o':
object_name = optarg;
str_upper(object_name);
@@ -79,8 +73,7 @@ main(int argc, char *argv[])
break;
case 'p':
property_name = optarg;
if (strlen(property_name) > 15)
{
if (strlen(property_name) > 15) {
fprintf(stderr, "%s: Property Name too long\n",
argv[0]);
exit(1);
@@ -100,26 +93,22 @@ main(int argc, char *argv[])
}
}
if (object_type < 0)
{
if (object_type < 0) {
fprintf(stderr, "%s: You must specify an object type\n",
argv[0]);
goto finished;
}
if (object_name == NULL)
{
if (object_name == NULL) {
fprintf(stderr, "%s: You must specify an object name\n",
argv[0]);
goto finished;
}
if (property_name == NULL)
{
if (property_name == NULL) {
fprintf(stderr, "%s: You must specify a property name\n",
argv[0]);
goto finished;
}
if (optind > argc - 1)
{
if (optind > argc - 1) {
fprintf(stderr, "%s: You must specify a property value\n",
argv[0]);
goto finished;
@@ -128,41 +117,35 @@ main(int argc, char *argv[])
optind += 1;
if (ncp_scan_property(conn, object_type, object_name,
0xffffffff, property_name, &info) != 0)
{
0xffffffff, property_name, &info) != 0) {
fprintf(stderr, "%s: Could not find property\n", argv[0]);
goto finished;
}
if ((info.property_flags & 2) != 0)
{
if ((info.property_flags & 2) != 0) {
/* Property is of type SET */
struct ncp_bindery_object o;
if (optind != argc)
{
if (optind != argc) {
fprintf(stderr, "%s: For the SET property %s, you must"
" specify an object id as value\n",
progname, property_name);
goto finished;
}
if (ncp_get_bindery_object_name(conn,
ntohl(strtol(value, NULL, 16)),
&o) != 0)
{
ntohl(strtol(value, NULL, 16)),
&o) != 0) {
fprintf(stderr, "%s: %s is not a valid object id\n",
progname, value);
goto finished;
}
if (ncp_add_object_to_set(conn, object_type, object_name,
property_name,
o.object_type, o.object_name) != 0)
{
o.object_type, o.object_name) != 0) {
fprintf(stderr, "%s: could not add object %s\n",
progname, o.object_name);
goto finished;
}
} else
{
} else {
/* Property is of type ITEM */
char contents[255 * 128];
int segno = 1;
@@ -170,50 +153,42 @@ main(int argc, char *argv[])
memset(contents, 0, sizeof(contents));
if (optind == argc)
{
if (optind == argc) {
/* value is the string to add */
length = strlen(value);
if (length >= sizeof(contents))
{
if (length >= sizeof(contents)) {
fprintf(stderr, "%s: Value too long\n",
progname);
goto finished;
}
strcpy(contents, value);
} else
{
} else {
/* value is the byte count */
int i;
length = atoi(value);
if (length >= sizeof(contents))
{
if (length >= sizeof(contents)) {
fprintf(stderr, "%s: Value too long\n",
progname);
goto finished;
}
if (optind != argc - length)
{
if (optind != argc - length) {
fprintf(stderr, "%s: Byte count does not match"
" number of bytes\n", progname);
goto finished;
}
i = 0;
while (optind < argc)
{
while (optind < argc) {
contents[i] = strtol(argv[optind], NULL, 16);
i += 1;
optind += 1;
}
}
for (segno = 1; segno <= 255; segno++)
{
for (segno = 1; segno <= 255; segno++) {
struct nw_property segment;
int offset = (segno - 1) * 128;
if (offset > length)
{
if (offset > length) {
/* everything written */
break;
}
@@ -222,8 +197,7 @@ main(int argc, char *argv[])
if (ncp_write_property_value(conn, object_type,
object_name,
property_name,
segno, &segment) != 0)
{
segno, &segment) != 0) {
fprintf(stderr, "%s: Could not write "
"property\n", progname);
goto finished;

View File

@@ -13,14 +13,12 @@
static char *progname;
static void
usage(void)
static void usage(void)
{
fprintf(stderr, "usage: %s [options]\n", progname);
}
static void
help(void)
static void help(void)
{
printf("\n");
printf("usage: %s [options]\n", progname);
@@ -41,34 +39,27 @@ help(void)
"\n");
}
static int
parse_security(const char *security)
static int parse_security(const char *security)
{
if (strcasecmp(security, "anyone") == 0)
{
if (strcasecmp(security, "anyone") == 0) {
return 0;
}
if (strcasecmp(security, "logged") == 0)
{
if (strcasecmp(security, "logged") == 0) {
return 1;
}
if (strcasecmp(security, "object") == 0)
{
if (strcasecmp(security, "object") == 0) {
return 2;
}
if (strcasecmp(security, "supervisor") == 0)
{
if (strcasecmp(security, "supervisor") == 0) {
return 3;
}
if (strcasecmp(security, "netware") == 0)
{
if (strcasecmp(security, "netware") == 0) {
return 4;
}
return -1;
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
struct ncp_conn *conn;
char *object_name = NULL;
@@ -85,15 +76,12 @@ main(int argc, char *argv[])
progname = argv[0];
if ((conn = ncp_initialize(&argc, argv, 1, &err)) == NULL)
{
if ((conn = ncp_initialize(&argc, argv, 1, &err)) == NULL) {
com_err(argv[0], err, "when initializing");
goto finished;
}
while ((opt = getopt(argc, argv, "h?o:t:p:sr:w:")) != EOF)
{
switch (opt)
{
while ((opt = getopt(argc, argv, "h?o:t:p:sr:w:")) != EOF) {
switch (opt) {
case 'o':
object_name = optarg;
str_upper(object_name);
@@ -103,8 +91,7 @@ main(int argc, char *argv[])
break;
case 'p':
property_name = optarg;
if (strlen(property_name) > 15)
{
if (strlen(property_name) > 15) {
fprintf(stderr, "%s: Property Name too long\n",
argv[0]);
exit(1);
@@ -116,8 +103,7 @@ main(int argc, char *argv[])
break;
case 'r':
read_sec = parse_security(optarg);
if (read_sec < 0)
{
if (read_sec < 0) {
fprintf(stderr,
"%s: Wrong read security\n"
"Must be one of anyone, logged, "
@@ -128,8 +114,7 @@ main(int argc, char *argv[])
break;
case 'w':
write_sec = parse_security(optarg);
if (write_sec < 0)
{
if (write_sec < 0) {
fprintf(stderr,
"%s: Wrong write security\n"
"Must be one of anyone, logged, "
@@ -148,20 +133,17 @@ main(int argc, char *argv[])
}
}
if (object_type < 0)
{
if (object_type < 0) {
fprintf(stderr, "%s: You must specify an object type\n",
argv[0]);
goto finished;
}
if (object_name == NULL)
{
if (object_name == NULL) {
fprintf(stderr, "%s: You must specify an object name\n",
argv[0]);
goto finished;
}
if (property_name == NULL)
{
if (property_name == NULL) {
fprintf(stderr, "%s: You must specify a property name\n",
argv[0]);
goto finished;
@@ -169,11 +151,9 @@ main(int argc, char *argv[])
if (ncp_create_property(conn, object_type, object_name,
property_name,
property_is_set ? 2 : 0,
(write_sec << 4) + read_sec) != 0)
{
(write_sec << 4) + read_sec) != 0) {
fprintf(stderr, "%s: Could not create the property\n", argv[0]);
} else
{
} else {
result = 0;
}

View File

@@ -13,14 +13,12 @@
static char *progname;
static void
usage(void)
static void usage(void)
{
fprintf(stderr, "usage: %s [options] [pattern]\n", progname);
}
static void
help(void)
static void help(void)
{
printf("\n");
printf("usage: %s [options]\n", progname);
@@ -38,8 +36,7 @@ help(void)
"\n");
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
struct ncp_conn *conn;
char *object_name = NULL;
@@ -53,15 +50,12 @@ main(int argc, char *argv[])
progname = argv[0];
if ((conn = ncp_initialize(&argc, argv, 1, &err)) == NULL)
{
if ((conn = ncp_initialize(&argc, argv, 1, &err)) == NULL) {
com_err(argv[0], err, "when initializing");
goto finished;
}
while ((opt = getopt(argc, argv, "h?o:t:p:")) != EOF)
{
switch (opt)
{
while ((opt = getopt(argc, argv, "h?o:t:p:")) != EOF) {
switch (opt) {
case 'o':
object_name = optarg;
str_upper(object_name);
@@ -71,8 +65,7 @@ main(int argc, char *argv[])
break;
case 'p':
property_name = optarg;
if (strlen(property_name) > 15)
{
if (strlen(property_name) > 15) {
fprintf(stderr, "%s: Property Name too long\n",
argv[0]);
exit(1);
@@ -89,30 +82,25 @@ main(int argc, char *argv[])
}
}
if (object_type < 0)
{
if (object_type < 0) {
fprintf(stderr, "%s: You must specify an object type\n",
argv[0]);
goto finished;
}
if (object_name == NULL)
{
if (object_name == NULL) {
fprintf(stderr, "%s: You must specify an object name\n",
argv[0]);
goto finished;
}
if (property_name == NULL)
{
if (property_name == NULL) {
fprintf(stderr, "%s: You must specify a property name\n",
argv[0]);
goto finished;
}
if (ncp_delete_property(conn, object_type, object_name,
property_name) != 0)
{
property_name) != 0) {
fprintf(stderr, "%s: Could not delete the property\n", argv[0]);
} else
{
} else {
result = 0;
}

View File

@@ -13,14 +13,12 @@
static char *progname;
static void
usage(void)
static void usage(void)
{
fprintf(stderr, "usage: %s [options]\n", progname);
}
static void
help(void)
static void help(void)
{
printf("\n");
printf("usage: %s [options] [values]\n", progname);
@@ -35,18 +33,16 @@ help(void)
}
static char *
get_line(char *buf, int len, FILE * stream)
get_line(char *buf, int len, FILE * stream)
{
char *result = fgets(buf, len, stream);
if (result != NULL)
{
if (result != NULL) {
buf[strlen(buf) - 1] = '\0'; /* remove newline */
}
return result;
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
struct ncp_conn *conn;
char object_name[49];
@@ -61,15 +57,12 @@ main(int argc, char *argv[])
progname = argv[0];
if ((conn = ncp_initialize(&argc, argv, 1, &err)) == NULL)
{
if ((conn = ncp_initialize(&argc, argv, 1, &err)) == NULL) {
com_err(argv[0], err, "when initializing");
goto finished;
}
while ((opt = getopt(argc, argv, "h?")) != EOF)
{
switch (opt)
{
while ((opt = getopt(argc, argv, "h?")) != EOF) {
switch (opt) {
case 'h':
case '?':
help();
@@ -81,79 +74,67 @@ main(int argc, char *argv[])
}
memset(buf, 0, sizeof(buf));
if (get_line(buf, sizeof(buf), stdin) == NULL)
{
if (get_line(buf, sizeof(buf), stdin) == NULL) {
fprintf(stderr, "Illegal format on stdin\n");
goto finished;
}
object_type = strtoul(buf, NULL, 16);
memset(object_name, 0, sizeof(object_name));
if (get_line(object_name, sizeof(object_name), stdin) == NULL)
{
if (get_line(object_name, sizeof(object_name), stdin) == NULL) {
fprintf(stderr, "Illegal format on stdin\n");
goto finished;
}
memset(property_name, 0, sizeof(property_name));
if (get_line(property_name, sizeof(property_name), stdin) == NULL)
{
if (get_line(property_name, sizeof(property_name), stdin) == NULL) {
fprintf(stderr, "Illegal format on stdin\n");
goto finished;
}
memset(buf, 0, sizeof(buf));
if (get_line(buf, sizeof(buf), stdin) == NULL)
{
if (get_line(buf, sizeof(buf), stdin) == NULL) {
fprintf(stderr, "Illegal format on stdin\n");
goto finished;
}
property_flag = (atoi(buf) & 3);
memset(buf, 0, sizeof(buf));
if (get_line(buf, sizeof(buf), stdin) == NULL)
{
if (get_line(buf, sizeof(buf), stdin) == NULL) {
fprintf(stderr, "Illegal format on stdin\n");
goto finished;
}
property_security = (strtoul(buf, NULL, 16) & 0xff);
if (ncp_scan_property(conn, object_type, object_name,
0xffffffff, property_name, &info) == 0)
{
0xffffffff, property_name, &info) == 0) {
/* Property already exists */
if ((property_flag & 2) != (info.property_flags & 2))
{
if ((property_flag & 2) != (info.property_flags & 2)) {
fprintf(stderr, "Tried to write %s property\n",
(property_flag & 2) != 0 ?
"SET over existing ITEM" :
"ITEM over existing SET");
goto finished;
}
if (info.property_security != property_security)
{
if (info.property_security != property_security) {
if (ncp_change_property_security(conn, object_type,
object_name,
property_name,
property_security) != 0)
{
property_security) != 0) {
fprintf(stderr, "Could not change "
"property security\n");
goto finished;
}
}
} else
{
} else {
if (ncp_create_property(conn, object_type, object_name,
property_name, property_flag,
property_security) != 0)
{
property_security) != 0) {
fprintf(stderr, "Could not create property\n");
goto finished;
}
}
if ((property_flag & 2) == 0)
{
if ((property_flag & 2) == 0) {
/* ITEM property */
int i;
int length;
@@ -162,23 +143,19 @@ main(int argc, char *argv[])
memset(property_value, 0, sizeof(property_value));
for (i = 0; i < sizeof(property_value); i++)
{
if (get_line(buf, sizeof(buf), stdin) == NULL)
{
for (i = 0; i < sizeof(property_value); i++) {
if (get_line(buf, sizeof(buf), stdin) == NULL) {
break;
}
property_value[i] = strtoul(buf, NULL, 16);
}
length = i - 1;
for (segno = 1; segno <= 255; segno++)
{
for (segno = 1; segno <= 255; segno++) {
struct nw_property segment;
int offset = (segno - 1) * 128;
if (offset > length)
{
if (offset > length) {
/* everything written */
break;
}
@@ -187,36 +164,30 @@ main(int argc, char *argv[])
if (ncp_write_property_value(conn, object_type,
object_name,
property_name,
segno, &segment) != 0)
{
segno, &segment) != 0) {
fprintf(stderr, "Could not write property\n");
goto finished;
}
}
} else
{
} else {
/* SET property */
while (get_line(buf, sizeof(buf), stdin) != NULL)
{
while (get_line(buf, sizeof(buf), stdin) != NULL) {
int element_type = strtoul(buf, NULL, 16);
char element_name[49];
memset(element_name, 0, sizeof(element_name));
if (get_line(element_name, sizeof(element_name),
stdin) == NULL)
{
stdin) == NULL) {
fprintf(stderr, "Illegal format on stdin\n");
goto finished;
}
if (ncp_add_object_to_set(conn, object_type,
object_name, property_name,
object_name, property_name,
element_type,
element_name) != 0)
{
if (conn->completion != 0xE9) /* object already
in set */
{
element_name) != 0) {
if (conn->completion != 0xE9) { /* object already
in set */
fprintf(stderr, "Could not add object "
"to set\n");
goto finished;

View File

@@ -17,14 +17,12 @@ static char *progname;
static void
print_property(char *prop_name, __u8 * val, int segments);
static void
usage(void)
static void usage(void)
{
fprintf(stderr, "usage: %s [options]\n", progname);
}
static void
help(void)
static void help(void)
{
printf("\n");
printf("usage: %s [options]\n", progname);
@@ -44,8 +42,7 @@ help(void)
"\n");
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
struct ncp_conn *conn;
char *object_name = NULL;
@@ -65,15 +62,12 @@ main(int argc, char *argv[])
progname = argv[0];
if ((conn = ncp_initialize(&argc, argv, 1, &err)) == NULL)
{
if ((conn = ncp_initialize(&argc, argv, 1, &err)) == NULL) {
com_err(argv[0], err, "when initializing");
goto finished;
}
while ((opt = getopt(argc, argv, "h?o:t:p:vc")) != EOF)
{
switch (opt)
{
while ((opt = getopt(argc, argv, "h?o:t:p:vc")) != EOF) {
switch (opt) {
case 'o':
object_name = optarg;
str_upper(object_name);
@@ -83,8 +77,7 @@ main(int argc, char *argv[])
break;
case 'p':
property_name = optarg;
if (strlen(property_name) > 15)
{
if (strlen(property_name) > 15) {
fprintf(stderr, "%s: Property Name too long\n",
argv[0]);
exit(1);
@@ -107,95 +100,77 @@ main(int argc, char *argv[])
}
}
if (object_type < 0)
{
if (object_type < 0) {
fprintf(stderr, "%s: You must specify an object type\n",
argv[0]);
goto finished;
}
if (object_name == NULL)
{
if (object_name == NULL) {
fprintf(stderr, "%s: You must specify an object name\n",
argv[0]);
goto finished;
}
if (property_name == NULL)
{
if (property_name == NULL) {
fprintf(stderr, "%s: You must specify a property name\n",
argv[0]);
goto finished;
}
if (ncp_scan_property(conn, object_type, object_name,
0xffffffff, property_name, &info) != 0)
{
0xffffffff, property_name, &info) != 0) {
fprintf(stderr, "%s: Could not find property\n", argv[0]);
goto finished;
}
segno = 1;
while (ncp_read_property_value(conn, object_type, object_name,
segno, property_name, &segment) == 0)
{
segno, property_name, &segment) == 0) {
memcpy(&(property_value[(segno - 1) * 128]), segment.value, 128);
if ((segment.more_flag == 0) || (segno == 255))
{
if ((segment.more_flag == 0) || (segno == 255)) {
break;
}
segno += 1;
}
if (canonical != 0)
{
if (canonical != 0) {
printf("%-4.4x\n%s\n", object_type, object_name);
printf("%s\n%d\n%x\n",
info.property_name, info.property_flags, info.property_security);
}
if ((info.property_flags & 2) == 0)
{
if ((info.property_flags & 2) == 0) {
/* ITEM property */
if (canonical != 0)
{
if (canonical != 0) {
int i;
for (i = 0; i < segno * 128; i++)
{
for (i = 0; i < segno * 128; i++) {
printf("%-2.2x\n", property_value[i]);
}
} else
{
} else {
print_property(property_name, property_value, segno);
}
} else
{
} else {
int objects = 32 * segno;
__u32 *value = (__u32 *) property_value;
int i = 0;
while (i < objects)
{
while (i < objects) {
struct ncp_bindery_object o;
if ((value[i] == 0) || (value[i] == 0xffffffff))
{
if ((value[i] == 0) || (value[i] == 0xffffffff)) {
/* Continue with next segment */
i = ((i / 32) + 1) * 32;
continue;
}
if (ncp_get_bindery_object_name(conn, ntohl(value[i]),
&o) == 0)
{
if (canonical != 0)
{
&o) == 0) {
if (canonical != 0) {
printf("%-4.4x\n%s\n",
(unsigned int) o.object_type,
(unsigned int) o.object_type,
o.object_name);
} else if (verbose != 0)
{
} else if (verbose != 0) {
printf("%s %08X %04X\n",
o.object_name,
(unsigned int) o.object_id,
(unsigned int) o.object_type);
} else
{
(unsigned int) o.object_type);
} else {
printf("%s\n", o.object_name);
}
}
@@ -209,25 +184,20 @@ main(int argc, char *argv[])
return result;
}
static void
print_unknown(__u8 * val)
static void print_unknown(__u8 * val)
{
int j = (128 / 16);
while (1)
{
while (1) {
int i;
for (i = 0; i < 16; i++)
{
for (i = 0; i < 16; i++) {
printf("%02X ", val[i]);
}
printf(" [");
for (i = 0; i < 16; i++)
{
for (i = 0; i < 16; i++) {
printf("%c", isprint(val[i]) ? val[i] : '.');
}
j -= 1;
if (j == 0)
{
if (j == 0) {
printf("]\n");
return;
}
@@ -236,29 +206,24 @@ print_unknown(__u8 * val)
}
}
static void
print_string(__u8 * val)
static void print_string(__u8 * val)
{
puts(val);
}
static char *
print_station_addr(char *fmt, struct ncp_station_addr *addr, char *buff)
print_station_addr(char *fmt, struct ncp_station_addr *addr, char *buff)
{
char *ret = buff;
while (*fmt != 0)
{
switch (*fmt)
{
while (*fmt != 0) {
switch (*fmt) {
case '%':
switch (*(++fmt))
{
switch (*(++fmt)) {
case 'N': /* node */
{
int i;
for (i = 0; i < 6; buff += 2, i++)
{
for (i = 0; i < 6; buff += 2, i++) {
sprintf(buff, "%02X", addr->Node[i]);
}
}
@@ -276,8 +241,7 @@ print_station_addr(char *fmt, struct ncp_station_addr *addr, char *buff)
default:
break;
}
if (*fmt)
{
if (*fmt) {
fmt++;
}
break;
@@ -289,8 +253,7 @@ print_station_addr(char *fmt, struct ncp_station_addr *addr, char *buff)
return ret;
}
void
print_login_control(__u8 * val)
void print_login_control(__u8 * val)
{
int i, j, mask;
char buff[32];
@@ -300,30 +263,25 @@ print_login_control(__u8 * val)
{"Sun", "Mon", "Tue", "Wen", "Thu", "Fri", "Sat"};
if (a->LastLogin[2] || a->LastLogin[1] || a->LastLogin[0] ||
a->LastLogin[3] || a->LastLogin[4] || a->LastLogin[5])
{
a->LastLogin[3] || a->LastLogin[4] || a->LastLogin[5]) {
printf("Last Login: %d.%d.%02d at %2d:%02d:%02d\n",
a->LastLogin[2], a->LastLogin[1], a->LastLogin[0],
a->LastLogin[3], a->LastLogin[4], a->LastLogin[5]);
} else
{
} else {
printf("Never logged in\n");
}
if (a->Disabled != 0)
{
if (a->Disabled != 0) {
printf(" --- Account disabled ---\n");
}
if (a->AccountExpireDate[2] || a->AccountExpireDate[1] ||
a->AccountExpireDate[0])
{
a->AccountExpireDate[0]) {
printf("Account expires on: %d.%d.%d\n",
a->AccountExpireDate[2],
a->AccountExpireDate[1],
a->AccountExpireDate[0]);
}
if (a->PasswordExpireDate[2] || a->PasswordExpireDate[1] ||
a->PasswordExpireDate[0])
{
a->PasswordExpireDate[0]) {
printf("Password expires on: %d.%d.%d\n",
a->PasswordExpireDate[2],
a->PasswordExpireDate[1],
@@ -333,64 +291,51 @@ print_login_control(__u8 * val)
printf("PasswortChangeInterval : %d days\n",
ntohs(a->PasswordExpireInterval));
}
if ((a->RestrictionMask & 2) != 0)
{
if ((a->RestrictionMask & 2) != 0) {
printf("New password must be different when changing\n");
}
if ((a->RestrictionMask & 1) != 0)
{
if ((a->RestrictionMask & 1) != 0) {
printf("User ist not allowed to change password\n");
}
printf("Minimal password length : %d\n", a->MinPasswordLength);
if (ntohs(a->MaxConnections) != 0)
{
if (ntohs(a->MaxConnections) != 0) {
printf("Maximum no of connections: %d\n",
ntohs(a->MaxConnections));
}
if (a->MaxDiskUsage != 0xFFFFFF7FL)
{
if (a->MaxDiskUsage != 0xFFFFFF7FL) {
printf("Maximum DiskQuota : %8ld blocks\n",
ntohl(a->MaxDiskUsage));
}
printf("Failed Logins: %5d\n", ntohs(a->BadLoginCount));
if (a->BadLoginCountDown != 0L)
{
if (a->BadLoginCountDown != 0L) {
printf("Account disabled still %8ld seconds\n",
ntohl(a->BadLoginCountDown));
}
if (a->LastIntruder.NetWork != 0L)
{
if (a->LastIntruder.NetWork != 0L) {
printf("Last \'intruder\' address: %s\n",
print_station_addr("(%L): %N[%S]",
&(a->LastIntruder), buff));
}
if (a->RestrictionMask & 0xFC)
{
if (a->RestrictionMask & 0xFC) {
printf("RestrictionMask : %02X\n", a->RestrictionMask);
}
for (i = 0; i < 42; i++)
{
if (a->ConnectionTimeMask[i] != 0xFF)
{
for (i = 0; i < 42; i++) {
if (a->ConnectionTimeMask[i] != 0xFF) {
i = 101;
}
}
if (i < 100)
{
if (i < 100) {
return;
}
val = a->ConnectionTimeMask;
printf("Time restrictions: 1 1 1 1 1 1 1 1 1 1 2 2 2 2 ]\n");
printf(" Day [0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 ]\n");
for (i = 0; i < 7; i++)
{
for (i = 0; i < 7; i++) {
printf(" %s [", days[i]);
for (j = 0; j < 6; j++)
{
for (mask = 1; mask < 0x100; mask <<= 1)
{
for (j = 0; j < 6; j++) {
for (mask = 1; mask < 0x100; mask <<= 1) {
putchar((*val & mask) ? '*' : ' ');
}
val++;
@@ -399,8 +344,7 @@ print_login_control(__u8 * val)
}
}
void
print_addr(__u8 * val)
void print_addr(__u8 * val)
{
char buff[50];
print_station_addr("(%L): %N[%S]",
@@ -408,12 +352,11 @@ print_addr(__u8 * val)
printf("%s\n", buff);
}
static struct
{
static struct {
char *pname;
void (*func) (__u8 *);
}
formats[] =
} formats[] =
{
{
"DESCRIPTION", print_string
@@ -452,28 +395,23 @@ formats[] =
}
};
static void
print_property(char *prop_name, __u8 * val, int segments)
static void print_property(char *prop_name, __u8 * val, int segments)
{
int i;
void (*f) (__u8 *);
for (i = 0; formats[i].pname != NULL; i++)
{
if (strcasecmp(prop_name, formats[i].pname) == 0)
{
for (i = 0; formats[i].pname != NULL; i++) {
if (strcasecmp(prop_name, formats[i].pname) == 0) {
break;
}
}
f = formats[i].func;
if (f != NULL)
{
if (f != NULL) {
f(val);
return;
}
for (i = 0; i < segments; i++)
{
for (i = 0; i < segments; i++) {
printf("Segment: %03d\n", i + 1);
print_unknown(&(val[i * 128]));
printf("\n");

View File

@@ -14,14 +14,12 @@
static char *progname;
static void
usage(void)
static void usage(void)
{
fprintf(stderr, "usage: %s [pattern]\n", progname);
}
static void
help(void)
static void help(void)
{
printf("\n");
printf("usage: %s [options]\n", progname);
@@ -35,8 +33,7 @@ help(void)
"\n");
}
static void
print_info(struct ncp_file_server_info *info)
static void print_info(struct ncp_file_server_info *info)
{
printf("\n");
printf("Fileservername %-48.48s\n", info->ServerName);
@@ -70,8 +67,7 @@ print_info(struct ncp_file_server_info *info)
return;
}
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
struct ncp_conn *conn;
int opt;
@@ -79,15 +75,12 @@ main(int argc, char **argv)
progname = argv[0];
if ((conn = ncp_initialize(&argc, argv, 0, &err)) == NULL)
{
if ((conn = ncp_initialize(&argc, argv, 0, &err)) == NULL) {
com_err(argv[0], err, "when initializing");
return 1;
}
while ((opt = getopt(argc, argv, "h?dti")) != EOF)
{
switch (opt)
{
while ((opt = getopt(argc, argv, "h?dti")) != EOF) {
switch (opt) {
case 'h':
case '?':
help();
@@ -98,18 +91,15 @@ main(int argc, char **argv)
char *s;
if (ncp_get_file_server_description_strings(conn,
strings)
!= 0)
{
strings)
!= 0) {
perror("could not get strings");
ncp_close(conn);
return 1;
}
s = strings;
while (s < strings + 512)
{
if (strlen(s) == 0)
{
while (s < strings + 512) {
if (strlen(s) == 0) {
break;
}
puts(s);
@@ -121,8 +111,7 @@ main(int argc, char **argv)
{
time_t t;
if (ncp_get_file_server_time(conn, &t) != 0)
{
if (ncp_get_file_server_time(conn, &t) != 0) {
perror("could not get server time");
ncp_close(conn);
return 1;
@@ -133,8 +122,7 @@ main(int argc, char **argv)
case 'i':
{
struct ncp_file_server_info info;
if (ncp_get_file_server_information(conn, &info) != 0)
{
if (ncp_get_file_server_information(conn, &info) != 0) {
perror("Could not get server information");
ncp_close(conn);
return 1;

View File

@@ -13,14 +13,12 @@
static char *progname;
static void
usage(void)
static void usage(void)
{
fprintf(stderr, "usage: %s [pattern]\n", progname);
}
static void
help(void)
static void help(void)
{
printf("\n");
printf("usage: %s [options]\n", progname);
@@ -36,8 +34,7 @@ help(void)
"\n");
}
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
struct ncp_conn *conn;
int opt;
@@ -47,15 +44,12 @@ main(int argc, char **argv)
progname = argv[0];
if ((conn = ncp_initialize(&argc, argv, 1, &err)) == NULL)
{
if ((conn = ncp_initialize(&argc, argv, 1, &err)) == NULL) {
com_err(argv[0], err, "when initializing");
return 1;
}
while ((opt = getopt(argc, argv, "h?s")) != EOF)
{
switch (opt)
{
while ((opt = getopt(argc, argv, "h?s")) != EOF) {
switch (opt) {
case 'h':
case '?':
help();
@@ -71,19 +65,15 @@ main(int argc, char **argv)
finished:
if (set != 0)
{
if (set != 0) {
time(&t);
if ((err = ncp_set_file_server_time(conn, &t)) != 0)
{
if ((err = ncp_set_file_server_time(conn, &t)) != 0) {
com_err(argv[0], err, "when setting file server time");
ncp_close(conn);
return 1;
}
} else
{
if ((err = ncp_get_file_server_time(conn, &t)) != 0)
{
} else {
if ((err = ncp_get_file_server_time(conn, &t)) != 0) {
com_err(argv[0], err, "when getting file server time");
ncp_close(conn);
return 1;

View File

@@ -13,14 +13,12 @@
static char *progname;
static void
usage(void)
static void usage(void)
{
fprintf(stderr, "usage: %s [options]\n", progname);
}
static void
help(void)
static void help(void)
{
printf("\n");
printf("usage: %s [options] file/directory\n", progname);
@@ -40,8 +38,7 @@ help(void)
"\n");
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
struct ncp_conn *conn;
char *object_name = NULL;
@@ -55,15 +52,12 @@ main(int argc, char *argv[])
progname = argv[0];
if ((conn = ncp_initialize(&argc, argv, 1, &err)) == NULL)
{
if ((conn = ncp_initialize(&argc, argv, 1, &err)) == NULL) {
com_err(argv[0], err, "when initializing");
goto finished;
}
while ((opt = getopt(argc, argv, "h?o:t:r:")) != EOF)
{
switch (opt)
{
while ((opt = getopt(argc, argv, "h?o:t:r:")) != EOF) {
switch (opt) {
case 'o':
object_name = optarg;
str_upper(object_name);
@@ -84,40 +78,34 @@ main(int argc, char *argv[])
}
}
if (object_type < 0)
{
if (object_type < 0) {
fprintf(stderr, "%s: You must specify an object type\n",
argv[0]);
goto finished;
}
if (object_name == NULL)
{
if (object_name == NULL) {
fprintf(stderr, "%s: You must specify an object name\n",
argv[0]);
goto finished;
}
if (rights < 0)
{
if (rights < 0) {
fprintf(stderr, "%s: You must specify a rights mask\n",
progname);
goto finished;
}
if (optind != argc - 1)
{
if (optind != argc - 1) {
fprintf(stderr, "%s: You must specify a directory\n",
progname);
goto finished;
}
path = argv[optind];
if (ncp_get_bindery_object_id(conn, object_type, object_name, &o) != 0)
{
if (ncp_get_bindery_object_id(conn, object_type, object_name, &o) != 0) {
fprintf(stderr, "%s: Could not find object %s\n",
progname, object_name);
goto finished;
}
if (ncp_add_trustee(conn, 0, path, o.object_id, rights) != 0)
{
if (ncp_add_trustee(conn, 0, path, o.object_id, rights) != 0) {
fprintf(stderr, "%s: Could not add trustee rights\n", progname);
goto finished;
}

View File

@@ -1,214 +0,0 @@
/*
* 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];
char *mount_point;
struct ncp_fs_info info;
struct passwd *pwd;
char tty[256];
char tty_path[256];
FILE *tty_file;
FILE *mtab;
struct mntent *mnt;
long err;
progname = argv[0];
openlog("nwmsg", LOG_PID, LOG_LPR);
if (argc != 2)
{
fprintf(stderr, "usage: %s mount-point\n",
progname);
exit(1);
}
mount_point = argv[1];
if ((conn = ncp_open_mount(mount_point, &err)) == NULL)
{
com_err(progname, err, "in ncp_open_mount");
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, 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\r\n",
mnt->mnt_fsname);
fprintf(tty_file, "%s\r\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;
}

View File

@@ -13,14 +13,12 @@
static char *progname;
static void
usage(void)
static void usage(void)
{
fprintf(stderr, "usage: %s [options]\n", progname);
}
static void
help(void)
static void help(void)
{
printf("\n");
printf("usage: %s [options]\n", progname);
@@ -34,8 +32,7 @@ help(void)
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
struct ncp_conn_spec *spec;
struct ncp_conn *conn;
@@ -56,10 +53,8 @@ main(int argc, char *argv[])
progname = argv[0];
while ((opt = getopt(argc, argv, "h?S:U:O:t:")) != EOF)
{
switch (opt)
{
while ((opt = getopt(argc, argv, "h?S:U:O:t:")) != EOF) {
switch (opt) {
case 'S':
server = optarg;
break;
@@ -84,16 +79,13 @@ main(int argc, char *argv[])
spec = ncp_find_conn_spec(server, user_name, "",
1, getuid(), &err);
if (spec == NULL)
{
if (spec == NULL) {
com_err(argv[0], err, "trying to find server");
exit(1);
}
if (!object_name)
{
if (!object_name) {
object_name = spec->user;
} else
{
} else {
strcpy(buf_obj_name, object_name);
object_name = buf_obj_name;
str_upper(object_name);
@@ -103,33 +95,28 @@ main(int argc, char *argv[])
printf("Changing password for user %s on server %s\n",
object_name, spec->server);
if (object_name == spec->user)
{
if (object_name == spec->user) {
str = getpass("Enter old password: ");
} else
{
} else {
char sx[80];
sprintf(sx, "Enter password for %s: ", spec->user);
str = getpass(sx);
}
if (strlen(str) >= sizeof(oldpass))
{
if (strlen(str) >= sizeof(oldpass)) {
printf("Password too long\n");
exit(1);
}
strcpy(oldpass, str);
str = getpass("Enter new password: ");
if (strlen(str) >= sizeof(newpass1))
{
if (strlen(str) >= sizeof(newpass1)) {
printf("Password too long\n");
exit(1);
}
strcpy(newpass1, str);
str = getpass("Re-Enter new password: ");
if (strlen(str) >= sizeof(newpass2))
{
if (strlen(str) >= sizeof(newpass2)) {
printf("Password too long\n");
exit(1);
}
@@ -139,27 +126,22 @@ main(int argc, char *argv[])
str_upper(newpass1);
str_upper(newpass2);
if (strcmp(newpass1, newpass2) != 0)
{
if (strcmp(newpass1, newpass2) != 0) {
printf("You mistype the new password, try again\n");
exit(1);
}
strcpy(spec->password, oldpass);
if ((conn = ncp_open(spec, &err)) == NULL)
{
if ((conn = ncp_open(spec, &err)) == NULL) {
com_err(argv[0], err, "when trying to open connection");
exit(1);
}
if (object_name != spec->user)
{
if (object_name != spec->user) {
if (!(err = ncp_get_bindery_object_id(conn, 1, spec->user,
&user))
&& !(err = ncp_login_user(conn, spec->user, oldpass)))
{
&& !(err = ncp_login_user(conn, spec->user, oldpass))) {
*oldpass = '\0';
} else
{
} else {
com_err(argv[0], err, "not own password");
}
}
@@ -167,8 +149,7 @@ main(int argc, char *argv[])
|| ((err = ncp_get_bindery_object_id(conn, 1, object_name,
&user)) != 0)
|| ((err = ncp_change_login_passwd(conn, &user, ncp_key,
oldpass, newpass1)) != 0))
{
oldpass, newpass1)) != 0)) {
com_err(argv[0], err, "trying to change password");
}
ncp_close(conn);

View File

@@ -13,14 +13,12 @@
static char *progname;
static void
usage(void)
static void usage(void)
{
fprintf(stderr, "usage: %s [options]\n", progname);
}
static void
help(void)
static void help(void)
{
printf("\n");
printf("usage: %s [options] file/directory\n", progname);
@@ -39,8 +37,7 @@ help(void)
"\n");
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
struct ncp_conn *conn;
char *object_name = NULL;
@@ -53,15 +50,12 @@ main(int argc, char *argv[])
progname = argv[0];
if ((conn = ncp_initialize(&argc, argv, 1, &err)) == NULL)
{
if ((conn = ncp_initialize(&argc, argv, 1, &err)) == NULL) {
com_err(argv[0], err, "when initializing");
goto finished;
}
while ((opt = getopt(argc, argv, "h?o:t:")) != EOF)
{
switch (opt)
{
while ((opt = getopt(argc, argv, "h?o:t:")) != EOF) {
switch (opt) {
case 'o':
object_name = optarg;
str_upper(object_name);
@@ -79,34 +73,29 @@ main(int argc, char *argv[])
}
}
if (object_type < 0)
{
if (object_type < 0) {
fprintf(stderr, "%s: You must specify an object type\n",
argv[0]);
goto finished;
}
if (object_name == NULL)
{
if (object_name == NULL) {
fprintf(stderr, "%s: You must specify an object name\n",
argv[0]);
goto finished;
}
if (optind != argc - 1)
{
if (optind != argc - 1) {
fprintf(stderr, "%s: You must specify a directory\n",
progname);
goto finished;
}
path = argv[optind];
if (ncp_get_bindery_object_id(conn, object_type, object_name, &o) != 0)
{
if (ncp_get_bindery_object_id(conn, object_type, object_name, &o) != 0) {
fprintf(stderr, "%s: Could not find object %s\n",
progname, object_name);
goto finished;
}
if (ncp_delete_trustee(conn, 0, path, o.object_id) != 0)
{
if (ncp_delete_trustee(conn, 0, path, o.object_id) != 0) {
fprintf(stderr, "%s: Could not remove trustee rights\n",
progname);
goto finished;

View File

@@ -13,14 +13,12 @@
static char *progname;
static void
usage(void)
static void usage(void)
{
fprintf(stderr, "usage: %s [options]\n", progname);
}
static void
help(void)
static void help(void)
{
printf("\n");
printf("usage: %s [options] file/directory\n", progname);
@@ -31,8 +29,7 @@ help(void)
"\n");
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
struct ncp_conn *conn = NULL;
char *path = ".";
@@ -43,10 +40,8 @@ main(int argc, char *argv[])
progname = argv[0];
while ((opt = getopt(argc, argv, "h?")) != EOF)
{
switch (opt)
{
while ((opt = getopt(argc, argv, "h?")) != EOF) {
switch (opt) {
case 'h':
case '?':
help();
@@ -57,25 +52,21 @@ main(int argc, char *argv[])
}
}
if (optind > argc)
{
if (optind > argc) {
usage();
goto finished;
}
if (optind == argc - 1)
{
if (optind == argc - 1) {
path = argv[optind];
}
if ((conn = ncp_open_mount(path, &err)) == NULL)
{
if ((conn = ncp_open_mount(path, &err)) == NULL) {
com_err(argv[0], err, "when initializing");
goto finished;
}
if ((err = ncp_get_eff_directory_rights(conn, 0, 0, 0x8006,
conn->i.volume_number,
conn->i.directory_id, NULL,
&rights)) != 0)
{
conn->i.directory_id, NULL,
&rights)) != 0) {
com_err(argv[0], err, "when finding rights");
goto finished;
}
@@ -90,36 +81,28 @@ main(int argc, char *argv[])
((rights & NCP_PERM_SEARCH) != 0) ? 'F' : ' ',
((rights & NCP_PERM_OWNER) != 0) ? 'A' : ' ');
if ((rights & NCP_PERM_SUPER) != 0)
{
if ((rights & NCP_PERM_SUPER) != 0) {
printf("(S): You have SUPERVISOR rights\n");
}
if ((rights & NCP_PERM_READ) != 0)
{
if ((rights & NCP_PERM_READ) != 0) {
printf("(R): You may READ from files\n");
}
if ((rights & NCP_PERM_WRITE) != 0)
{
if ((rights & NCP_PERM_WRITE) != 0) {
printf("(W): You may WRITE to files\n");
}
if ((rights & NCP_PERM_CREATE) != 0)
{
if ((rights & NCP_PERM_CREATE) != 0) {
printf("(C): You may CREATE files\n");
}
if ((rights & NCP_PERM_DELETE) != 0)
{
if ((rights & NCP_PERM_DELETE) != 0) {
printf("(E): You may ERASE files\n");
}
if ((rights & NCP_PERM_MODIFY) != 0)
{
if ((rights & NCP_PERM_MODIFY) != 0) {
printf("(M): You may MODIFY directory\n");
}
if ((rights & NCP_PERM_SEARCH) != 0)
{
if ((rights & NCP_PERM_SEARCH) != 0) {
printf("(F): You may SCAN for files\n");
}
if ((rights & NCP_PERM_OWNER) != 0)
{
if ((rights & NCP_PERM_OWNER) != 0) {
printf("(A): You may change ACCESS control\n");
}
result = 0;

View File

@@ -15,15 +15,13 @@
static char *progname;
static void
usage(void)
static void usage(void)
{
fprintf(stderr, "usage: %s [options] pattern\n", progname);
return;
}
static void
help(void)
static void help(void)
{
printf("\n");
printf("usage: %s [options]\n", progname);
@@ -44,8 +42,7 @@ help(void)
"\n");
}
int
fromhex(char c)
int fromhex(char c)
{
c -= '0';
if (c > 9)
@@ -53,8 +50,7 @@ fromhex(char c)
return c & 15;
}
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
struct ncp_conn *conn;
struct ncp_bindery_object bobj;
@@ -69,15 +65,12 @@ main(int argc, char **argv)
progname = argv[0];
if ((conn = ncp_initialize(&argc, argv, 1, &err)) == NULL)
{
if ((conn = ncp_initialize(&argc, argv, 1, &err)) == NULL) {
com_err(argv[0], err, "when initializing");
return 1;
}
while ((opt = getopt(argc, argv, "h?vl:L:o:O:t:")) != EOF)
{
switch (opt)
{
while ((opt = getopt(argc, argv, "h?vl:L:o:O:t:")) != EOF) {
switch (opt) {
case 'h':
case '?':
help();
@@ -86,8 +79,7 @@ main(int argc, char **argv)
vid = atoi(optarg);
break;
case 'L':
if (ncp_get_volume_number(conn, optarg, &vid))
{
if (ncp_get_volume_number(conn, optarg, &vid)) {
ncp_close(conn);
return 1;
}
@@ -95,19 +87,16 @@ main(int argc, char **argv)
case 'o':
oid = 0;
while (*optarg)
{
while (*optarg) {
oid = (oid << 4) | fromhex(*optarg);
optarg++;
}
break;
case 'O':
for (p = optarg; *p != 0; p++)
{
for (p = optarg; *p != 0; p++) {
*p = toupper(*p);
}
if (ncp_get_bindery_object_id(conn, type, optarg, &bobj))
{
if (ncp_get_bindery_object_id(conn, type, optarg, &bobj)) {
ncp_close(conn);
return 1;
}
@@ -125,30 +114,25 @@ main(int argc, char **argv)
}
}
if (optind < argc)
{
if (optind < argc) {
usage();
exit(1);
}
nextp = 0;
while (!ncp_get_trustee(conn, oid, vid, ppath, &trust, &nextp))
{
while (!ncp_get_trustee(conn, oid, vid, ppath, &trust, &nextp)) {
if (!nextp)
break;
printf("%s ", ppath);
if (verbose)
{
if (verbose) {
strcpy(ppath, "[ R W O C E A F M ]");
p = ppath + 2;
for (type = 1; type < 256; type <<= 1)
{
for (type = 1; type < 256; type <<= 1) {
if (!(trust & type))
*p = ' ';
p += 2;
}
printf("%s\n", ppath);
} else
{
} else {
printf("%X\n", trust);
}
}

View File

@@ -13,26 +13,22 @@
static char *progname;
static void
usage(void)
static void usage(void)
{
fprintf(stderr, "usage: %s [pattern]\n", progname);
}
static void
str_trim_right(char *s, char c)
static void str_trim_right(char *s, char c)
{
int len = strlen(s) - 1;
while ((len > 0) && (s[len] == c))
{
while ((len > 0) && (s[len] == c)) {
s[len] = '\0';
len -= 1;
}
}
static void
help(void)
static void help(void)
{
printf("\n");
printf("usage: %s [options]\n", progname);
@@ -43,8 +39,7 @@ help(void)
"\n");
}
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
struct ncp_conn *conn;
int opt;
@@ -57,15 +52,12 @@ main(int argc, char **argv)
progname = argv[0];
if ((conn = ncp_initialize(&argc, argv, 1, &err)) == NULL)
{
if ((conn = ncp_initialize(&argc, argv, 1, &err)) == NULL) {
com_err(argv[0], err, "when initializing");
goto finished;
}
while ((opt = getopt(argc, argv, "h?a")) != EOF)
{
switch (opt)
{
while ((opt = getopt(argc, argv, "h?a")) != EOF) {
switch (opt) {
case 'h':
case '?':
help();
@@ -79,26 +71,22 @@ main(int argc, char **argv)
}
}
if (ncp_get_file_server_information(conn, &info) != 0)
{
if (ncp_get_file_server_information(conn, &info) != 0) {
perror("Could not get server information");
ncp_close(conn);
return 1;
}
if (isatty(1))
{
if (print_addr == 0)
{
if (isatty(1)) {
if (print_addr == 0) {
printf("\n%-6s%-21s%-12s\n"
"---------------------------------------------"
"---------------------------------------------"
"------\n",
"Conn",
"User name",
"Login time");
} else
{
} else {
printf("\n%-6s%-21s%-27s%-12s\n"
"---------------------------------------------"
"---------------------------------------------"
"---------------------------------\n",
"Conn",
"User name",
@@ -106,21 +94,18 @@ main(int argc, char **argv)
"Login time");
}
}
for (i = 1; i <= info.MaximumServiceConnections; i++)
{
for (i = 1; i <= info.MaximumServiceConnections; i++) {
char name[49];
name[48] = '\0';
if (ncp_get_stations_logged_info(conn, i, &user,
&login_time) != 0)
{
&login_time) != 0) {
continue;
}
memcpy(name, user.object_name, 48);
str_trim_right(name, ' ');
printf("%4d: %-20s ", i, name);
if (print_addr != 0)
{
if (print_addr != 0) {
struct sockaddr_ipx addr;
__u8 conn_type;

View File

@@ -15,15 +15,13 @@
static char *progname;
static void
usage(void)
static void usage(void)
{
fprintf(stderr, "usage: %s [options] pattern\n", progname);
return;
}
static void
help(void)
static void help(void)
{
printf("\n");
printf("usage: %s [options]\n", progname);
@@ -40,8 +38,7 @@ help(void)
"\n");
}
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
struct ncp_conn *conn;
struct ncp_volume_info o;
@@ -54,15 +51,12 @@ main(int argc, char **argv)
progname = argv[0];
if ((conn = ncp_initialize(&argc, argv, 1, &err)) == NULL)
{
if ((conn = ncp_initialize(&argc, argv, 1, &err)) == NULL) {
com_err(argv[0], err, "when initializing");
return 1;
}
while ((opt = getopt(argc, argv, "h?Nv:")) != EOF)
{
switch (opt)
{
while ((opt = getopt(argc, argv, "h?Nv:")) != EOF) {
switch (opt) {
case 'h':
case '?':
help();
@@ -79,23 +73,19 @@ main(int argc, char **argv)
}
}
if (optind < argc)
{
if (optind < argc) {
usage();
exit(1);
}
if (ncp_get_volume_number(conn, volname, &opt))
{
if (ncp_get_volume_number(conn, volname, &opt)) {
exit(1);
}
if (ncp_get_volume_info_with_number(conn, opt, &o))
{
if (ncp_get_volume_info_with_number(conn, opt, &o)) {
exit(1);
}
numk = o.sectors_per_block / 2;
o.free_blocks += o.purgeable_blocks;
if (type)
{
if (type) {
printf("%d %d %d %d %d %d\n",
o.total_blocks * numk,
o.free_blocks * numk,
@@ -103,8 +93,7 @@ main(int argc, char **argv)
o.not_yet_purgeable_blocks * numk,
o.total_dir_entries,
o.available_dir_entries);
} else
{
} else {
printf("Total : %dK\n", o.total_blocks * numk);
printf("Free : %dK\n", o.free_blocks * numk);
printf("Purgable : %dK\n", o.purgeable_blocks * numk);

View File

@@ -12,8 +12,7 @@
#include <ctype.h>
#include "ncplib.h"
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
struct ncp_conn *conn;
struct ncp_bindery_object q;
@@ -24,27 +23,22 @@ main(int argc, char **argv)
char *p;
long err;
if ((conn = ncp_initialize(&argc, argv, 1, &err)) == NULL)
{
if ((conn = ncp_initialize(&argc, argv, 1, &err)) == NULL) {
com_err(argv[0], err, "when initializing");
return 1;
}
if (argc > 2)
{
if (argc > 2) {
fprintf(stderr, "usage: %s [options] [pattern]\n", argv[0]);
return 1;
}
if (argc == 2)
{
if (argc == 2) {
pattern = argv[1];
}
for (p = pattern; *p != '\0'; p++)
{
for (p = pattern; *p != '\0'; p++) {
*p = toupper(*p);
}
if (isatty(1))
{
if (isatty(1)) {
printf("\nServer: %s\n", conn->server);
printf("%-52s%-10s\n"
"-----------------------------------------------"
@@ -55,15 +49,13 @@ main(int argc, char **argv)
q.object_id = 0xffffffff;
while (ncp_scan_bindery_object(conn, q.object_id,
NCP_BINDERY_PQUEUE, pattern, &q) == 0)
{
NCP_BINDERY_PQUEUE, pattern, &q) == 0) {
found = 1;
printf("%-52s", q.object_name);
printf("%08X\n", (unsigned int) q.object_id);
}
if ((found == 0) && (isatty(1)))
{
if ((found == 0) && (isatty(1))) {
printf("No queues found\n");
}
ncp_close(conn);

View File

@@ -18,8 +18,7 @@
#include <signal.h>
#include "ncplib.h"
struct nw_queue
{
struct nw_queue {
struct ncp_conn *conn;
char queue_name[NCP_BINDERY_NAME_LEN];
@@ -41,15 +40,13 @@ static int
static int
poll_queue(struct nw_queue *q);
static void
usage(void)
static void usage(void)
{
fprintf(stderr, "usage: %s [options] file\n", progname);
exit(1);
}
static void
help(void)
static void help(void)
{
printf("\n");
printf("usage: %s [options]\n", progname);
@@ -72,8 +69,7 @@ help(void)
#define NCP_BINDERY_PSERVER (0x0007)
#endif
static void
terminate_handler()
static void terminate_handler()
{
signal(SIGTERM, terminate_handler);
signal(SIGINT, terminate_handler);
@@ -81,16 +77,13 @@ terminate_handler()
}
/* Daemon_init is taken from Stevens, Adv. Unix programming */
static int
daemon_init(void)
static int daemon_init(void)
{
pid_t pid;
if ((pid = fork()) < 0)
{
if ((pid = fork()) < 0) {
return -1;
} else if (pid != 0)
{
} else if (pid != 0) {
exit(0); /* parent vanishes */
}
/* child process */
@@ -103,8 +96,7 @@ daemon_init(void)
return 0;
}
int
main(int argc, char *argv[])
int main(int argc, char *argv[])
{
struct ncp_conn *conn;
int poll_timeout = 30;
@@ -121,40 +113,32 @@ main(int argc, char *argv[])
progname = argv[0];
for (i = 1; i < argc; i += 1)
{
for (i = 1; i < argc; i += 1) {
if ((strcmp(argv[i], "-h") == 0)
|| (strcmp(argv[i], "-?") == 0))
{
|| (strcmp(argv[i], "-?") == 0)) {
help();
exit(0);
}
}
for (i = 1; i < argc; i += 1)
{
if (strcmp(argv[i], "-d") == 0)
{
for (i = 1; i < argc; i += 1) {
if (strcmp(argv[i], "-d") == 0) {
debug = 1;
break;
}
}
if (debug == 0)
{
if (debug == 0) {
daemon_init();
openlog("pserver", LOG_PID, LOG_LPR);
}
if ((conn = ncp_initialize_as(&argc, argv, 1,
NCP_BINDERY_PSERVER, &err)) == NULL)
{
NCP_BINDERY_PSERVER, &err)) == NULL) {
com_err(argv[0], err, "when initializing");
return 1;
}
while ((opt = getopt(argc, argv, "q:c:j:t:dh")) != EOF)
{
switch (opt)
{
while ((opt = getopt(argc, argv, "q:c:j:t:dh")) != EOF) {
switch (opt) {
case 'q':
queue_name = optarg;
break;
@@ -178,20 +162,17 @@ main(int argc, char *argv[])
}
}
if (argc != optind)
{
if (argc != optind) {
usage();
return -1;
}
memzero(q);
if (queue_name == NULL)
{
if (queue_name == NULL) {
fprintf(stderr, "You must specify a queue\n");
return 1;
}
if (init_queue(conn, queue_name, command, &q) != 0)
{
if (init_queue(conn, queue_name, command, &q) != 0) {
perror("Could not init queue");
ncp_close(conn);
return 1;
@@ -202,15 +183,12 @@ main(int argc, char *argv[])
signal(SIGTERM, terminate_handler);
signal(SIGINT, terminate_handler);
while (1)
{
while (1) {
if ((poll_queue(&q) != 0)
&& (term_request == 0))
{
&& (term_request == 0)) {
continue;
}
if (term_request != 0)
{
if (term_request != 0) {
break;
}
sleep(poll_timeout);
@@ -222,9 +200,8 @@ main(int argc, char *argv[])
return 0;
}
static int
init_queue(struct ncp_conn *conn, char *queue_name, char *command,
struct nw_queue *q)
static int init_queue(struct ncp_conn *conn, char *queue_name, char *command,
struct nw_queue *q)
{
struct ncp_bindery_object obj;
@@ -234,16 +211,14 @@ init_queue(struct ncp_conn *conn, char *queue_name, char *command,
q->command = command;
if (ncp_get_bindery_object_id(conn, NCP_BINDERY_PQUEUE,
queue_name, &obj) != 0)
{
queue_name, &obj) != 0) {
fprintf(stderr, "Queue %s not found\n", queue_name);
return -1;
}
q->queue_id = obj.object_id;
memcpy(q->queue_name, obj.object_name, sizeof(q->queue_name));
if (ncp_attach_to_queue(conn, q->queue_id) != 0)
{
if (ncp_attach_to_queue(conn, q->queue_id) != 0) {
fprintf(stderr, "Could not attach to queue %s\n",
queue_name);
return -1;
@@ -252,18 +227,15 @@ init_queue(struct ncp_conn *conn, char *queue_name, char *command,
}
void
build_command(struct nw_queue *q, struct queue_job *j,
char *target, int target_size)
void build_command(struct nw_queue *q, struct queue_job *j,
char *target, int target_size)
{
char *s = q->command;
char *target_end = target + target_size;
void add_string(char *s)
{
void add_string(char *s) {
int len = strlen(s);
if (target + len + 1 > target_end)
{
if (target + len + 1 > target_end) {
len = target_end - target - 1;
}
strncpy(target, s, len);
@@ -273,17 +245,14 @@ build_command(struct nw_queue *q, struct queue_job *j,
memset(target, 0, target_size);
while ((*s != 0) && (target < target_end))
{
if (*s != '%')
{
while ((*s != 0) && (target < target_end)) {
if (*s != '%') {
*target = *s;
target += 1;
s += 1;
continue;
}
switch (*(s + 1))
{
switch (*(s + 1)) {
case '%':
*target = '%';
target += 1;
@@ -293,11 +262,9 @@ build_command(struct nw_queue *q, struct queue_job *j,
struct ncp_bindery_object u;
if (ncp_get_bindery_object_name
(q->conn, j->j.ClientObjectID, &u)
== 0)
{
== 0) {
user = u.object_name;
} else
{
} else {
user = "*UNKNOWN USER*";
}
add_string(user);
@@ -314,31 +281,26 @@ build_command(struct nw_queue *q, struct queue_job *j,
static int
poll_queue(struct nw_queue *q)
static int poll_queue(struct nw_queue *q)
{
struct queue_job job;
int fd[2];
int pid;
if (ncp_service_queue_job(q->conn, q->queue_id, q->job_type,
&job) != 0)
{
&job) != 0) {
/* No job for us */
return 0;
}
if (pipe(fd) < 0)
{
if (pipe(fd) < 0) {
syslog(LOG_ERR, "pipe error: %m");
goto fail;
}
if ((pid = fork()) < 0)
{
if ((pid = fork()) < 0) {
syslog(LOG_ERR, "fork error: %m");
goto fail;
}
if (pid > 0)
{
if (pid > 0) {
/* parent */
char buf[1024];
size_t result;
@@ -347,33 +309,27 @@ poll_queue(struct nw_queue *q)
close(fd[0]); /* close read end */
while ((result = ncp_read(q->conn, job.file_handle, offset,
sizeof(buf), buf)) > 0)
{
sizeof(buf), buf)) > 0) {
offset += result;
if (write(fd[1], buf, result) != result)
{
if (write(fd[1], buf, result) != result) {
goto fail;
}
}
close(fd[1]); /* and close write end */
if (waitpid(pid, NULL, 0) < 0)
{
if (waitpid(pid, NULL, 0) < 0) {
syslog(LOG_ERR, "waitpid: %m\n");
}
} else
{
} else {
/* child */
char command[2048];
close(fd[1]); /* close write end */
if (fd[0] != STDIN_FILENO)
{
if (dup2(fd[0], STDIN_FILENO) != STDIN_FILENO)
{
if (fd[0] != STDIN_FILENO) {
if (dup2(fd[0], STDIN_FILENO) != STDIN_FILENO) {
syslog(LOG_ERR, "dup2 error: %m\n");
close(fd[0]);
exit(1);

View File

@@ -14,8 +14,7 @@
#include <string.h>
#include <ctype.h>
void
main(int argc, char *argv[])
void main(int argc, char *argv[])
{
struct ncp_conn *conn;
struct ncp_bindery_object obj;
@@ -25,27 +24,22 @@ main(int argc, char *argv[])
char *p;
long err;
if (argc > 2)
{
if (argc > 2) {
printf("usage: %s [pattern]\n", argv[0]);
exit(1);
}
if (argc == 2)
{
if (argc == 2) {
pattern = argv[1];
}
for (p = pattern; *p != '\0'; p++)
{
for (p = pattern; *p != '\0'; p++) {
*p = toupper(*p);
}
if ((conn = ncp_open(NULL, &err)) == NULL)
{
if ((conn = ncp_open(NULL, &err)) == NULL) {
com_err(argv[0], err, "in ncp_open");
exit(1);
}
if (isatty(1))
{
if (isatty(1)) {
printf("\n%-52s%-10s%-12s\n"
"-----------------------------------------------"
"---------------------------\n",
@@ -57,8 +51,7 @@ main(int argc, char *argv[])
while (ncp_scan_bindery_object(conn, obj.object_id,
NCP_BINDERY_FSERVER, pattern,
&obj) == 0)
{
&obj) == 0) {
struct nw_property prop;
struct prop_net_address *naddr
= (struct prop_net_address *) &prop;
@@ -68,9 +61,8 @@ main(int argc, char *argv[])
printf("%-52s", obj.object_name);
if (ncp_read_property_value(conn, NCP_BINDERY_FSERVER,
obj.object_name, 1, "NET_ADDRESS",
&prop) == 0)
{
obj.object_name, 1, "NET_ADDRESS",
&prop) == 0) {
ipx_print_network(naddr->network);
printf(" ");
ipx_print_node(naddr->node);
@@ -78,8 +70,7 @@ main(int argc, char *argv[])
printf("\n");
}
if ((found == 0) && (isatty(1)))
{
if ((found == 0) && (isatty(1))) {
printf("No servers found\n");
}
ncp_close(conn);