* userv - client.c
* client code
*
- * Copyright (C)1996-1997 Ian Jackson
+ * Copyright (C)1996-1997,1999 Ian Jackson
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
#include "config.h"
#include "common.h"
+#include "both.h"
#include "version.h"
enum fdmodifiervalues {
static gid_t mygid, spoofgid, *gidarray;
static int ngids;
static struct opening_msg opening_mbuf;
-static const char *logname;
+static const char *loginname;
static char *cwdbuf;
static size_t cwdbufsize;
static char *ovbuf;
static void xfread(void *p, size_t sz, FILE *file) {
size_t nr;
- nr= fread(p,1,sz,file);
+ nr= working_fread(p,sz,file);
if (nr != sz) protoreaderror(file,"in data");
}
protoerror("stderr message length %d is far too long",
progress_r->data.errmsg.messagelen);
for (i=0; i<progress_r->data.errmsg.messagelen; i++) {
- c= getc(file); if (c==EOF) protoreaderror(file,"in error message");
+ c= working_getc(file);
+ if (c==EOF) protoreaderror(file,"in error message");
if (isprint(c)) putc(c,stderr);
else fprintf(stderr,"\\x%02x",(unsigned char)c);
}
char *equals;
if (oip->values == 2) {
equals= strchr(arg,'=');
- if (!equals)
+ if (!equals) {
if (oip->abbrev)
usageerror("option --%s (-%c) passed argument `%s' with no `='",
oip->full,oip->abbrev,arg);
else
usageerror("option --%s passed argument `%s' with no `='",
oip->full,arg);
+ }
*equals++= 0;
(oip->fn)(oip,equals,arg);
} else {
spoofuid= myuid;
spoofgid= mygid;
- logname= getenv("LOGNAME");
- if (!logname) logname= getenv("USER");
- if (logname) {
- pw= getpwnam(logname);
- if (!pw || pw->pw_uid != myuid) logname= 0;
+ loginname= getenv("LOGNAME");
+ if (!loginname) loginname= getenv("USER");
+ if (loginname) {
+ pw= getpwnam(loginname);
+ if (!pw || pw->pw_uid != myuid) loginname= 0;
}
- if (!logname) {
+ if (!loginname) {
pw= getpwuid(myuid); if (!pw) miscerror("cannot determine your login name");
- logname= pw->pw_name;
+ loginname= pw->pw_name;
}
- if (!strcmp(serviceuser,"-")) serviceuser= logname;
+ if (!strcmp(serviceuser,"-")) serviceuser= loginname;
pw= getpwnam(serviceuser);
if (!pw) miscerror("requested service user `%s' is not a user",serviceuser);
serviceuid= pw->pw_uid;
" the user who will be providing the service");
if (spoofuser) {
- logname= spoofuser;
- pw= getpwnam(logname);
- if (!pw) miscerror("spoofed login name `%s' is not valid",logname);
+ loginname= spoofuser;
+ pw= getpwnam(loginname);
+ if (!pw) miscerror("spoofed login name `%s' is not valid",loginname);
spoofuid= pw->pw_uid;
spoofgid= pw->pw_gid;
ngidssize= ngids; ngids= 0;
}
gidarray[ngids++]= spoofgid;
while ((gr= getgrent())) { /* ouch! getgrent has no error behaviour! */
- for (mem= gr->gr_mem; *mem && strcmp(*mem,logname); mem++);
+ for (mem= gr->gr_mem; *mem && strcmp(*mem,loginname); mem++);
if (!*mem) continue;
if (ngids>=ngidssize) {
if (ngids>=MAX_GIDS) miscerror("spoofed user is member of too many groups");
request_mbuf.clientpid= getpid();
request_mbuf.serviceuserlen= strlen(serviceuser);
request_mbuf.servicelen= strlen(argv[0]);
- request_mbuf.lognamelen= strlen(logname);
+ request_mbuf.loginnamelen= strlen(loginname);
request_mbuf.spoofed= spoofuser ? 1 : 0;
request_mbuf.cwdlen= cwdbufsize;
request_mbuf.callinguid= spoofuid;
xfwrite(&request_mbuf,sizeof(request_mbuf),swfile);
xfwrite(serviceuser,sizeof(*serviceuser)*request_mbuf.serviceuserlen,swfile);
xfwrite(argv[0],sizeof(*argv[0])*request_mbuf.servicelen,swfile);
- xfwrite(logname,sizeof(*logname)*request_mbuf.lognamelen,swfile);
+ xfwrite(loginname,sizeof(*loginname)*request_mbuf.loginnamelen,swfile);
xfwrite(cwdbuf,sizeof(*cwdbuf)*request_mbuf.cwdlen,swfile);
if (ovused>=0) xfwrite(ovbuf,sizeof(*ovbuf)*ovused,swfile);
xfwrite(&spoofgid,sizeof(gid_t),swfile);
struct sigaction sig;
char catnamebuf[sizeof(int)*3+30];
int fd, reading;
+ pid_t child;
for (fd=0; fd<fdsetupsize; fd++) {
if (!fdsetup[fd].filename) continue;
if (fdsetup[fd].copyfd<0)
syscallerror("open file `%s' for fd %d",fdsetup[fd].filename,fd);
}
- fdsetup[fd].catpid= fork();
- if (fdsetup[fd].catpid==-1) syscallerror("fork for cat for fd %d",fd);
- if (!fdsetup[fd].catpid) {
+ blocksignals(SIG_BLOCK);
+ child= fork();
+ fdsetup[fd].catpid= child;
+ blocksignals(SIG_UNBLOCK);
+ if (child==-1) syscallerror("fork for cat for fd %d",fd);
+ if (!child) {
snprintf(catnamebuf,sizeof(catnamebuf),"cat fd%d",fd);
catnamebuf[sizeof(catnamebuf)-1]= 0;
sig.sa_handler= SIG_DFL;