bind.c
来自「ftam等标准协议服务器和客户端的源代码。」· C语言 代码 · 共 958 行 · 第 1/2 页
C
958 行
if (secure_ds_bind (&bindarg, &binderr, &bindresult) != OK) { (void) signal (SIGALRM, SIG_IGN); if (binderr.dbe_value == 0) ps_print (OPT, "*** Service error : Unable to contact DSA ***\n"); else ds_bind_error(OPT, &binderr);#ifdef DEBUG if (binderr.dbe_cc) ps_printf (OPT, "%s\n", binderr.dbe_data);#endif dsa_address = save_address; myname = save_name; return (NOTOK); } (void) signal (SIGALRM, SIG_IGN); main_dsa_id = dsap_ad;#ifndef NO_STATS LLOG (log_stat,LLOG_NOTICE,("Bound '%s' to '%s'",username,myname));#endif bound = TRUE; user_name = bindarg.dba_dn; return (OK); }rebind () { if (referral_dsa != 0) { (void) dap_unbind (referral_dsa); referral_dsa = 0; dsap_ad = main_dsa_id; } if (first_bind) { char * buff = "bind"; return (call_bind (1,&buff)); } if (bound) return (OK); /* prepare credentials */ bindarg.dba_auth_type = auth_type; switch (auth_type) { case DBA_AUTH_NONE: case DBA_AUTH_SIMPLE: break; case DBA_AUTH_PROTECTED: protect_password(); break; case DBA_AUTH_STRONG: if (sign_bindarg() != OK) bindarg.dba_auth_type = DBA_AUTH_NONE; break; } binderr.dbe_value = 0; bind_alarm (); if (secure_ds_bind (&bindarg, &binderr, &bindresult) != OK) { (void) signal (SIGALRM, SIG_IGN); if (binderr.dbe_value == 0) ps_print (OPT, "*** Service error: Unable to contact DSA ***\n"); else ds_bind_error(OPT, &binderr);#ifdef DEBUG if (binderr.dbe_cc) ps_printf (OPT, "%s\n", binderr.dbe_data);#endif return (NOTOK); } (void) signal (SIGALRM, SIG_IGN); main_dsa_id = dsap_ad;#ifndef NO_STATS LLOG (log_stat,LLOG_NOTICE,("re-connect"));#endif bound = TRUE; user_name = bindarg.dba_dn; return (OK);}referral_bind (addr) struct PSAPaddr * addr;{ if (referral_dsa != 0) (void) dap_unbind (referral_dsa++); else referral_dsa = dsap_ad + 1; dsap_ad = referral_dsa; /* prepare credentials */ bindarg.dba_auth_type = auth_type; switch (auth_type) { case DBA_AUTH_NONE: case DBA_AUTH_SIMPLE: break; case DBA_AUTH_PROTECTED: protect_password(); break; case DBA_AUTH_STRONG: (void) sign_bindarg(); break; } binderr.dbe_value = 0; bind_alarm (); if (dap_bind (&dsap_ad, &bindarg, &binderr, &bindresult, addr) != OK) { (void) signal (SIGALRM, SIG_IGN); if (binderr.dbe_value == 0) ps_print (OPT, "*** Service error : Unable to contact DSA ***\n"); else ds_bind_error(OPT, &binderr);#ifdef DEBUG if (binderr.dbe_cc) ps_printf (OPT, "%s\n", binderr.dbe_data);#endif referral_dsa = 0; dsap_ad = main_dsa_id; return (0); } (void) signal (SIGALRM, SIG_IGN); referral_dsa = dsap_ad;#ifndef NO_STATS LLOG (log_stat,LLOG_NOTICE,("referral connect"));#endif return (1);}call_unbind (argc,argv)int argc;char ** argv;{ int x; char noquit = FALSE; extern char resbuf []; static int very_first_time = 1; for (x=1; x<argc; x++) { if (test_arg (argv[x], "-noquit",3)) noquit = TRUE; else { Usage (argv[0]); return; } } if (!noquit) (void) signal (SIGINT, SIG_DFL); if (bound) { (void) dap_unbind (main_dsa_id); if (referral_dsa != 0) { (void) dap_unbind (referral_dsa); referral_dsa = 0; } } bound = FALSE; if (! noquit) { if (frompipe) exit_pipe (); ps_free (opt); ps_free (rps); directory_free (database_root); /* clean /tmp files */ exit (0); } else if (dad_flag && very_first_time) { very_first_time = 0; cache_time = 24 * 60 * 60; }}unbind_from_dsa (){ if (bound) { (void) dap_unbind (main_dsa_id); if (referral_dsa != 0) { (void) dap_unbind (referral_dsa); referral_dsa = 0; } } bound = FALSE;}extern char no_rcfile;static time_t rc_mod_time;static char Dish_Home[LINESIZE];user_tailor (){ int isenv; char *part1; char *part2; char *getenv (); char *home; FILE *file; char Read_in_Stuff[BUFSIZ]; char *p, *TidyString(); extern char *local_dit; extern char dishinit; struct stat sbuf; *password = 0; *username = 0; set_sequence ("default"); (void) set_cmd_default ("modify","-dontusecopy"); /* we dont want to make templates with copies */ bzero ((char *)&bindarg, sizeof bindarg); bindarg.dba_version = DBA_VERSION_V1988; isenv = 0; if (home = getenv ("QUIPURC")) (void) strcpy (Dish_Home, home), isenv = 1; else if (home = getenv ("HOME")) (void) sprintf (Dish_Home, "%s/.quipurc", home); else (void) strcpy (Dish_Home, "./.quipurc"); if (no_rcfile) goto out; if (stat (Dish_Home,&sbuf) != 0) { if (isenv) goto no_dice; if (dishinit && !frompipe) { char cmd_buf [LINESIZE]; int msk; ps_print (OPT,"Please wait whilst I initialise everything...\n"); msk = umask (0111); (void) strcpy (cmd_buf, isodefile ("new_quipurc", 1)); 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 %s - BUT I just created it!!!\n", Dish_Home); return (NOTOK); } } else { (void) unlink (Dish_Home); return (NOTOK); } rc_mod_time = time ((time_t *)0); } else { rc_mod_time = time ((time_t *)0); goto out; } } else rc_mod_time = sbuf.st_mtime; if ((file = fopen (Dish_Home, "r")) == 0) {no_dice: ; (void) fprintf (stderr,"Cant open "); perror (Dish_Home); return NOTOK; } while (fgets (Read_in_Stuff, BUFSIZ, 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); if (lexequ (part1, "username") == 0) { if ((user_name = str2dn (*part2 != '@' ? part2 : part2 + 1)) == NULLDN) { ps_printf (OPT,"Invalid DN for 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, 5 * 60 * 60); /* enforce 5 hour maximum */ else if (lexequ (part1, "connect_time") == 0) connect_time = MIN (atoi(part2) * 60, 5 * 60); /* 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, "sequence") == 0) { DN sdn; if ( (sdn = str2dn (*part2 != '@' ? part2 : part2 + 1)) == NULLDN) { ps_printf (OPT,"Invalid DN for sequence: %s\n",part2); return (NOTOK); } (void) add_sequence (sdn); } 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 (*part2 == '@') part2++; if (add_alias (part1,part2) != OK) { ps_printf (OPT,"Unknown parameter %s\n",part1); return (NOTOK); } } } (void) fclose (file);out:; if ((local_dit != NULLCP) && (strcmp ("@", TidyString(local_dit)) != 0)) if ((fixed_pos = str2dn (*local_dit != '@' ? local_dit : local_dit + 1)) == NULLDN) { ps_printf (OPT,"Invalid DN for dsaptailor default position: %s\n",local_dit); return (NOTOK); } (void) strcpy (bindarg.dba_passwd,password); bindarg.dba_passwd_len = strlen (password); isodexport (NULLCP); return (OK);}test_rc_file (ps)PS ps;{ struct stat sbuf; if (stat (Dish_Home,&sbuf) != 0) return; if (rc_mod_time < sbuf.st_mtime) { ps_printf (ps,"WARNING: %s has changed - but not re-read!!!\n", Dish_Home); rc_mod_time = sbuf.st_mtime; }}SFD dish_quit (sig)int sig;{ if (bound) { (void) dap_unbind (main_dsa_id); if (referral_dsa != 0) { (void) dap_unbind (referral_dsa); referral_dsa = 0; } } if (frompipe) exit_pipe (); else (void) fprintf (stderr,"Dish Problem\n"); hide_picture(); switch (sig) { case SIGALRM: LLOG (log_dsap, LLOG_EXCEPTIONS, ("Timer expired :- Dish quitting")); exit (0); case SIGHUP: case SIGINT: case SIGTERM: LLOG (log_dsap, LLOG_EXCEPTIONS, ("Dish quitting - signal %d",sig)); exit (0); default: LLOG (log_dsap, LLOG_FATAL, ("Dish problem - signal %d",sig)); (void) signal (sig, SIG_DFL); /* to stop recursion */ abort (); } }static int protect_password(){long hash;char *cp;int len; bindarg.dba_time1 = new_version(); bindarg.dba_time2 = NULLCP; bindarg.dba_r1.n_bits = 0; bindarg.dba_r1.value = NULLCP; bindarg.dba_r2.n_bits = 0; bindarg.dba_r2.value = NULLCP; hash = 0; hash = hash_passwd(hash, password, strlen(password)); hash = hash_passwd(hash, bindarg.dba_time1, strlen(bindarg.dba_time1)); cp = hash2str(hash, &len); bcopy(cp, bindarg.dba_passwd, len); bindarg.dba_passwd_len = len;}static int sign_bindarg(){struct Nonce *nonce; if (dsap_security == (struct SecurityServices *) 0) return (NOTOK); if (! dsap_security->serv_mknonce) return (NOTOK); nonce = (dsap_security->serv_mknonce)((struct Nonce *) 0); if (nonce == (struct Nonce *) 0) return (NOTOK); bindarg.dba_time1 = nonce->non_time1; bindarg.dba_time2 = nonce->non_time2; bindarg.dba_r1.n_bits = nonce->non_r1.n_bits; bindarg.dba_r1.value = nonce->non_r1.value; bindarg.dba_r2.n_bits = nonce->non_r2.n_bits; bindarg.dba_alg.algorithm = nonce->non_alg.algorithm; bindarg.dba_alg.p_type = nonce->non_alg.p_type; bindarg.dba_alg.asn = nonce->non_alg.asn; free((char *) nonce); if (dsap_security->serv_sign) bindarg.dba_sig = (dsap_security->serv_sign)((char*)&bindarg, _ZTokenToSignDAS, &_ZDAS_mod); else return (NOTOK); if (bindarg.dba_sig == (struct signature *) 0) return (NOTOK); if (dsap_security->serv_mkpath) bindarg.dba_cpath = (dsap_security->serv_mkpath)(); else bindarg.dba_cpath = (struct certificate_list *)0; return (OK);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?