Subject: putprtcnam / DU4 -> register X-terminals ?
To: None <port-alpha@NetBSD.ORG>
From: daniel Azuelos <dan@pasteur.fr>
List: port-alpha
Date: 09/18/1996 16:15:07
We've written the following piece of code to add X-terminals on a
DU with enhanced security.

# cat <<'eof' >add_tx.c
/*
** Allows priviledged users to add a tty on Digital Unix + C2
*/

#include <stdio.h>
#include <malloc.h>
#include <sys/types.h>
#include <sys/security.h>
#include <prot.h>
#include <string.h>

typedef struct  pr_term *T_pterm;
T_pterm term;
char *term_name;
char *cname;
int     to_rm = 0;
#define REMOVE  "rm_tx"

int     main (int argc, char **argv)
{
        set_auth_parameters (argc, argv);
        if (geteuid() != 0) {
                fprintf (stderr, "%s may only be run as `root'.\n", argv[0]);
                exit (0);
        }
        if (argc != 2) {
                fprintf (stderr, "Usage: %s term_x_name\n", argv[0]);
                exit (1);
        }
        cname = strrchr (argv[0], '/') + 1;
        if (cname == NULL) cname = argv[0];
        fprintf (stderr, "cname = %s\n", cname);
        if (strcmp ( cname, REMOVE) == 0) {
                to_rm = 1;
        }
        if ((term_name = (char *)malloc (strlen(argv[1]) + 3)) == (char *) NULL) {
                perror ("malloc");
                exit (1);
        }
        term_name = strcat (argv[1], ":0");
        fprintf( stderr, "term_name = %s\tto_rm = %d\n", term_name, to_rm);

        term = getprtcnam (term_name);
        if ((to_rm == 0) && (term != (T_pterm)NULL)) {
                fprintf (stderr, "%s already exists. Aborting.\n", argv[1]);
                exit (1);
        }
        if ((to_rm == 1) && (term == (T_pterm)NULL)) {
                fprintf (stderr, "%s doesn't exist. Aborting.\n", argv[1]);
                exit (1);
        }
        if ((term = (T_pterm) malloc (sizeof *term)) == (T_pterm) NULL) {
                perror ("malloc");
                exit (1);
        }
        strcpy (term->ufld.fd_devname, "*");
        term->ufld.fd_xdisp = 1;
        term->ufld.fd_login_timeout = 0;
        to_rm ? (term->uflg.fg_devname = 0) : (term->uflg.fg_devname = 1);
        term->uflg.fg_uid = 0;
        term->uflg.fg_slogin = 0;
        term->uflg.fg_uuid = 0;
        term->uflg.fg_ulogin = 0;
        term->uflg.fg_loutuid = 0;
        term->uflg.fg_louttime = 0;
        term->uflg.fg_nlogins = 0;
        term->uflg.fg_max_tries = 0;
        term->uflg.fg_logdelay = 0;
        term->uflg.fg_unlockint = 0;
        term->uflg.fg_lock = 0;
        term->uflg.fg_xdisp = 1;
        term->uflg.fg_login_timeout = 1;

        if (putprtcnam(term_name, term) == 0) {
                perror ("putprtcnam");
                exit(1);
        }
        return (0);
}
eof

To compile it, you have to do:
LDFLAGS=-lsecurity make add_tx

Here is the real question:
under DU 3.2x, this program was perfectly working.
under DU 4.0 it gives the following message:

# ./add_tx zozie.fanfreluche.zob.com
cname = add_tx.1
term_name = zozie.fanfreluche.zob.com:0 to_rm = 0
putprtcnam: Invalid argument
#

How to track down the problem ? Any help would be greatly appreciated.

-- 
dan     ``La langue de l'alligator ne s'attrape pas avec les mains.''