Index: ossp-pkg/lmtp2nntp/fixme.h RCS File: /v/ossp/cvs/ossp-pkg/lmtp2nntp/Attic/fixme.h,v rcsdiff -q -kk '-r1.3' '-r1.4' -u '/v/ossp/cvs/ossp-pkg/lmtp2nntp/Attic/fixme.h,v' 2>/dev/null --- fixme.h 2002/01/31 09:03:58 1.3 +++ fixme.h 2002/01/31 10:14:54 1.4 @@ -58,24 +58,30 @@ uid_t option_uid; int option_daemon; - /*FIXME replaced by following + /* int option_aclc; struct acl option_acl[MAXACLS]; - */ - int nacl; - struct acl *pacl; + FIXME replaced by following */ + int nacl; /* number of acl structures found at pacl */ + struct acl *pacl; /* pointer to an array of acl structures */ int option_veryverbose; int option_childsmax; int active_childs; l2_env_t *l2_env; l2_channel_t *l2; + /* sa_addr_t *saaAltio; sa_t *saAltio; + FIXME replaced by following */ + sa_addr_t *saaServerbind; + sa_t *saServerbind; + char *cpBindh; char *cpBindp; sa_addr_t *saaBind; sa_t *saBind; + sa_addr_t *saaIO; sa_t *saIO; int fdIOi; Index: ossp-pkg/lmtp2nntp/lmtp2nntp_config.c RCS File: /v/ossp/cvs/ossp-pkg/lmtp2nntp/lmtp2nntp_config.c,v rcsdiff -q -kk '-r1.19' '-r1.20' -u '/v/ossp/cvs/ossp-pkg/lmtp2nntp/lmtp2nntp_config.c,v' 2>/dev/null --- lmtp2nntp_config.c 2002/01/31 09:03:58 1.19 +++ lmtp2nntp_config.c 2002/01/31 10:14:54 1.20 @@ -257,6 +257,108 @@ catch (ex) rethrow; + /* --bind SINGLE */ + try { + if ( (val_get(ctx->val, "option.bind", &ov) != VAL_OK) + || (ov->ndata != 1) + || (ov->data.s == NULL) + ) throw(0,0,0); + log1(ctx, TRACE, "--bind = \"%s\"", ov->data.s); + + /* dash means stdio */ + if (strcmp(ov->data.s, "-") != 0) { //FIXME does this work with popt()? + if ((rc = sa_create(&ctx->saServerbind)) != SA_OK) { + log1(ctx, ERROR, "option --bind, creating TCP socket (internal) failed with \"%s\"", + sa_error(rc)); + throw(0,0,0); + } + if ((rc = sa_addr_create(&ctx->saaServerbind)) != SA_OK) { + log1(ctx, ERROR, "option --bind, create address (internal) failed with \"%s\"", + sa_error(rc)); + throw(0,0,0); + } + /* slash means UNIX socket */ + if (ov->data.s[0] == '/') { + char *cpPath; + char *cpPerm; + int nPerm; + int n; + int i; + + cpPath = strdup(optarg); + cpPerm = NULL; + nPerm = -1; + if ((cpPerm = strrchr(cpPath, ':')) != NULL) { + *cpPerm++ = '\0'; + nPerm = 0; + for (i = 0; i < 4 && cpPerm[i] != '\0'; i++) { + if (!isdigit((int)cpPerm[i])) { + nPerm = -1; + break; + } + n = cpPerm[i] - '0'; + if (n > 7) { + nPerm = -1; + break; + } + nPerm = ((nPerm << 3) | n); + } + if (nPerm == -1 || cpPerm[i] != '\0') { + log1(ctx, ERROR, "option --bind, invalid permissions \"%s\"", + cpPerm); + throw(0,0,0); + } + } + if ((rc = sa_addr_u2a(ctx->saaServerbind, "unix:%s", cpPath)) != SA_OK) { + log2(ctx, ERROR, "option --bind, parsing alternate IO guessing UNIX socket (%s) failed with \"%s\"", + cpPath, sa_error(rc)); + throw(0,0,0); + } + if ((rc = sa_bind(ctx->saServerbind, ctx->saaServerbind)) != SA_OK) { + log2(ctx, ERROR, "option --bind, bind (%s) failed with \"%s\"", + cpPath, sa_error(rc)); + throw(0,0,0); + } + if (nPerm != -1) { + if (chmod(cpPath, nPerm) == -1) { + log3(ctx, ERROR, "option --bind, chmod (%s, 0%o) failed with \"%s\"", + cpPath, nPerm, strerror(errno)); + throw(0,0,0); + } + } + if (getuid() == 0 && getuid() != ctx->option_uid) { + if (chown(cpPath, ctx->option_uid, -1) == -1) { + log3(ctx, ERROR, "option --bind, chown (%s, %d) failed with \"%s\"", + cpPath, ctx->option_uid, strerror(errno)); + throw(0,0,0); + } + } + free(cpPath); + } + /* otherwise assume INET socket */ + else { + if ((rc = sa_addr_u2a(ctx->saaServerbind, "inet://%s", ov->data.s)) != SA_OK) { + log2(ctx, ERROR, "option --bind, parsing alternate IO guessing INET socket (%s) failed with \"%s\"", + ov->data.s, sa_error(rc)); + throw(0,0,0); + } + if ((rc = sa_bind(ctx->saServerbind, ctx->saaServerbind)) != SA_OK) { + log2(ctx, ERROR, "option --bind, bind (%s) failed with \"%s\"", + ov->data.s, sa_error(rc)); + throw(0,0,0); + } + } + /* for either sockets */ + if ((rc = sa_listen(ctx->saServerbind, -1)) != SA_OK) { + log2(ctx, ERROR, "option --bind, listen (%s) failed with \"%s\"", + ov->data.s, sa_error(rc)); + throw(0,0,0); + } + } + } + catch (ex) + rethrow; + CUS: return; } Index: ossp-pkg/lmtp2nntp/lmtp2nntp_main.c RCS File: /v/ossp/cvs/ossp-pkg/lmtp2nntp/lmtp2nntp_main.c,v rcsdiff -q -kk '-r1.13' '-r1.14' -u '/v/ossp/cvs/ossp-pkg/lmtp2nntp/lmtp2nntp_main.c,v' 2>/dev/null --- lmtp2nntp_main.c 2002/01/31 09:03:58 1.13 +++ lmtp2nntp_main.c 2002/01/31 10:14:54 1.14 @@ -431,8 +431,8 @@ ctx->active_childs = 0; ctx->l2_env = NULL; ctx->l2 = NULL; - ctx->saaAltio = NULL; - ctx->saAltio = NULL; + ctx->saaServerbind = NULL; + ctx->saServerbind = NULL; ctx->cpBindh = NULL; ctx->cpBindp = NULL; ctx->saaBind = NULL; @@ -482,89 +482,6 @@ /* read in the arguments */ while ((i = getopt(argc, argv, "C:DKP:Va:b:c:d:g:h:l:m:n:o:r:s:t:u:v")) != -1) { switch (i) { - case 'b': /*POD [B<-b> I[I<:port>]|C<->|I[:perms]] */ - if (strcmp(optarg, "-") != 0) { - if ((rc = sa_create(&ctx->saAltio)) != SA_OK) { - fprintf(stderr, "%s:Error: Creating TCP socket failed for \"%s\": %s\n", - ctx->progname, optarg, strerror(errno)); - CU(ERR_EXECUTION); - } - if ((rc = sa_addr_create(&ctx->saaAltio)) != SA_OK) { - fprintf(stderr, "%s:Error: Creating address failed for -b option (%d)\n", - ctx->progname, rc); - } - if (optarg[0] == '/') { - char *cpPath; - char *cpPerm; - int nPerm; - int n; - - cpPath = strdup(optarg); - cpPerm = NULL; - nPerm = -1; - if ((cpPerm = strrchr(cpPath, ':')) != NULL) { - *cpPerm++ = '\0'; - nPerm = 0; - for (i = 0; i < 4 && cpPerm[i] != '\0'; i++) { - if (!isdigit((int)cpPerm[i])) { - nPerm = -1; - break; - } - n = cpPerm[i] - '0'; - if (n > 7) { - nPerm = -1; - break; - } - nPerm = ((nPerm << 3) | n); - } - if (nPerm == -1 || cpPerm[i] != '\0') { - fprintf(stderr, "%s:Error: Invalid permissions \"%s\"\n", ctx->progname, cpPerm); - CU(ERR_EXECUTION); - } - } - if ((rc = sa_addr_u2a(ctx->saaAltio, "unix:%s", cpPath)) != SA_OK) { - fprintf(stderr, "%s:Error: Parsing alternate IO guessing UNIX domain socket failed for \"%s\" (%d)\n", - ctx->progname, cpPath, rc); - CU(ERR_EXECUTION); - } - if ((rc = sa_bind(ctx->saAltio, ctx->saaAltio)) != SA_OK) { - fprintf(stderr, "%s:Error: Bind failed for \"%s\": %s\n", - ctx->progname, cpPath, strerror(errno)); - CU(ERR_EXECUTION); - } - if (nPerm != -1) { - if (chmod(cpPath, nPerm) == -1) { - fprintf(stderr, "%s:Error: chmod failed for \"%s\": %s\n", ctx->progname, cpPath, strerror(errno)); - CU(ERR_EXECUTION); - } - } - if (getuid() == 0 && getuid() != ctx->option_uid) { - if (chown(cpPath, ctx->option_uid, -1) == -1) { - fprintf(stderr, "%s:Error: chown failed for \"%s\": %s\n", ctx->progname, cpPath, strerror(errno)); - CU(ERR_EXECUTION); - } - } - free(cpPath); - } - else { - if ((rc = sa_addr_u2a(ctx->saaAltio, "inet://%s", optarg)) != SA_OK) { - fprintf(stderr, "%s:Error: Parsing alternate IO guessing INET socket failed for \"%s\" (%d)\n", - ctx->progname, optarg, rc); - CU(ERR_EXECUTION); - } - if ((rc = sa_bind(ctx->saAltio, ctx->saaAltio)) != SA_OK) { - fprintf(stderr, "%s:Error: Bind failed for \"%s\": %s\n", - ctx->progname, optarg, strerror(errno)); - CU(ERR_EXECUTION); - } - } - if ((rc = sa_listen(ctx->saAltio, -1)) != SA_OK) { - fprintf(stderr, "%s:Error: Listen to failed for \"%s\": %s\n", - ctx->progname, optarg, strerror(errno)); - CU(ERR_EXECUTION); - } - } - break; case 'c': /*POD [B<-c> I[I<:port>]] */ ctx->cpBindh = strdup(optarg); if ((ctx->cpBindp = strrchr(ctx->cpBindh, ':')) != NULL) { @@ -908,7 +825,7 @@ signal(SIGUSR2, SIG_IGN ); /* loop for LMTP protocol with support for alternate io through daemon */ - if (ctx->saAltio == NULL) { + if (ctx->saServerbind == NULL) { /* initialize LMTP context */ ctx->fdIOi = STDIN_FILENO; ctx->fdIOo = STDOUT_FILENO; @@ -960,17 +877,17 @@ } } - sa_timeout(ctx->saAltio, SA_TIMEOUT_ALL, 0, 0); - sa_timeout(ctx->saAltio, SA_TIMEOUT_ACCEPT, ctx->option_timeout_lmtp_accept, 0); - sa_timeout(ctx->saAltio, SA_TIMEOUT_READ, ctx->option_timeout_lmtp_read, 0); - sa_timeout(ctx->saAltio, SA_TIMEOUT_WRITE, ctx->option_timeout_lmtp_write, 0); + sa_timeout(ctx->saServerbind, SA_TIMEOUT_ALL, 0, 0); + sa_timeout(ctx->saServerbind, SA_TIMEOUT_ACCEPT, ctx->option_timeout_lmtp_accept, 0); + sa_timeout(ctx->saServerbind, SA_TIMEOUT_READ, ctx->option_timeout_lmtp_read, 0); + sa_timeout(ctx->saServerbind, SA_TIMEOUT_WRITE, ctx->option_timeout_lmtp_write, 0); while (1) { while (ctx->active_childs >= ctx->option_childsmax) { log1(ctx, ERROR, "maximum number of childs (%d) reached - waiting (1s)", ctx->option_childsmax); sleep(1); } - if ((rc = sa_accept(ctx->saAltio, &ctx->saaIO, &ctx->saIO)) != SA_OK) { + if ((rc = sa_accept(ctx->saServerbind, &ctx->saaIO, &ctx->saIO)) != SA_OK) { if (rc == SA_ERR_SYS) log3(ctx, ERROR, "accept failed: %s: (%d) %s", sa_error(rc), errno, strerror(errno)); else @@ -1050,8 +967,8 @@ log1(ctx, NOTICE, "startup new child process, parent pid[%d]", getppid()); /* child must close listening socket */ - sa_destroy(ctx->saAltio); - ctx->saAltio = NULL; /* prevent cleanup from free'ing this again */ + sa_destroy(ctx->saServerbind); + ctx->saServerbind = NULL; /* prevent cleanup from free'ing this again */ /* initialize LMTP context */ lmtp_io.ctx = ctx; @@ -1097,10 +1014,10 @@ log0(ctx, NOTICE, "graceful shutdown shortly before exit - no more logging"); l2_channel_destroy(ctx->l2); l2_env_destroy(ctx->l2_env); - if (ctx->saAltio) - sa_destroy(ctx->saAltio); - if (ctx->saaAltio) - sa_addr_destroy(ctx->saaAltio); + if (ctx->saServerbind) + sa_destroy(ctx->saServerbind); + if (ctx->saaServerbind) + sa_addr_destroy(ctx->saaServerbind); if (ctx->option_restrictheader != NULL) free(ctx->option_restrictheader); if (ctx->azHeaderValuePairs != NULL)