owping/owping.c
/*
 ** Initialize authentication and policy data (used by owping and owfetch)
 */
Initialize authentication and policy data (used by owping and owfetch)
Initialize authentication and policy data ( used by owping and owfetch )
void
owp_set_auth(
        OWPContext    ctx,
        char        *progname,
        ow_ping_trec    *pctx
        )
{
    if(pctx->opt.identity){
        char        *lbuf=NULL;
        size_t      lbuf_max=0;
        char        *passphrase;
        if(pctx->opt.pffile){
            FILE        *filep;
            int         rc = 0;
            if(!(filep = fopen(pctx->opt.pffile,"r"))){
                I2ErrLog(eh,"Unable to open %s: %M",
                        pctx->opt.pffile);
                goto DONE;
            }
            rc = I2ParsePFFile(eh,filep,NULL,0,pctx->opt.identity,NULL,
                    &passphrase,&pfbuff_len,&lbuf,&lbuf_max);
            if(rc < 1){
                I2ErrLog(eh,
                        "Unable to find pass-phrase for id=\"%s\" from pffile=\"%s\"",
                        pctx->opt.identity,pctx->opt.pffile);
            }
            fclose(filep);
        }else{
            char        prompt[MAX_PASSPROMPT];
            if(snprintf(prompt,MAX_PASSPROMPT,
                        "Enter passphrase for identity '%s': ",
                        pctx->opt.identity) >= MAX_PASSPROMPT){
                I2ErrLog(eh,"ip_set_auth: Invalid identity");
                goto DONE;
            }
            if(!(passphrase = I2ReadPassPhraseAlloc(prompt,I2RPP_ECHO_OFF,
                            &lbuf,&lbuf_max))){
                I2ErrLog(eh,"I2ReadPassPhraseAlloc(): %M");
                goto DONE;
            }
            pfbuff_len = strlen(passphrase);
        }
        if(passphrase){
            if( !(pfbuff = malloc(pfbuff_len))){
                I2ErrLog(eh,"malloc: %M");
                exit(1);
            }
            memcpy(pfbuff,passphrase,pfbuff_len);
        }
DONE:
        if(lbuf){
            free(lbuf);
        }
        lbuf = NULL;
        lbuf_max = 0;
        if(pfbuff){
            OWPGetPFFunc    getpf = getclientpf;
            if(!OWPContextConfigSetF(ctx,OWPGetPF,(OWPFunc)getpf)){
                I2ErrLog(eh,"Unable to set pass-phrase func for context: %M");
                exit(1);
            }
        }
        else{
            free(pctx->opt.identity);
            pctx->opt.identity = NULL;
        }
    }
    if(pctx->opt.authmode){
        char    *s = ping_ctx.opt.authmode;
        pctx->auth_mode = 0;
        while(*s != '\0'){
            switch (toupper(*s)){
                case 'O':
                    pctx->auth_mode |= OWP_MODE_OPEN;
                    break;
                case 'A':
                    pctx->auth_mode |= OWP_MODE_AUTHENTICATED;
                    break;
                case 'E':
                    pctx->auth_mode |= OWP_MODE_ENCRYPTED;
                    break;
#ifdef TWAMP
                case 'M':
                    pctx->auth_mode |= TWP_MODE_MIXED;
                    break;
#endif
                default:
                    I2ErrLogP(eh,EINVAL,"Invalid -authmode %c",*s);
                    usage(progname, NULL);
                    exit(1);
            }
            s++;
        }
    }
    else{
        if (pctx->opt.identity) {
            pctx->auth_mode = NWP_DEFAULT_OFFERED_MODE;
        } else {
            pctx->auth_mode = OWP_MODE_OPEN;
        }
    }
}
void owp_set_auth ( OWPContext ctx , char * progname , ow_ping_trec * pctx ) { if ( pctx -> opt . identity ) { char * lbuf = NULL ; size_t lbuf_max = 0 ; char * passphrase ; if ( pctx -> opt . pffile ) { FILE * filep ; int rc = 0 ; if ( ! ( filep = fopen ( pctx -> opt . pffile , " " ) ) ) { I2ErrLog ( eh , " " , pctx -> opt . pffile ) ; goto DONE ; } rc = I2ParsePFFile ( eh , filep , NULL , 0 , pctx -> opt . identity , NULL , & passphrase , & pfbuff_len , & lbuf , & lbuf_max ) ; if ( rc < 1 ) { I2ErrLog ( eh , " \" \" \" \" " , pctx -> opt . identity , pctx -> opt . pffile ) ; } fclose ( filep ) ; } else { char prompt [ MAX_PASSPROMPT ] ; if ( snprintf ( prompt , MAX_PASSPROMPT , " " , pctx -> opt . identity ) >= MAX_PASSPROMPT ) { I2ErrLog ( eh , " " ) ; goto DONE ; } if ( ! ( passphrase = I2ReadPassPhraseAlloc ( prompt , I2RPP_ECHO_OFF , & lbuf , & lbuf_max ) ) ) { I2ErrLog ( eh , " " ) ; goto DONE ; } pfbuff_len = strlen ( passphrase ) ; } if ( passphrase ) { if ( ! ( pfbuff = malloc ( pfbuff_len ) ) ) { I2ErrLog ( eh , " " ) ; exit ( 1 ) ; } memcpy ( pfbuff , passphrase , pfbuff_len ) ; } DONE : if ( lbuf ) { free ( lbuf ) ; } lbuf = NULL ; lbuf_max = 0 ; if ( pfbuff ) { OWPGetPFFunc getpf = getclientpf ; if ( ! OWPContextConfigSetF ( ctx , OWPGetPF , ( OWPFunc ) getpf ) ) { I2ErrLog ( eh , " " ) ; exit ( 1 ) ; } } else { free ( pctx -> opt . identity ) ; pctx -> opt . identity = NULL ; } } if ( pctx -> opt . authmode ) { char * s = ping_ctx . opt . authmode ; pctx -> auth_mode = 0 ; while ( * s != ' \0 ' ) { switch ( toupper ( * s ) ) { case ' ' : pctx -> auth_mode |= OWP_MODE_OPEN ; break ; case ' ' : pctx -> auth_mode |= OWP_MODE_AUTHENTICATED ; break ; case ' ' : pctx -> auth_mode |= OWP_MODE_ENCRYPTED ; break ; #ifdef TWAMP case ' ' : pctx -> auth_mode |= TWP_MODE_MIXED ; break ; #endif default : I2ErrLogP ( eh , EINVAL , " " , * s ) ; usage ( progname , NULL ) ; exit ( 1 ) ; } s ++ ; } } else { if ( pctx -> opt . identity ) { pctx -> auth_mode = NWP_DEFAULT_OFFERED_MODE ; } else { pctx -> auth_mode = OWP_MODE_OPEN ; } } }
Initialize authentication and policy data (used by owping and owfetch)
Initialize authentication and policy data ( used by owping and owfetch )
/*
         * If pffile specified, attempt to get key from there.
         */ /* pffile */ /*
             * Do passphrase:
             *     open tty and get passphrase.
             */ /* copy passphrase */ /*
             * install getpf func (pf is in pfbuff)
             */ /*
     * Verify/decode auth options.
     */ /*
         * Default to all modes if identity set.
         */