Files
mars-nwe/opt/sendm.c
Mario Fetka f8317503df
All checks were successful
Source release / source-package (push) Successful in 40s
docs: normalize source license headers to gpl2 only
2026-06-03 00:46:27 +02:00

89 lines
2.3 KiB
C

/* SPDX-License-Identifier: GPL-2.0-only */
/*
* This file is part of mars_nwe.
*
* Copyright (C) 1993-2000 Martin Stover, Marburg, Germany
* Copyright (C) 2026 Mario Fetka
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 only.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
/* sendm.c 23-Oct-96 */
/*
* simple demo for a sendmail acces under DOS
* DOS <-> UNX command handling using PIPE filesystem.
* can be used with unxsendm for UNX.
*
* Can also be used under Linux for ncpfs <-> mars_nwe.
* but do not use it directly (the opencall will destroy unxsendm)!!
*
* QUICK + DIRTY !!!
*/
#define ENV_UNXCOMM "UNXSENDM"
#ifdef LINUX
# include <unistd.h>
# include <string.h>
# define DEFAULT_COMM "/pipes/unxsendm"
# else
# define DEFAULT_COMM "p:/unxsendm"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#ifndef LINUX
# include <io.h>
#endif
#include <fcntl.h>
int main(int argc, char **argv)
{
char *unxcomm=getenv(ENV_UNXCOMM);
int fdout;
int fdin;
int is_pipe=isatty(0) ? 0 :1;
if (NULL == unxcomm)
unxcomm=DEFAULT_COMM;
fdout = open(unxcomm, O_RDWR);
fdin = dup(fdout);
if (fdout > -1 && fdin > -1) {
char **pp=argv+1;
unsigned char b=32;
int size;
char buf[1024];
while(--argc >0) {
if (write(fdout, *pp, strlen(*pp))) {}
++pp;
if (write(fdout, &b, 1)) {}
}
b=0;
if (write(fdout, &b, 1)) {}
close(fdout);
fdout=dup(fdin);
if (6 == (size = read(fdin, buf, 6)) && !memcmp(buf, "+++++\n", 6)) {
/* now write stdin -> sendmail */
if (is_pipe) {
while (0 < (size = fread(buf, 1, sizeof(buf), stdin)))
if (write(fdout, buf, size)) {}
}
} else if (size > 0)
if (write(1, buf, size)) {} /* probably errormessage */
close(fdout);
/* now we print errors */
while (0 < (size = read(fdin, buf, sizeof(buf)))) {
if (write(1, buf, size)) {}
}
close(fdin);
return(0);
} else
fprintf(stderr, "Cannot open PIPECOMMAND '%s'\n", unxcomm);
return(1);
}