|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T b
Length: 9570 (0x2562)
Types: TextFile
Names: »bind.c«
└─⟦3d0c2be1b⟧ Bits:30001254 ISODE-5.0 Tape
└─⟦eba4602b1⟧ »./isode-5.0.tar.Z«
└─⟦d3ac74d73⟧
└─⟦this⟧ »isode-5.0/quipu/dish/bind.c«
/* bind.c - */
#ifndef lint
static char *rcsid = "$Header: /f/osi/quipu/dish/RCS/bind.c,v 6.0 89/03/18 23:40:37 mrose Rel $";
#endif
/*
* $Header: /f/osi/quipu/dish/RCS/bind.c,v 6.0 89/03/18 23:40:37 mrose Rel $
*
*
* $Log: bind.c,v $
* Revision 6.0 89/03/18 23:40:37 mrose
* Release 5.0
*
*/
/*
* NOTICE
*
* Acquisition, use, and distribution of this module and related
* materials are subject to the restrictions of a license agreement.
* Consult the Preface in the User's Manual for the full terms of
* this agreement.
*
*/
#include "quipu/util.h"
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <signal.h>
#include "quipu/dua.h"
#include "quipu/name.h"
#include "quipu/bind.h"
#include "quipu/dsp.h"
#include "quipu/ds_error.h"
#include "tailor.h"
#ifndef ETCDIR
#define ETCDIR "/etc/"
#endif
extern DN fixed_pos;
DN user_name;
extern LLog *log_dua;
extern PS opt,
rps;
extern char retpipe[],
inbuf [],
bound,
frompipe;
extern int fd;
extern unsigned connect_time,
cache_time;
static char username [LINESIZE];
static char password [LINESIZE];
static char first_bind = TRUE;
static struct ds_bind_arg bindarg;
static struct ds_bind_arg bindresult;
static struct ds_bind_error binderr;
#ifndef NO_STATS
extern LLog * log_stat;
#endif
SFD unbind_sig ()
{
SFD dish_quit ();
#ifndef NO_STATS
LLOG (log_stat,LLOG_NOTICE,("Connection closed"));
#endif
if (bound)
(void) ds_unbind ();
bound = FALSE;
if (frompipe) {
(void) signal (SIGALRM, dish_quit);
(void) alarm (cache_time);
}
}
call_bind (argc,argv)
int argc;
char ** argv;
{
int x;
char noconnect = FALSE;
char bpass [LINESIZE];
char bname [LINESIZE];
char bdsa [LINESIZE];
char *save_address;
extern char * dsa_address,
* myname;
FILE *fp;
char buf[BUFSIZ];
extern char * tailfile;
(void) strcpy (bpass,password);
(void) strcpy (bname,username);
bdsa[0] = 0;
save_address = dsa_address;
for (x=1; x<argc; x++) {
if (test_arg (argv[x], "-noconnect",1))
noconnect = TRUE;
#ifdef PDU_DUMP
else if (test_arg (argv[x], "-pdus",2)) {
if (++x == argc) {
ps_print (opt,"PDU file name missing\n");
Usage (argv[0]);
return (NOTOK);
}
ps_printf (rps,"Dumping PDUs in directory %s\n",argv[x]);
pdu_dump_init (argv[x]);
}
#endif
else if (test_arg (argv[x], "-user",1)) {
if ((++x == argc) || (*argv[x] == '-')) {
x--;
*bname = 0;
} else
(void) strcpy (bname,argv[x]);
} else if (test_arg (argv[x], "-pipe",2)) {
if (strcmp (argv[0],"dish") == 0)
ps_print (opt,"Sorry... '-pipe' must be the first argument to dish.\n");
else
Usage (argv[0]);
return (NOTOK);
} else if (test_arg (argv[x], "-password",2)) {
if ((++x == argc) || (*argv[x] == '-')) {
x--;
*bpass = 0;
} else
(void) strcpy (bpass,argv[x]);
} else if (test_arg (argv[x], "-call",1)) {
if (++x == argc) {
ps_print (opt,"dsa name missing\n");
Usage (argv[0]);
return (NOTOK);
}
(void) strcpy (bdsa,argv[x]);
} else {
ps_printf (opt,"Unknown option %s\n",argv[x]);
Usage (argv[0]);
return (NOTOK);
}
}
if (noconnect)
return (OK);
if (*bpass == 0) {
bindarg.dba_passwd_len = 0;
bindarg.dba_passwd[0] = 0;
if (*bname != 0) {
get_password (bname,&bindarg.dba_passwd[0]);
if (bindarg.dba_passwd[0] != 0)
bindarg.dba_passwd_len = strlen (&bindarg.dba_passwd[0]);
}
} else {
bindarg.dba_passwd_len = strlen (bpass);
(void) strcpy (bindarg.dba_passwd,bpass);
}
if (*bname == 0)
bindarg.dba_dn = NULLDN;
else {
char * bnameptr;
bnameptr = bname;
if (*bnameptr == '@')
bnameptr++;
if ((bindarg.dba_dn = str2dn (bnameptr)) == NULLDN) {
ps_printf (opt,"Invalid user name %s",bname);
Usage (argv[0]);
return (NOTOK);
}
}
/* now set dsa_address */
if (bdsa[0] != 0) {
myname = bdsa;
dsa_address = NULLCP;
/* read tailor file to get address */
if( (fp = fopen(isodefile(tailfile), "r")) == (FILE *)NULL) {
LLOG (log_dua,LLOG_FATAL,("can't open tailor file '%s'", isodefile(tailfile)));
fatal (-72, "Cannot open tailor file");
}
while(fgets(buf, sizeof(buf), fp) != NULLCP)
if ( (*buf != '#') && (*buf != '\n') )
/* not a comment or blank */
if (tai_string (buf) == NOTOK)
LLOG (log_dua,LLOG_DEBUG,("tai_string failed %s",buf));
(void) fclose(fp);
if (dsa_address == NULLCP)
dsa_address = myname;
}
if (bound)
(void) unbind_sig ();
first_bind = FALSE;
if (ds_bind (&bindarg, &binderr, &bindresult) != OK) {
if (binderr.dbe_type == DBE_TYPE_SECURITY)
ps_print (opt, "Security error - Check name and password\n");
else
ps_print (opt, "Service error - Unable to contact DSA\n");
dsa_address = save_address;
return (NOTOK);
}
#ifndef NO_STATS
LLOG (log_stat,LLOG_NOTICE,("Bound '%s' to '%s'",bname,dsa_address));
#endif
bound = TRUE;
user_name = bindarg.dba_dn;
if (frompipe)
ps_print (rps,"Connected\n");
return (OK);
}
rebind () {
if (first_bind) {
char * buff = "bind";
return (call_bind (1,&buff));
}
if (bound)
return (OK);
if (ds_bind (&bindarg, &binderr, &bindresult) != OK) {
if (binderr.dbe_type == DBE_TYPE_SECURITY)
ps_print (opt, "Bind security error\n");
else
ps_print (opt, "Bind service error\n");
return (NOTOK);
}
#ifndef NO_STATS
LLOG (log_stat,LLOG_NOTICE,("re-connect"));
#endif
bound = TRUE;
user_name = bindarg.dba_dn;
return (OK);
}
call_unbind (argc,argv)
int argc;
char ** argv;
{
int file;
int x;
char noquit = FALSE;
extern char resbuf [];
extern int wfd;
for (x=1; x<argc; x++) {
if (test_arg (argv[x], "-noquit",3))
noquit = TRUE;
else {
Usage (argv[0]);
return;
}
}
if (bound)
(void) unbind_sig ();
if (! noquit) {
if (frompipe) {
if ((file = open (inbuf, O_WRONLY)) <= 0)
(void) fprintf (stderr,"Quitting...");
else {
*resbuf = '2';
(void) write (file, resbuf, 1);
(void) close (file);
}
(void) close (fd);
(void) close (wfd);
(void) unlink (retpipe);
} else {
ps_free (opt);
ps_free (rps);
}
exit (0);
}
}
user_tailor ()
{
char *part1;
char *part2;
char *getenv ();
char *ptr = "/.quipurc";
char Dish_Home[LINESIZE];
FILE *file;
char Read_in_Stuff[132];
char *p,
*TidyString();
extern char *local_dit;
extern char dishinit;
*password = 0;
*username = 0;
set_sequence ("default");
bindarg.dba_version = DBA_VERSION_V1988;
bindarg.dba_dn = NULLDN;
bindarg.dba_passwd_len = 0;
bindarg.dba_passwd[0] = 0;
(void) strcpy (Dish_Home, getenv ("HOME"));
(void) strcat (Dish_Home, ptr);
if ((file = fopen (Dish_Home, "r")) == 0)
if (dishinit) {
char cmd_buf [LINESIZE];
int msk;
ps_print (opt,"Please wait whilst I initialise everything...\n");
msk = umask (0111);
(void) sprintf (cmd_buf,"%snew_quipurc",ETCDIR);
if ((file = fopen (Dish_Home, "w")) == 0)
return (OK); /* cant make one */
(void) umask (msk);
(void) fclose (file);
if (system (cmd_buf) == 0) {
(void) chmod (Dish_Home,0600);
if ((file = fopen (Dish_Home, "r")) == 0) {
(void) fprintf (stderr,"Cant open .quipurc - BUT I just created it!!!\n");
return (NOTOK);
}
} else {
(void) unlink (Dish_Home);
return (NOTOK);
}
} else
return (OK); /* no .quipurc */
while (fgets (Read_in_Stuff, 80, file) != 0) {
p = SkipSpace (Read_in_Stuff);
if (( *p == '#') || (*p == '\0'))
continue; /* ignore comments and blanks */
part1 = p;
if ((part2 = index (p,':')) == NULLCP) {
ps_printf (opt,"Seperator missing '%s'\n",p);
return (NOTOK);
}
*part2++ = '\0';
part2 = TidyString (part2);
DLOG (log_dua, LLOG_TRACE, ("Collected '%s', and '%s'.\n", part1, p));
if (lexequ (part1, "username") == 0) {
if ((user_name = str2dn (part2)) == NULLDN) {
ps_printf (opt,"Invalid username %s\n",part2);
return (NOTOK);
}
(void) strcpy (username, part2);
bindarg.dba_dn = user_name;
}
else if (lexequ (part1, "password") == 0) {
(void) strcpy (bindarg.dba_passwd,part2);
(void) strcpy (password, part2);
bindarg.dba_passwd_len = strlen (part2);
} else if (lexequ (part1, "cache_time") == 0)
cache_time = MIN (atoi(part2) * 60, 180000);
/* enforce 5 hour maximum */
else if (lexequ (part1, "connect_time") == 0)
connect_time = MIN (atoi(part2) * 60, 300);
/* enforce 5 minute maximum */
else if (lexequ (part1, "service") == 0)
new_service (part2);
else if (lexequ (part1, "type") == 0) {
if (lexequ (part2,"unknown") == 0)
show_unknown();
} else if (lexequ (part1, "notype") == 0)
new_ignore (part2);
else if (lexequ (part1, "dsap") == 0)
(void) tai_string (part2);
else if (lexequ (part1, "isode") == 0) {
char * split;
if ((split = index (part2,' ')) != NULLCP) {
*split++ = 0;
(void)isodesetvar (part2,strdup(split),0);
}
} else if (set_cmd_default (part1,part2) != OK)
if (add_alias (part1,part2) != OK) {
ps_printf (opt,"Unknown parameter %s\n",part1);
return (NOTOK);
}
}
if (local_dit != NULLCP)
if ((fixed_pos = str2dn (TidyString(local_dit))) == NULLDN) {
ps_printf (opt,"Invalid default position (dsaptailor) %s\n",local_dit);
return (NOTOK);
}
(void) strcpy (bindarg.dba_passwd,password);
bindarg.dba_passwd_len = strlen (password);
isodexport ();
return (OK);
}