Updated execute calls
This commit is contained in:
parent
fb1767f5a6
commit
e20f1d3f39
31
ChangeLog
31
ChangeLog
@ -18,6 +18,16 @@ v0.51.1 21-Feb-2004
|
||||
mbse did compile under OS X, but things are different since
|
||||
then. Work is underway to let it compile and run again.
|
||||
|
||||
libmbse.a:
|
||||
Changed the execute function so it will work on 2.6.x kernels
|
||||
and fast cpu's.
|
||||
Added execute_str function for compatibility with the older
|
||||
api. Added execute_pth function to execute programs in the
|
||||
path.
|
||||
|
||||
mbout:
|
||||
Replaced system() call with execute.
|
||||
|
||||
mbsetup:
|
||||
In edit message groups added setup for default character set.
|
||||
In edit message areas added setup for character set for the
|
||||
@ -30,6 +40,7 @@ v0.51.1 21-Feb-2004
|
||||
screen.
|
||||
Removed users fullscreen chat setting, not used.
|
||||
Added menu setup for change character set, menu 321.
|
||||
Replaced system() call with execute.
|
||||
|
||||
mbsebbs:
|
||||
Writes the ^aCHRS: kludge again in new created messages.
|
||||
@ -45,6 +56,13 @@ v0.51.1 21-Feb-2004
|
||||
Junius Fidogate package.
|
||||
In delete file in home directory the Y/N keys were read from
|
||||
the wrong language prompt.
|
||||
Replaced system() call with execute.
|
||||
|
||||
mbnewusr:
|
||||
Replaced system() call with execute.
|
||||
|
||||
mball:
|
||||
Replaced system() call with execute.
|
||||
|
||||
mbmsg:
|
||||
Writes the ^aCHRS: kludge again in new created messages.
|
||||
@ -60,17 +78,30 @@ v0.51.1 21-Feb-2004
|
||||
For the tic area create and message area create the check is
|
||||
now case insensitive, also the area tagnames are forced to
|
||||
uppercase. This should solve the problems with Linuxnet.
|
||||
Replaced system() call with execute.
|
||||
|
||||
mbdiff:
|
||||
Replaced system() call with execute.
|
||||
|
||||
mbfile:
|
||||
For creating www pages of the download areas, the new mapping
|
||||
tables are used to translate from ibmpc characters to
|
||||
iso-8859-1.
|
||||
Replaced system() call with execute.
|
||||
|
||||
examples:
|
||||
Added change character set in English menus and textfiles.
|
||||
Updated all newfiles macro template to include the magic file-
|
||||
request macro (English, German, Spanish and Dutch).
|
||||
|
||||
mbuseradd:
|
||||
Uses the execv instead of system to call the systems useradd
|
||||
program.
|
||||
|
||||
mbpasswd:
|
||||
Uses the execv instead of system to call the systems vpassswd
|
||||
program if needed.
|
||||
|
||||
lang:
|
||||
Added language prompts 23, 24 and 25.
|
||||
|
||||
|
2
TODO
2
TODO
@ -71,6 +71,8 @@ newuser:
|
||||
|
||||
N: Add menu setup to set users preffered character set.
|
||||
|
||||
U: Fix (kernel 2.6.x ??) problem with creating new users.
|
||||
|
||||
mbtask:
|
||||
N: Add a thread that keeps track of disk usage of all partitions used
|
||||
by mbse, update partition list after setup changes. Make the info
|
||||
|
@ -101,7 +101,7 @@ clean:
|
||||
filelist: Makefile
|
||||
BASE=`pwd`; \
|
||||
BASE=`basename $${BASE}`; \
|
||||
(for f in ${SRCS} ${HDRS} ${OTHER} ;do echo ${PACKAGE}-${VERSION}/$${BASE}/$$f; done) >filelist
|
||||
(for f in ${SRCS} ${HDRS} ${OTHER} ${MAPS} ;do echo ${PACKAGE}-${VERSION}/$${BASE}/$$f; done) >filelist
|
||||
|
||||
depend: ftscprod.c
|
||||
@rm -f Makefile.bak; \
|
||||
|
101
lib/execute.c
101
lib/execute.c
@ -36,24 +36,21 @@ int e_pid = 0; /* Execute child pid */
|
||||
|
||||
|
||||
|
||||
int _execute(char *, char *, char *, char *, char *, char *);
|
||||
int _execute(char *cmd, char *fil, char *pkt, char *in, char *out, char *err)
|
||||
int _execute(char **, char *, char *, char *);
|
||||
int _execute(char **args, char *in, char *out, char *err)
|
||||
{
|
||||
char buf[PATH_MAX];
|
||||
char *vector[16];
|
||||
int i, pid, status = 0, rc = 0;
|
||||
|
||||
if (pkt == NULL)
|
||||
sprintf(buf, "%s %s", cmd, fil);
|
||||
memset(&buf, 0, sizeof(buf));
|
||||
for (i = 0; i < 16; i++) {
|
||||
if (args[i])
|
||||
sprintf(buf, "%s %s", buf, args[i]);
|
||||
else
|
||||
sprintf(buf, "%s %s %s", cmd, fil, pkt);
|
||||
break;
|
||||
}
|
||||
Syslog('+', "Execute:%s",buf);
|
||||
|
||||
memset(vector, 0, sizeof(vector));
|
||||
i = 0;
|
||||
vector[i++] = strtok(buf," \t\n");
|
||||
while ((vector[i++] = strtok(NULL," \t\n")) && (i<16));
|
||||
vector[15] = NULL;
|
||||
fflush(stdout);
|
||||
fflush(stderr);
|
||||
|
||||
@ -86,8 +83,8 @@ int _execute(char *cmd, char *fil, char *pkt, char *in, char *out, char *err)
|
||||
if (rc)
|
||||
WriteError("$execv can't set priority to 15");
|
||||
}
|
||||
rc = execv(vector[0],vector);
|
||||
WriteError("$execv \"%s\" returned %d", MBSE_SS(vector[0]), rc);
|
||||
rc = execv(args[0],args);
|
||||
WriteError("$execv \"%s\" returned %d", MBSE_SS(args[0]), rc);
|
||||
setpriority(PRIO_PROCESS, 0, 0);
|
||||
exit(MBERR_EXEC_FAILED);
|
||||
}
|
||||
@ -104,7 +101,7 @@ int _execute(char *cmd, char *fil, char *pkt, char *in, char *out, char *err)
|
||||
switch (rc) {
|
||||
case -1:
|
||||
WriteError("$Wait returned %d, status %d,%d", rc,status>>8,status&0xff);
|
||||
return MBERR_EXEC_FAILED;
|
||||
return 0;
|
||||
case 0:
|
||||
return 0;
|
||||
default:
|
||||
@ -129,7 +126,7 @@ int _execute(char *cmd, char *fil, char *pkt, char *in, char *out, char *err)
|
||||
|
||||
|
||||
|
||||
int execute(char *cmd, char *fil, char *pkt, char *in, char *out, char *err)
|
||||
int execute(char **args, char *in, char *out, char *err)
|
||||
{
|
||||
int rc;
|
||||
|
||||
@ -137,7 +134,7 @@ int execute(char *cmd, char *fil, char *pkt, char *in, char *out, char *err)
|
||||
sync();
|
||||
#endif
|
||||
msleep(300);
|
||||
rc = _execute(cmd, fil, pkt, in, out, err);
|
||||
rc = _execute(args, in, out, err);
|
||||
#ifdef __linux__
|
||||
sync();
|
||||
#endif
|
||||
@ -146,6 +143,76 @@ int execute(char *cmd, char *fil, char *pkt, char *in, char *out, char *err)
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* The old behaviour, parse command strings to arguments.
|
||||
*/
|
||||
int execute_str(char *cmd, char *fil, char *pkt, char *in, char *out, char *err)
|
||||
{
|
||||
int i;
|
||||
char *args[16], buf[PATH_MAX];
|
||||
|
||||
memset(args, 0, sizeof(args));
|
||||
memset(&buf, 0, sizeof(buf));
|
||||
i = 0;
|
||||
|
||||
if ((pkt != NULL) && strlen(pkt))
|
||||
sprintf(buf, "%s %s %s", cmd, fil, pkt);
|
||||
else
|
||||
sprintf(buf, "%s %s", cmd, fil);
|
||||
|
||||
args[i++] = strtok(buf, " \t\0");
|
||||
while ((args[i++] = strtok(NULL," \t\n")) && (i < 15));
|
||||
args[i++] = NULL;
|
||||
|
||||
return execute(args, in, out, err);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Execute command in the PATH.
|
||||
*/
|
||||
int execute_pth(char *prog, char *opts, char *in, char *out, char *err)
|
||||
{
|
||||
char *pth;
|
||||
int rc;
|
||||
|
||||
if (strchr(prog, ' ') || strchr(prog, '/')) {
|
||||
WriteError("First parameter of execute_pth() must be a program name");
|
||||
return -1;
|
||||
}
|
||||
|
||||
pth = xstrcpy((char *)"/usr/bin/");
|
||||
pth = xstrcat(pth, prog);
|
||||
if (access(pth, X_OK) == -1) {
|
||||
free(pth);
|
||||
pth = xstrcpy((char *)"/usr/local/bin/");
|
||||
pth = xstrcat(pth, prog);
|
||||
if (access(pth, X_OK) == -1) {
|
||||
free(pth);
|
||||
pth = xstrcpy((char *)"/bin/");
|
||||
pth = xstrcat(pth, prog);
|
||||
if (access(pth, X_OK) == -1) {
|
||||
free(pth);
|
||||
pth = xstrcpy((char *)"/usr/pkg/bin/");
|
||||
pth = xstrcat(pth, prog);
|
||||
if (access(pth, X_OK) == -1) {
|
||||
WriteError("Can't find %s", prog);
|
||||
free(pth);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rc = execute_str(pth, opts, NULL, in, out, err);
|
||||
free(pth);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#define SHELL "/bin/sh"
|
||||
|
||||
|
||||
@ -199,7 +266,7 @@ int _execsh(char *cmd, char *in, char *out, char *err)
|
||||
while (((rc > 0) && (rc != pid)) || ((rc == -1) && (sverr == EINTR)));
|
||||
if (rc == -1) {
|
||||
WriteError("$Wait returned %d, status %d,%d", rc, status >> 8, status & 0xff);
|
||||
return MBERR_EXEC_FAILED;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return status;
|
||||
|
@ -2104,7 +2104,9 @@ char *Unix2Dos(char *);
|
||||
/*
|
||||
* From execute.c
|
||||
*/
|
||||
int execute(char *, char *, char *, char *, char *, char *);
|
||||
int execute(char **, char *, char *, char *);
|
||||
int execute_str(char *, char *, char *, char *, char *, char *);
|
||||
int execute_pth(char *, char *, char *, char *, char *);
|
||||
int execsh(char *, char *, char *, char *);
|
||||
|
||||
|
||||
|
@ -46,7 +46,7 @@ int do_req = FALSE; /* Request files from a node */
|
||||
int do_stat = FALSE; /* Show outbound status */
|
||||
int do_stop = FALSE; /* Stop polling a node */
|
||||
int do_reset = FALSE; /* Reset node's try counter */
|
||||
int e_pid = 0; /* Pid of child */
|
||||
extern pid_t e_pid; /* Pid of child */
|
||||
extern int show_log; /* Show logging */
|
||||
time_t t_start; /* Start time */
|
||||
time_t t_end; /* End time */
|
||||
@ -88,7 +88,7 @@ void die(int onsig)
|
||||
/*
|
||||
* In case the child had the tty in raw mode...
|
||||
*/
|
||||
system("stty sane");
|
||||
execute_pth((char *)"stty", (char *)"sane", (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null");
|
||||
}
|
||||
|
||||
signal(onsig, SIG_IGN);
|
||||
|
@ -233,7 +233,7 @@ void Magic_ExecCommand(void)
|
||||
opts = strtok(NULL, "\0");
|
||||
MagicResult((char *)"Exec: \"%s %s\"", cmd, opts);
|
||||
|
||||
if ((Err = execute(cmd, opts, NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null")) == 0) {
|
||||
if ((Err = execute_str(cmd, opts, NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null")) == 0) {
|
||||
Magics++;
|
||||
} else
|
||||
Syslog('!', "Mgc Exec: (%s %s) returns %d", cmd, opts, Err);
|
||||
@ -287,7 +287,7 @@ void Magic_UnpackFile(void)
|
||||
if (getarchiver(unarc)) {
|
||||
cmd = xstrcpy(archiver.munarc);
|
||||
if (strlen(cmd)) {
|
||||
rc = execute(cmd, Fn, (char *)NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null");
|
||||
rc = execute_str(cmd, Fn, (char *)NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null");
|
||||
if (rc)
|
||||
WriteError("$Magic: unpack in %s, error %d", magic.Path, rc);
|
||||
else
|
||||
|
@ -84,7 +84,7 @@ void die(int onsig)
|
||||
/*
|
||||
* In case the child had the tty in raw mode...
|
||||
*/
|
||||
system("stty sane");
|
||||
execute_pth((char *)"stty", (char *)"sane", (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null");
|
||||
}
|
||||
|
||||
signal(onsig, SIG_IGN);
|
||||
@ -287,11 +287,11 @@ int main(int argc, char **argv)
|
||||
die(MBERR_CONFIG_ERROR);
|
||||
}
|
||||
|
||||
if (execute(cmd, nd, (char *)NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null")) {
|
||||
if (execute_str(cmd, nd, (char *)NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null")) {
|
||||
WriteError("Warning: unpack error, trying again after a sync");
|
||||
sync();
|
||||
sleep(1);
|
||||
if (execute(cmd, nd, (char *)NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null")) {
|
||||
if (execute_str(cmd, nd, (char *)NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null")) {
|
||||
show_log = TRUE;
|
||||
free(cmd);
|
||||
free(onl);
|
||||
@ -406,7 +406,7 @@ int main(int argc, char **argv)
|
||||
p = xstrcpy(onl);
|
||||
p = xstrcat(p, (char *)" ");
|
||||
p = xstrcat(p, nn);
|
||||
if (execute(cmd, p, (char *)NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null"))
|
||||
if (execute_str(cmd, p, (char *)NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null"))
|
||||
WriteError("Create %s failed", onl);
|
||||
else {
|
||||
CreateSema((char *)"mailin");
|
||||
|
@ -176,7 +176,7 @@ void die(int onsig)
|
||||
/*
|
||||
* In case the child had the tty in raw mode, reset the tty.
|
||||
*/
|
||||
system("stty sane");
|
||||
execute_pth((char *)"stty", (char *)"sane", (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null");
|
||||
}
|
||||
|
||||
if (onsig != MBERR_NO_PROGLOCK)
|
||||
@ -750,7 +750,7 @@ int TossPkts(void)
|
||||
* See if "pktdate" from Tobias Ernst (or another preprocessor) is installed.
|
||||
*/
|
||||
if (strlen(CFG.pktdate)) {
|
||||
rc = execute(CFG.pktdate, fname, (char *)NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null");
|
||||
rc = execute_str(CFG.pktdate, fname, (char *)NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null");
|
||||
if (rc)
|
||||
Syslog('+', "%s preprocessing rc=%d", fname, rc);
|
||||
}
|
||||
|
@ -659,7 +659,7 @@ void HtmlIndex(char *Lang)
|
||||
sprintf(linebuf, "%s/%s", area.Path, file.Name);
|
||||
sprintf(outbuf, "%s/.%s", area.Path, file.Name);
|
||||
if (file_exist(outbuf, R_OK)) {
|
||||
if ((j = execute(CFG.www_convert, linebuf, outbuf,
|
||||
if ((j = execute_str(CFG.www_convert, linebuf, outbuf,
|
||||
(char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null"))) {
|
||||
Syslog('+', "Failed to create thumbnail for %s, rc=% d", file.Name, j);
|
||||
} else {
|
||||
|
@ -77,7 +77,7 @@ void die(int onsig)
|
||||
* In case the child had the tty in raw mode...
|
||||
*/
|
||||
if (!do_quiet)
|
||||
system("stty sane");
|
||||
execute_pth((char *)"stty", (char *)"sane", (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null");
|
||||
}
|
||||
|
||||
signal(onsig, SIG_IGN);
|
||||
@ -211,8 +211,8 @@ void DeleteVirusWork()
|
||||
|
||||
if (chdir(temp) == 0) {
|
||||
Syslog('f', "DeleteVirusWork %s/arc", temp);
|
||||
system("rm -r -f arc");
|
||||
system("mkdir arc");
|
||||
execute_pth((char *)"rm", (char *)"-r -f arc", (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null");
|
||||
execute_pth((char *)"mkdir", (char *)"arc", (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null");
|
||||
} else
|
||||
WriteError("$Can't chdir to %s", temp);
|
||||
|
||||
@ -282,7 +282,7 @@ int UnpackFile(char *File)
|
||||
die(MBERR_GENERAL);
|
||||
}
|
||||
|
||||
if (execute(cmd, File, (char *)NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null") == 0) {
|
||||
if (execute_str(cmd, File, (char *)NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null") == 0) {
|
||||
chdir(pwd);
|
||||
free(temp);
|
||||
free(pwd);
|
||||
|
@ -481,7 +481,7 @@ int ProcessTic(fa_list *sbl)
|
||||
Syslog('!', "No unarc command available");
|
||||
} else {
|
||||
sprintf(temp1, "%s/%s", TIC.Inbound, TIC.TicIn.File);
|
||||
if (execute(cmd, temp1, (char *)NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null") == 0) {
|
||||
if (execute_str(cmd, temp1, (char *)NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null") == 0) {
|
||||
UnPacked = TRUE;
|
||||
} else {
|
||||
chdir(TIC.Inbound);
|
||||
@ -566,11 +566,11 @@ int ProcessTic(fa_list *sbl)
|
||||
sprintf(temp1, "%s/tmp", getenv("MBSE_ROOT"));
|
||||
chdir(temp1);
|
||||
sprintf(temp1, "%s/%s FILE_ID.DIZ", TIC.Inbound, TIC.TicIn.File);
|
||||
if (execute(cmd, temp1, (char *)NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null") == 0) {
|
||||
if (execute_str(cmd, temp1, (char *)NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null") == 0) {
|
||||
File_Id = TRUE;
|
||||
} else {
|
||||
sprintf(temp1, "%s/%s file_id.diz", TIC.Inbound, TIC.TicIn.File);
|
||||
if (execute(cmd, temp1, (char *)NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null") == 0) {
|
||||
if (execute_str(cmd, temp1, (char *)NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null") == 0) {
|
||||
File_Id = TRUE;
|
||||
}
|
||||
}
|
||||
@ -658,7 +658,7 @@ int ProcessTic(fa_list *sbl)
|
||||
} else {
|
||||
sprintf(temp1, "%s/%s", TIC.Inbound, TIC.NewFile);
|
||||
sprintf(Temp, "%s/etc/%s", getenv("MBSE_ROOT"), tic.Banner);
|
||||
if (execute(cmd, temp1, (char *)NULL, Temp, (char *)"/dev/null", (char *)"/dev/null")) {
|
||||
if (execute_str(cmd, temp1, (char *)NULL, Temp, (char *)"/dev/null", (char *)"/dev/null")) {
|
||||
WriteError("$Changing the banner failed");
|
||||
} else {
|
||||
Syslog('+', "New banner %s", tic.Banner);
|
||||
|
@ -384,13 +384,13 @@ void flush_dir(char *ndir)
|
||||
flushed = TRUE;
|
||||
}
|
||||
|
||||
if (execute(archiver.marc, arcfile, fname, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null") == 0) {
|
||||
if (execute_str(archiver.marc, arcfile, fname, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null") == 0) {
|
||||
unlink(fname);
|
||||
} else {
|
||||
WriteError("Create ARCmail failed, trying again after sync()");
|
||||
sync();
|
||||
sleep(1);
|
||||
if (execute(archiver.marc, arcfile, fname, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null") == 0) {
|
||||
if (execute_str(archiver.marc, arcfile, fname, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null") == 0) {
|
||||
unlink(fname);
|
||||
} else {
|
||||
WriteError("Can't add %s to ARCmail archive", fname);
|
||||
|
@ -90,18 +90,15 @@ int unpack(char *fn)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ((rc = execute(cmd,fn,(char *)NULL,(char*)"/dev/null",(char*)"/dev/null",(char*)"/dev/null")) == 0) {
|
||||
// sync();
|
||||
if ((rc = execute_str(cmd,fn,(char *)NULL,(char*)"/dev/null",(char*)"/dev/null",(char*)"/dev/null")) == 0) {
|
||||
unlink(fn);
|
||||
} else {
|
||||
sync();
|
||||
sleep(1);
|
||||
WriteError("Warning: unpack %s failed, trying again after sync()", fn);
|
||||
if ((rc = execute(cmd,fn,(char *)NULL,(char*)"/dev/null",(char*)"/dev/null",(char*)"/dev/null")) == 0) {
|
||||
// sync();
|
||||
if ((rc = execute_str(cmd,fn,(char *)NULL,(char*)"/dev/null",(char*)"/dev/null",(char*)"/dev/null")) == 0) {
|
||||
unlink(fn);
|
||||
} else {
|
||||
// sync();
|
||||
strncpy(newname,fn,sizeof(newname)-1);
|
||||
strcpy(newname+8,".bad");
|
||||
rename(fn,newname);
|
||||
|
@ -113,7 +113,7 @@ int Rearc(char *unarc)
|
||||
Syslog('f' , "NewFile=\"%s\", NewFullName=\"%s\"", TIC.NewFile, TIC.NewFullName);
|
||||
|
||||
sprintf(temp, "%s/%s .", TIC.Inbound, TIC.NewFile);
|
||||
if (execute(cmd, temp, (char *)NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null") == 0) {
|
||||
if (execute_str(cmd, temp, (char *)NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null") == 0) {
|
||||
free(cmd);
|
||||
return TRUE;
|
||||
}
|
||||
@ -142,8 +142,8 @@ void DeleteVirusWork()
|
||||
|
||||
if (chdir(temp) == 0) {
|
||||
Syslog('f', "DeleteVirusWork %s/arc", temp);
|
||||
system("rm -r -f arc");
|
||||
system("mkdir arc");
|
||||
execute_pth((char *)"rm", (char *)"-r -f arc", (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null");
|
||||
execute_pth((char *)"mkdir", (char *)"arc", (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null");
|
||||
} else
|
||||
WriteError("$Can't chdir to %s", temp);
|
||||
|
||||
|
@ -80,7 +80,7 @@ int VirScan(char *path)
|
||||
cmd = xstrcpy(virscan.scanner);
|
||||
cmd = xstrcat(cmd, (char *)" ");
|
||||
cmd = xstrcat(cmd, virscan.options);
|
||||
if (execute(cmd, (char *)"*", (char *)NULL, (char *)"/dev/null",
|
||||
if (execute_str(cmd, (char *)"*", (char *)NULL, (char *)"/dev/null",
|
||||
(char *)"/dev/null" , (char *)"/dev/null") != virscan.error) {
|
||||
Syslog('!', "Virus found by %s", virscan.comment);
|
||||
rc = TRUE;
|
||||
|
@ -142,7 +142,7 @@ int Chg_Language(int NewMode)
|
||||
|
||||
void Chg_Password()
|
||||
{
|
||||
char *temp1, *temp2;
|
||||
char *temp1, *temp2, *args[16];
|
||||
|
||||
temp1 = calloc(PATH_MAX, sizeof(char));
|
||||
temp2 = calloc(PATH_MAX, sizeof(char));
|
||||
@ -190,8 +190,15 @@ void Chg_Password()
|
||||
}
|
||||
|
||||
Syslog('+', "%s/bin/mbpasswd -n %s ******", getenv("MBSE_ROOT"), exitinfo.Name);
|
||||
sprintf(temp1, "%s/bin/mbpasswd -n %s %s", getenv("MBSE_ROOT"), exitinfo.Name, temp2);
|
||||
if (system(temp1) != 0) {
|
||||
sprintf(temp1, "%s/bin/mbpasswd", getenv("MBSE_ROOT"));
|
||||
memset(args, 0, sizeof(args));
|
||||
args[0] = temp1;
|
||||
args[1] = (char *)"-n";
|
||||
args[2] = exitinfo.Name;
|
||||
args[3] = temp2;
|
||||
args[4] = NULL;
|
||||
|
||||
if (execute(args, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null") != 0) {
|
||||
WriteError("Failed to set new Unix password");
|
||||
} else {
|
||||
memset(&exitinfo.Password, 0, sizeof(exitinfo.Password));
|
||||
|
@ -291,7 +291,7 @@ void ExtDoor(char *Program, int NoDoorsys, int Y2Kdoorsys, int Comport, int NoSu
|
||||
if (NoSuid)
|
||||
rc = exec_nosuid(Program);
|
||||
else
|
||||
rc = execute((char *)"/bin/sh", (char *)"-c", Program, NULL, NULL, NULL);
|
||||
rc = execute_str((char *)"/bin/sh", (char *)"-c", Program, NULL, NULL, NULL);
|
||||
|
||||
Altime(0);
|
||||
alarm_off();
|
||||
|
@ -181,7 +181,7 @@ void Download(void)
|
||||
Enter(2);
|
||||
OldArea = iAreaNumber;
|
||||
WhosDoingWhat(DOWNLOAD, NULL);
|
||||
system("rm -f ./tag/*");
|
||||
execute_pth((char *)"rm", (char *)"-f ./tag/*", (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null");
|
||||
|
||||
if ((tf = fopen("taglist", "r+")) == NULL) {
|
||||
Syslog('+', "Download command but no files marked");
|
||||
@ -382,7 +382,7 @@ void Download(void)
|
||||
}
|
||||
}
|
||||
if (temp != NULL) {
|
||||
if ((err = execute(sProtDn, temp, NULL, NULL, NULL, NULL))) {
|
||||
if ((err = execute_str(sProtDn, temp, NULL, NULL, NULL, NULL))) {
|
||||
perror("");
|
||||
colour(CFG.HiliteF, CFG.HiliteB);
|
||||
WriteError("Download error %d, prot: %s", err, sProtDn);
|
||||
@ -1140,7 +1140,7 @@ int Upload()
|
||||
*/
|
||||
Altime(7200);
|
||||
alarm_set(7190);
|
||||
if ((err = execute(sProtUp, (char *)"", NULL, NULL, NULL, NULL))) {
|
||||
if ((err = execute_str(sProtUp, (char *)"", NULL, NULL, NULL, NULL))) {
|
||||
/*
|
||||
* Log any errors
|
||||
*/
|
||||
@ -1309,7 +1309,7 @@ int DownloadDirect(char *Name, int Wait)
|
||||
*/
|
||||
alarm_set(((exitinfo.iTimeLeft + 10) * 60) - 10);
|
||||
Altime((exitinfo.iTimeLeft + 10) * 60);
|
||||
if ((err = execute(sProtDn, symFrom, NULL, NULL, NULL, NULL))) {
|
||||
if ((err = execute_str(sProtDn, symFrom, NULL, NULL, NULL, NULL))) {
|
||||
/*
|
||||
* Only log the error, we might have sent some files
|
||||
* instead of nothing.
|
||||
@ -1671,7 +1671,7 @@ int Upload_Home()
|
||||
*/
|
||||
Altime(7200);
|
||||
alarm_set(7190);
|
||||
if ((err = execute(sProtUp, (char *)"", NULL, NULL, NULL, NULL))) {
|
||||
if ((err = execute_str(sProtUp, (char *)"", NULL, NULL, NULL, NULL))) {
|
||||
/*
|
||||
* Log any errors
|
||||
*/
|
||||
@ -2342,7 +2342,7 @@ void ViewFile(char *name)
|
||||
* display to the user.
|
||||
*/
|
||||
sprintf(temp, "%s/%s/temptxt", CFG.bbs_usersdir, exitinfo.Name);
|
||||
rc = execute(archiver.varc, File, NULL, (char *)"/dev/null", temp, (char *)"/dev/null");
|
||||
rc = execute_str(archiver.varc, File, NULL, (char *)"/dev/null", temp, (char *)"/dev/null");
|
||||
Syslog('+', "Display temp file %s", temp);
|
||||
DisplayTextFile(temp);
|
||||
unlink(temp);
|
||||
|
@ -532,7 +532,7 @@ int ScanDirect(char *fn)
|
||||
fflush(stdout);
|
||||
|
||||
Altime(3600);
|
||||
if ((err = execute(virscan.scanner, virscan.options, temp, (char *)"/dev/null",
|
||||
if ((err = execute_str(virscan.scanner, virscan.options, temp, (char *)"/dev/null",
|
||||
(char *)"/dev/null" , (char *)"/dev/null")) != virscan.error) {
|
||||
WriteError("VIRUS ALERT: Result %d (%s)", err, virscan.comment);
|
||||
colour(CFG.HiliteF, CFG.HiliteB);
|
||||
@ -613,9 +613,9 @@ int ScanArchive(char *fn, char *ftype)
|
||||
WriteError("No unarc command available");
|
||||
} else {
|
||||
sprintf(temp, "%s/%s/upl/%s", CFG.bbs_usersdir, exitinfo.Name, fn);
|
||||
if (execute(archiver.funarc, temp, (char *)NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null")) {
|
||||
if (execute_str(archiver.funarc, temp, (char *)NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null")) {
|
||||
WriteError("$Failed %s %s", archiver.funarc, temp);
|
||||
system("rm -f -r ./*");
|
||||
execute_pth((char *)"rm", (char *)"-r -f ./*", (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null");
|
||||
chdir(cwd);
|
||||
free(cwd);
|
||||
colour(CFG.HiliteF, CFG.HiliteB);
|
||||
@ -643,7 +643,7 @@ int ScanArchive(char *fn, char *ftype)
|
||||
fflush(stdout);
|
||||
|
||||
Altime(3600);
|
||||
err = execute(virscan.scanner, virscan.options, (char *)"*", (char *)"/dev/null",
|
||||
err = execute_str(virscan.scanner, virscan.options, (char *)"*", (char *)"/dev/null",
|
||||
(char *)"/dev/null", (char *)"/dev/null");
|
||||
if (err != virscan.error) {
|
||||
WriteError("VIRUS ALERT: Result %d (%s)", err, virscan.comment);
|
||||
@ -663,7 +663,7 @@ int ScanArchive(char *fn, char *ftype)
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
system("rm -f -r ./*");
|
||||
execute_pth((char *)"rm", (char *)"-r -f ./*", (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null");
|
||||
chdir(cwd);
|
||||
free(cwd);
|
||||
free(temp);
|
||||
@ -892,9 +892,9 @@ int Addfile(char *File, int AreaNum, int fileid)
|
||||
* get the FILE_ID.DIZ if it exists.
|
||||
*/
|
||||
sprintf(temp, "%s/%s", area.Path, File);
|
||||
if ((err = execute(archiver.iunarc, temp, (char *)"FILE_ID.DIZ", (char *)"/dev/null",
|
||||
if ((err = execute_str(archiver.iunarc, temp, (char *)"FILE_ID.DIZ", (char *)"/dev/null",
|
||||
(char *)"/dev/null", (char *)"/dev/null"))) {
|
||||
if ((err = execute(archiver.iunarc, temp, (char *)"file_id.diz", (char *)"/dev/null",
|
||||
if ((err = execute_str(archiver.iunarc, temp, (char *)"file_id.diz", (char *)"/dev/null",
|
||||
(char *)"/dev/null", (char *)"/dev/null"))) {
|
||||
Syslog('+', "No FILE_ID.DIZ found in %s", File);
|
||||
} else {
|
||||
|
@ -77,7 +77,7 @@ void die(int onsig)
|
||||
/*
|
||||
* In case the child had the tty in raw mode...
|
||||
*/
|
||||
system("stty sane");
|
||||
execute_pth((char *)"stty", (char *)"sane", (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null");
|
||||
}
|
||||
|
||||
signal(onsig, SIG_IGN);
|
||||
@ -491,14 +491,14 @@ void MakeArc()
|
||||
Nopper();
|
||||
if (!do_quiet)
|
||||
printf("Creating allfiles.zip\n");
|
||||
if (!execute(cmd, (char *)"allfiles.zip allfiles.txt", (char *)NULL, (char *)"/dev/null",
|
||||
if (!execute_str(cmd, (char *)"allfiles.zip allfiles.txt", (char *)NULL, (char *)"/dev/null",
|
||||
(char *)"/dev/null", (char *)"/dev/null") == 0)
|
||||
WriteError("Create allfiles.zip failed");
|
||||
|
||||
Nopper();
|
||||
if (!do_quiet)
|
||||
printf("Creating newfiles.zip\n");
|
||||
if (!execute(cmd, (char *)"newfiles.zip newfiles.txt", (char *)NULL, (char *)"/dev/null",
|
||||
if (!execute_str(cmd, (char *)"newfiles.zip newfiles.txt", (char *)NULL, (char *)"/dev/null",
|
||||
(char *)"/dev/null", (char *)"/dev/null") == 0)
|
||||
WriteError("Create newfiles.zip failed");
|
||||
free(cmd);
|
||||
|
@ -178,9 +178,7 @@ void UserPack(int days, int level, int pack)
|
||||
long oldsize, curpos;
|
||||
int updated, delete = 0, rc, highest = 0, record = 0, sysop = FALSE;
|
||||
time_t Last;
|
||||
#ifdef _VPOPMAIL_PATH
|
||||
char *cmd;
|
||||
#endif
|
||||
|
||||
fnin = calloc(PATH_MAX, sizeof(char));
|
||||
fnout = calloc(PATH_MAX, sizeof(char));
|
||||
@ -323,22 +321,26 @@ void UserPack(int days, int level, int pack)
|
||||
WriteError("Cannot delete unix account %s", usr.Name);
|
||||
} else {
|
||||
#ifndef __FreeBSD__
|
||||
rc = execute((char *)"/usr/sbin/userdel ", usr.Name, NULL,
|
||||
rc = execute_str((char *)"/usr/sbin/userdel ", usr.Name, NULL,
|
||||
(char *)"/dev/null",(char *)"/dev/null",(char *)"/dev/null");
|
||||
#else
|
||||
rc = execute((char *)"/usr/sbin/pw userdel ", usr.Name, NULL,
|
||||
rc = execute_str((char *)"/usr/sbin/pw userdel ", usr.Name, NULL,
|
||||
(char *)"/dev/null",(char *)"/dev/null",(char *)"/dev/null");
|
||||
#endif
|
||||
#ifdef _VPOPMAIL_PATH
|
||||
cmd = xstrcpy((char *)_VPOPMAIL_PATH);
|
||||
cmd = xstrcat(cmd, (char *)"/vdeluser ");
|
||||
rc = execute(cmd, usr.Name, NULL,
|
||||
rc = execute_str(cmd, usr.Name, NULL,
|
||||
(char *)"/dev/null",(char *)"/dev/null",(char *)"/dev/null");
|
||||
free(cmd);
|
||||
#endif
|
||||
if (chdir(CFG.bbs_usersdir) == 0)
|
||||
rc = execute((char *)"/bin/rm -Rf ", usr.Name, NULL,
|
||||
if (chdir(CFG.bbs_usersdir) == 0) {
|
||||
cmd = xstrcpy((char *)"-Rf ");
|
||||
cmd = xstrcat(cmd, usr.Name);
|
||||
rc = execute_pth((char *)"rm", cmd,
|
||||
(char *)"/dev/null",(char *)"/dev/null",(char *)"/dev/null");
|
||||
free(cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -598,7 +598,7 @@ void Good_Bye(int onsig)
|
||||
*/
|
||||
char *NameGen(char *FidoName)
|
||||
{
|
||||
char *sUserName;
|
||||
static char *sUserName;
|
||||
|
||||
sUserName = calloc(10, sizeof(char));
|
||||
Syslog('+', "NameGen(%s)", FidoName);
|
||||
@ -635,34 +635,47 @@ char *NameGen(char *FidoName)
|
||||
*/
|
||||
char *NameCreate(char *Name, char *Comment, char *Password)
|
||||
{
|
||||
char *progname;
|
||||
char *progname, *args[16], *gidstr;
|
||||
int err;
|
||||
|
||||
progname = calloc(PATH_MAX, sizeof(char));
|
||||
gidstr = calloc(10, sizeof(char));
|
||||
memset(args, 0, sizeof(args));
|
||||
|
||||
/*
|
||||
* Call mbuseradd, this is a special setuid root program to create
|
||||
* unix acounts and home directories.
|
||||
*/
|
||||
sprintf(progname, "%s/bin/mbuseradd %d %s \"%s\" %s", getenv("MBSE_ROOT"), getgid(), Name, Comment, CFG.bbs_usersdir);
|
||||
Syslog('+', "%s", progname);
|
||||
sprintf(progname, "%s/bin/mbuseradd", getenv("MBSE_ROOT"));
|
||||
sprintf(gidstr, "%d", getgid());
|
||||
fflush(stdout);
|
||||
fflush(stdin);
|
||||
args[0] = progname;
|
||||
args[1] = gidstr;
|
||||
args[2] = Name;
|
||||
args[3] = Comment;
|
||||
args[4] = CFG.bbs_usersdir;
|
||||
args[5] = NULL;
|
||||
|
||||
if ((err = system(progname))) {
|
||||
perror("");
|
||||
if ((err = execute(args, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null"))) {
|
||||
WriteError("Failed to create unix account");
|
||||
free(progname);
|
||||
free(gidstr);
|
||||
ExitClient(MBERR_GENERAL);
|
||||
}
|
||||
free(gidstr);
|
||||
|
||||
sprintf(progname, "%s/bin/mbpasswd -f %s %s", getenv("MBSE_ROOT"), Name, Password);
|
||||
Syslog('+', "%s/bin/mbpasswd -f %s ******", getenv("MBSE_ROOT"), Name);
|
||||
sprintf(progname, "%s/bin/mbpasswd", getenv("MBSE_ROOT"));
|
||||
memset(args, 0, sizeof(args));
|
||||
args[0] = progname;
|
||||
args[1] = (char *)"-f";
|
||||
args[2] = Name;
|
||||
args[3] = Password;
|
||||
args[4] = NULL;
|
||||
fflush(stdout);
|
||||
fflush(stdin);
|
||||
|
||||
if ((err = system(progname))) {
|
||||
perror("");
|
||||
if ((err = execute(args, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null"))) {
|
||||
WriteError("Failed to set unix password");
|
||||
free(progname);
|
||||
ExitClient(MBERR_GENERAL);
|
||||
|
@ -97,7 +97,7 @@ unsigned long ASCII_PackArea(unsigned long, long);
|
||||
|
||||
void AddArc(char *Temp, char *Pktname)
|
||||
{
|
||||
execute((char *)archiver.marc, Pktname, Temp, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null");
|
||||
execute_str((char *)archiver.marc, Pktname, Temp, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null");
|
||||
unlink(Temp);
|
||||
printf(".");
|
||||
fflush(stdout);
|
||||
@ -1097,7 +1097,7 @@ void OLR_Upload(void)
|
||||
*/
|
||||
Altime(7200);
|
||||
alarm_set(7190);
|
||||
if ((err = execute(sProtUp, (char *)"", NULL, NULL, NULL, NULL))) {
|
||||
if ((err = execute_str(sProtUp, (char *)"", NULL, NULL, NULL, NULL))) {
|
||||
colour(CFG.HiliteF, CFG.HiliteB);
|
||||
WriteError("$Upload error %d, prot: %s", err, sProtUp);
|
||||
}
|
||||
@ -1184,7 +1184,7 @@ void OLR_Upload(void)
|
||||
Syslog('m', "Unarc %s", temp);
|
||||
colour(CFG.HiliteF, CFG.HiliteB);
|
||||
|
||||
if ((err = execute(archiver.funarc, File, NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null"))) {
|
||||
if ((err = execute_str(archiver.funarc, File, NULL, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null"))) {
|
||||
WriteError("$Failed %s", temp);
|
||||
/* ERROR */
|
||||
printf("%s\n", (char *) Language(217));
|
||||
|
@ -62,7 +62,7 @@ void die(int onsig)
|
||||
/*
|
||||
* In case the child had the tty in raw mode, reset the tty
|
||||
*/
|
||||
system("stty sane");
|
||||
execute_pth((char *)"stty", (char *)"sane", (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null");
|
||||
}
|
||||
|
||||
if (MsgBase.Locked)
|
||||
|
@ -394,8 +394,8 @@ int EditFileRec(int Area)
|
||||
* Erase file in path if path is set and not the default
|
||||
* FTP base path
|
||||
*/
|
||||
sprintf(temp, "rm -f %s", area.Path);
|
||||
system(temp);
|
||||
sprintf(temp, "-f %s", area.Path);
|
||||
execute_pth((char *)"rm", temp, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null");
|
||||
rmdir(area.Path);
|
||||
}
|
||||
memset(&area, 0, sizeof(area));
|
||||
|
@ -352,7 +352,7 @@ void Fields2(void)
|
||||
int EditUsrRec2(void)
|
||||
{
|
||||
int j = 0, ch;
|
||||
char temp[PATH_MAX];
|
||||
char temp[PATH_MAX], *args[16];
|
||||
|
||||
Screen2();
|
||||
for (;;) {
|
||||
@ -379,8 +379,15 @@ int EditUsrRec2(void)
|
||||
strcpy(usrconfig.Password, temp);
|
||||
usrconfig.tLastPwdChange = time(NULL);
|
||||
Syslog('+', "%s/bin/mbpasswd -f %s ******", getenv("MBSE_ROOT"), usrconfig.Name);
|
||||
sprintf(temp, "%s/bin/mbpasswd -f %s %s", getenv("MBSE_ROOT"), usrconfig.Name, usrconfig.Password);
|
||||
if (system(temp) != 0) {
|
||||
sprintf(temp, "%s/bin/mbpasswd", getenv("MBSE_ROOT"));
|
||||
memset(args, 0, sizeof(args));
|
||||
args[0] = temp;
|
||||
args[1] = (char *)"-f";
|
||||
args[2] = usrconfig.Name;
|
||||
args[3] = usrconfig.Password;
|
||||
args[4] = NULL;
|
||||
|
||||
if (execute(args, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null")!= 0) {
|
||||
WriteError("$Failed to set new Unix password");
|
||||
} else {
|
||||
Syslog('+', "Password changed for %s (%s)", usrconfig.sUserName, usrconfig.Name);
|
||||
|
@ -47,6 +47,9 @@
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <errno.h>
|
||||
#if defined(SHADOW_PASSWORD)
|
||||
#include <shadow.h>
|
||||
#endif
|
||||
@ -119,6 +122,59 @@ static int force; /* Force update of locked passwords */
|
||||
|
||||
|
||||
|
||||
#ifdef _VPOPMAIL_PATH
|
||||
int execute(char **args, char *in, char *out, char *err)
|
||||
{
|
||||
char buf[PATH_MAX];
|
||||
int i, pid, status = 0, rc = 0;
|
||||
|
||||
for (i = 0; i < 16; i++) {
|
||||
if (args[i])
|
||||
sprintf(buf, "%s %s", buf, args[i]);
|
||||
else
|
||||
break;
|
||||
}
|
||||
syslog(LOG_WARNING, "Execute:%s", buf);
|
||||
fflush(stdout);
|
||||
fflush(stderr);
|
||||
|
||||
if ((pid = fork()) == 0) {
|
||||
if (in) {
|
||||
close(0);
|
||||
if (open(in, O_RDONLY) != 0) {
|
||||
syslog(LOG_WARNING, "Reopen of stdin to %s failed", in);
|
||||
_exit(-1);
|
||||
}
|
||||
}
|
||||
if (out) {
|
||||
close(1);
|
||||
if (open(out, O_WRONLY | O_APPEND | O_CREAT,0600) != 1) {
|
||||
syslog(LOG_WARNING, "Reopen of stdout to %s failed", out);
|
||||
_exit(-1);
|
||||
}
|
||||
}
|
||||
if (err) {
|
||||
close(2);
|
||||
if (open(err, O_WRONLY | O_APPEND | O_CREAT,0600) != 2) {
|
||||
syslog(LOG_WARNING, "Reopen of stderr to %s failed", err);
|
||||
_exit(-1);
|
||||
}
|
||||
}
|
||||
rc = execv(args[0],args);
|
||||
syslog(LOG_WARNING, "Exec \"%s\" returned %d", args[0], rc);
|
||||
_exit(-1);
|
||||
}
|
||||
|
||||
do {
|
||||
rc = wait(&status);
|
||||
} while (((rc > 0) && (rc != pid)) || ((rc == -1) && (errno == EINTR)));
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if !defined(__FreeBSD__) && !defined(__NetBSD__)
|
||||
static void fail_exit(int status)
|
||||
{
|
||||
@ -735,6 +791,7 @@ int main(int argc, char *argv[])
|
||||
char *cp;
|
||||
#ifdef _VPOPMAIL_PATH
|
||||
char temp[PATH_MAX];
|
||||
char *args[16];
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -926,11 +983,17 @@ int main(int argc, char *argv[])
|
||||
#endif /* __FreeBSD__ */
|
||||
|
||||
#ifdef _VPOPMAIL_PATH
|
||||
sprintf(temp, "%s/vpasswd %s %s", _VPOPMAIL_PATH, argv[2], argv[3]);
|
||||
fflush(stdout);
|
||||
fflush(stdin);
|
||||
memset(args, 0, sizeof(args));
|
||||
|
||||
if (system(temp) != 0) {
|
||||
sprintf(temp, "%s/vpasswd", _VPOPMAIL_PATH);
|
||||
args[0] = temp;
|
||||
args[1] = argv[2];
|
||||
args[2] = argv[3];
|
||||
args[3] = NULL;
|
||||
|
||||
if (execute(args, (char *)"/dev/tty", (char *)"/dev/tty", (char *)"/dev/tty") != 0) {
|
||||
perror("mbpasswd: Failed to change vpopmail password\n");
|
||||
syslog(LOG_ERR, "Failed to change vpopmail password");
|
||||
}
|
||||
|
101
unix/mbuseradd.c
101
unix/mbuseradd.c
@ -48,19 +48,19 @@
|
||||
|
||||
|
||||
|
||||
int execute(char *cmd, char *file, char *in, char *out, char *err)
|
||||
int execute(char **args, char *in, char *out, char *err)
|
||||
{
|
||||
char buf[PATH_MAX], *vector[16];
|
||||
char buf[PATH_MAX];
|
||||
int i, pid, status = 0, rc = 0;
|
||||
|
||||
sprintf(buf, "%s %s", cmd, file);
|
||||
for (i = 0; i < 16; i++) {
|
||||
if (args[i])
|
||||
sprintf(buf, "%s %s", buf, args[i]);
|
||||
else
|
||||
break;
|
||||
}
|
||||
syslog(LOG_WARNING, "Execute:%s", buf);
|
||||
|
||||
memset(vector, 0, sizeof(vector));
|
||||
i = 0;
|
||||
vector[i++] = strtok(buf, " \t\n");
|
||||
while ((vector[i++] = strtok(NULL," \t\n")) && (i < 16)) { syslog(LOG_NOTICE, "%s", vector[i]); } ;
|
||||
vector[15] = NULL;
|
||||
fflush(stdout);
|
||||
fflush(stderr);
|
||||
|
||||
@ -86,8 +86,8 @@ int execute(char *cmd, char *file, char *in, char *out, char *err)
|
||||
_exit(-1);
|
||||
}
|
||||
}
|
||||
rc = execv(vector[0],vector);
|
||||
syslog(LOG_WARNING, "Exec \"%s\" returned %d", vector[0], rc);
|
||||
rc = execv(args[0],args);
|
||||
syslog(LOG_WARNING, "Exec \"%s\" returned %d", args[0], rc);
|
||||
_exit(-1);
|
||||
}
|
||||
|
||||
@ -95,11 +95,6 @@ int execute(char *cmd, char *file, char *in, char *out, char *err)
|
||||
rc = wait(&status);
|
||||
} while (((rc > 0) && (rc != pid)) || ((rc == -1) && (errno == EINTR)));
|
||||
|
||||
if (rc == -1) {
|
||||
syslog(LOG_WARNING, "Wait returned %d, status %d,%d", rc, status >> 8, status & 0xff);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -125,7 +120,7 @@ void makedir(char *path, mode_t mode, uid_t owner, gid_t group)
|
||||
*/
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char *PassEnt, *temp, *shell;
|
||||
char *temp, *shell, *homedir, *args[16];
|
||||
int i;
|
||||
struct passwd *pwent, *pwuser;
|
||||
|
||||
@ -142,9 +137,12 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
PassEnt = calloc(PATH_MAX, sizeof(char));
|
||||
memset(args, 0, sizeof(args));
|
||||
|
||||
temp = calloc(PATH_MAX, sizeof(char));
|
||||
shell = calloc(PATH_MAX, sizeof(char));
|
||||
homedir = calloc(PATH_MAX, sizeof(char));
|
||||
|
||||
|
||||
if (setuid(0) == -1 || setgid(1) == -1) {
|
||||
perror("");
|
||||
@ -168,22 +166,22 @@ int main(int argc, char *argv[])
|
||||
*/
|
||||
#if defined(__linux__) || defined(__NetBSD__)
|
||||
if ((access("/usr/bin/useradd", R_OK)) == 0)
|
||||
strcpy(temp, "/usr/bin/useradd");
|
||||
args[0] = (char *)"/usr/bin/useradd";
|
||||
else if ((access("/bin/useradd", R_OK)) == 0)
|
||||
strcpy(temp, "/bin/useradd");
|
||||
args[0] = (char *)"/bin/useradd";
|
||||
else if ((access("/usr/sbin/useradd", R_OK)) == 0)
|
||||
strcpy(temp, "/usr/sbin/useradd");
|
||||
args[0] = (char *)"/usr/sbin/useradd";
|
||||
else if ((access("/sbin/useradd", R_OK)) == 0)
|
||||
strcpy(temp, "/sbin/useradd");
|
||||
args[0] = (char *)"/sbin/useradd";
|
||||
else {
|
||||
syslog(LOG_WARNING, "Can't find useradd");
|
||||
exit(1);
|
||||
}
|
||||
#elif __FreeBSD__
|
||||
if ((access("/usr/sbin/pw", X_OK)) == 0)
|
||||
strcpy(temp, "/usr/sbin/pw");
|
||||
args[0] = (char *)"/usr/sbin/pw";
|
||||
else if ((access("/sbin/pw", X_OK)) == 0)
|
||||
strcpy(temp, "/sbin/pw");
|
||||
args[0] = (char *)"/sbin/pw";
|
||||
else {
|
||||
syslog(LOG_WARNING, "Can't find pw");
|
||||
exit(1);
|
||||
@ -194,19 +192,39 @@ int main(int argc, char *argv[])
|
||||
#endif
|
||||
|
||||
sprintf(shell, "%s/bin/mbsebbs", getenv("MBSE_ROOT"));
|
||||
sprintf(homedir, "%s/%s", argv[4], argv[2]);
|
||||
|
||||
#if defined(__linux__) || defined(__NetBSD__)
|
||||
sprintf(PassEnt, "%s -c \"%s\" -d %s/%s -g %s -s %s %s", temp, argv[3], argv[4], argv[2], argv[1], shell, argv[2]);
|
||||
args[1] = (char *)"-c";
|
||||
args[2] = argv[3];
|
||||
args[3] = (char *)"-d";
|
||||
args[4] = homedir;
|
||||
args[5] = (char *)"-g";
|
||||
args[6] = argv[1];
|
||||
args[7] = (char *)"-s";
|
||||
args[8] = shell;
|
||||
args[9] = argv[2];
|
||||
args[10] = NULL;
|
||||
#endif
|
||||
#ifdef __FreeBSD__
|
||||
sprintf(PassEnt, "%s useradd %s -c \"%s\" -d %s/%s -g %s -s %s", temp, argv[2], argv[3], argv[4], argv[2], argv[1], shell);
|
||||
args[1] = (char *)"useradd";
|
||||
args[2] = argv[2];
|
||||
args[3] = (char *)"-c";
|
||||
args[4] = argv[3];
|
||||
args[5] = (char *)"-d";
|
||||
args[6] = homedir;
|
||||
args[7] = (char *)"-g";
|
||||
args[8] = argv[1];
|
||||
args[9] = (char *)"-s";
|
||||
args[10] = shell;
|
||||
args[11] = NULL;
|
||||
#endif
|
||||
|
||||
syslog(LOG_WARNING, "system(%s)", PassEnt);
|
||||
if (system(PassEnt) != 0) {
|
||||
if (execute(args, (char *)"/dev/tty", (char *)"/dev/tty", (char *)"/dev/tty") != 0) {
|
||||
syslog(LOG_WARNING, "Failed to create unix account");
|
||||
exit(1);
|
||||
}
|
||||
syslog(LOG_WARNING, "Created Unix account");
|
||||
|
||||
/*
|
||||
* Now create directories and files for this user.
|
||||
@ -220,26 +238,29 @@ int main(int argc, char *argv[])
|
||||
*
|
||||
* Check bbs users base home directory
|
||||
*/
|
||||
if ((access(argv[4], R_OK)) != 0)
|
||||
if ((access(argv[4], R_OK)) != 0) {
|
||||
syslog(LOG_WARNING, "No bbs base homedirectory, creating..");
|
||||
makedir(argv[4], 0770, pwent->pw_uid, pwent->pw_gid);
|
||||
}
|
||||
|
||||
/*
|
||||
* Now create users home directory. Check for an existing directory,
|
||||
* some systems have already created a home directory. If one is found
|
||||
* it is removed to create a fresh one.
|
||||
*/
|
||||
sprintf(temp, "%s/%s", argv[4], argv[2]);
|
||||
if ((access(temp, R_OK)) == 0) {
|
||||
if ((access("/bin/rm", X_OK)) == 0)
|
||||
strcpy(shell, "/bin/rm");
|
||||
args[0] = (char *)"/bin/rm";
|
||||
else if ((access("/usr/bin/rm", X_OK)) == 0)
|
||||
strcpy(shell, "/usr/bin/rm");
|
||||
args[0] = (char *)"/usr/bin/rm";
|
||||
else {
|
||||
syslog(LOG_WARNING, "Can't find rm");
|
||||
exit(2);
|
||||
}
|
||||
sprintf(PassEnt, " -Rf %s", temp);
|
||||
i = execute(shell, PassEnt, (char *)"/dev/tty", (char *)"/dev/tty", (char *)"/dev/tty");
|
||||
args[1] = (char *)"-Rf";
|
||||
args[2] = homedir;
|
||||
args[3] = NULL;
|
||||
i = execute(args, (char *)"/dev/tty", (char *)"/dev/tty", (char *)"/dev/tty");
|
||||
if (i != 0) {
|
||||
syslog(LOG_WARNING, "Unable remove old home directory");
|
||||
exit(2);
|
||||
@ -253,7 +274,7 @@ int main(int argc, char *argv[])
|
||||
syslog(LOG_WARNING, "Can't get passwd entry for %s", argv[2]);
|
||||
exit(2);
|
||||
}
|
||||
makedir(temp, 0770, pwuser->pw_uid, pwent->pw_gid);
|
||||
makedir(homedir, 0770, pwuser->pw_uid, pwent->pw_gid);
|
||||
|
||||
/*
|
||||
* Create Maildir and subdirs for Qmail.
|
||||
@ -268,16 +289,22 @@ int main(int argc, char *argv[])
|
||||
makedir(temp, 0700, pwuser->pw_uid, pwent->pw_gid);
|
||||
|
||||
#ifdef _VPOPMAIL_PATH
|
||||
sprintf(temp, "%s/vadduser %s %s", _VPOPMAIL_PATH, argv[2], argv[2]);
|
||||
sprintf(temp, "%s/vadduser", _VPOPMAIL_PATH);
|
||||
args[0] = temp;
|
||||
args[1] = argv[2];
|
||||
args[2] = argv[2];
|
||||
args[3] = NULL;
|
||||
|
||||
if (system(temp) != 0) {
|
||||
if (execute(args, (char *)"/dev/tty", (char *)"/dev/tty", (char *)"/dev/tty") != 0) {
|
||||
syslog(LOG_WARNING, "Failed to create vpopmail account");
|
||||
} else {
|
||||
syslog(LOG_WARNING, "Created vpopmail account");
|
||||
}
|
||||
#endif
|
||||
|
||||
free(shell);
|
||||
free(PassEnt);
|
||||
free(temp);
|
||||
free(homedir);
|
||||
syslog(LOG_WARNING, "Added system account for user\"%s\"", argv[2]);
|
||||
exit(0);
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
#define _MBUSERADD_H
|
||||
|
||||
|
||||
int execute(char *, char *, char *, char *, char *);
|
||||
int execute(char **, char *, char *, char *);
|
||||
void makedir(char *, mode_t, uid_t, gid_t);
|
||||
void Help(void);
|
||||
|
||||
|
Reference in New Issue
Block a user