Annotation of 43BSDReno/sys/nfs/TEST/billboard/src/billboard_util.c, revision 1.1

1.1     ! root        1: /*
        !             2:  ******************************************************************************
        !             3:  *
        !             4:  * Module: billboard_util.c
        !             5:  *
        !             6:  * Description: billboard_util.c
        !             7:  *             Routines that handle the works for each feature.
        !             8:  *
        !             9:  * Functions:
        !            10:  *     bb_call_set_unset(flag, bb_set_in_p)
        !            11:  *     bb_set_unset_print_result(flag, bb_set_in_p, bb_set_out_p)
        !            12:  *     bb_list(flag, bb_list_in_p)
        !            13:  *     bb_list_print_result(flag, bb_list_in_p, bb_list_out_p)
        !            14:  *     bb_change_passwd(bb_passwd_in_p)
        !            15:  *     bb_print_vendor_info(bb_vendor_p)
        !            16:  *
        !            17:  * Notes:
        !            18:  *
        !            19:  ******************************************************************************
        !            20:  */
        !            21: /*
        !            22:  ******************************************************************************
        !            23:  * Include Files
        !            24:  ******************************************************************************
        !            25:  */
        !            26: #include <stdio.h>
        !            27: #include <rpc/rpc.h>
        !            28: #include "common.h"
        !            29: #include "protocol.h"
        !            30: 
        !            31: /*
        !            32:  ******************************************************************************
        !            33:  * Module Local Definitions
        !            34:  ******************************************************************************
        !            35:  */
        !            36: 
        !            37: /* 
        !            38:  * local copy of password, saved for interactive use of the tool
        !            39:  * i.e. the password entered when in interactive mode will be used for the
        !            40:  *      rest of the interactive session
        !            41:  */
        !            42: static BB_passwd       _pwbuff;
        !            43: 
        !            44: /*
        !            45:  ******************************************************************************
        !            46:  * External Declarations
        !            47:  ******************************************************************************
        !            48:  */
        !            49: extern CLIENT  *client_handle_p;
        !            50: extern char    server_name[];
        !            51: extern char    *_bb_salt;
        !            52: 
        !            53: 
        !            54: /*
        !            55:  ******************************************************************************
        !            56:  * Function Declarations
        !            57:  ******************************************************************************
        !            58:  */
        !            59: void bb_set_unset();
        !            60: void bb_lists();
        !            61: void bb_list_print_result();
        !            62: void bb_set_unset_print_result();
        !            63: void bb_change_passwd();
        !            64: void bb_print_vendor_info();
        !            65: 
        !            66: 
        !            67: /*
        !            68:  ******************************************************************************
        !            69:  *
        !            70:  * Function: bb_call_set_unset
        !            71:  *
        !            72:  * Description: handles the operation to set test failed/passed
        !            73:  *             The user request will be sent to the server via RPC,
        !            74:  *             if password is needed, the user will be prompted for one and
        !            75:  *             the request will be re-sent. 
        !            76:  *
        !            77:  * Input: 
        !            78:  *     flag -- BB_SET or BB_UNSET
        !            79:  *     bb_set_in_p -- input bb_set_in structure to RPC call
        !            80:  *
        !            81:  * Output:
        !            82:  *
        !            83:  * Returns:
        !            84:  *
        !            85:  * Side Effects:
        !            86:  *
        !            87:  * Notes:
        !            88:  *
        !            89:  ******************************************************************************
        !            90:  */
        !            91: void
        !            92: bb_call_set_unset(flag, bb_set_in_p)
        !            93: int            flag;
        !            94: BB_set_in      *bb_set_in_p;
        !            95: {
        !            96: BB_set_out     *bb_set_out_p;
        !            97: 
        !            98:        /* 
        !            99:         * initialise the passowrd buffer, and copy exisiting password if 
        !           100:         * exists
        !           101:         */
        !           102:        memset(bb_set_in_p->passwd, NUL, BB_PASSWD_LEN);
        !           103:        strncpy(bb_set_in_p->passwd, _pwbuff, BB_PASSWD_LEN-1);
        !           104: 
        !           105:        /*
        !           106:         * issue the RPC call
        !           107:         */
        !           108:        if (flag == BB_SET)
        !           109:                bb_set_out_p= (BB_set_out *) bb_call_rpc(bb_set_1, bb_set_in_p);
        !           110:        else if (flag == BB_UNSET)
        !           111:                bb_set_out_p= (BB_set_out *) bb_call_rpc(bb_unset_1, 
        !           112:                                                        bb_set_in_p);
        !           113:        else
        !           114:                return;
        !           115: 
        !           116:        /*
        !           117:         * if NULL is returned, RPC call failed.
        !           118:         */
        !           119:        if (bb_set_out_p == NULL) {
        !           120:                clnt_perror(client_handle_p, server_name);
        !           121:                return;
        !           122:        }
        !           123: 
        !           124:        /*
        !           125:         * If password is requested, the user is prompted for one and
        !           126:         * the request is re-sent
        !           127:         */
        !           128:        if (bb_set_out_p->status == BB_BAD_PASSWD) {
        !           129:                /*
        !           130:                 * gets password
        !           131:                 */
        !           132:                memset(bb_set_in_p->passwd, NUL, BB_PASSWD_LEN);
        !           133:                strncpy(bb_set_in_p->passwd, 
        !           134:                        crypt(getpass("Password:"), _bb_salt), BB_PASSWD_LEN-1);
        !           135:                /*
        !           136:                 * save the password to be re-used if the tool is in
        !           137:                 * interactive mode
        !           138:                 */
        !           139:                strncpy(_pwbuff, bb_set_in_p->passwd, BB_PASSWD_LEN);
        !           140:                if (flag == BB_SET)
        !           141:                        bb_set_out_p= (BB_set_out *) bb_call_rpc(bb_set_1, 
        !           142:                                        bb_set_in_p);
        !           143:                else
        !           144:                        bb_set_out_p= (BB_set_out *) bb_call_rpc(bb_unset_1, 
        !           145:                                        bb_set_in_p);
        !           146: 
        !           147:                if (bb_set_out_p == NULL) {
        !           148:                        clnt_perror(client_handle_p, server_name);
        !           149:                        return;
        !           150:                }
        !           151: 
        !           152:                bb_set_unset_print_result(flag, bb_set_in_p, bb_set_out_p);
        !           153:        } else 
        !           154:                bb_set_unset_print_result(flag, bb_set_in_p, bb_set_out_p);
        !           155: 
        !           156:        return;
        !           157: }
        !           158: 
        !           159: 
        !           160: /*
        !           161:  ******************************************************************************
        !           162:  *
        !           163:  * Function: bb_set_unset_print_result
        !           164:  *
        !           165:  * Description: print the result of RPC call for set unset of tests
        !           166:  *
        !           167:  * Input:
        !           168:  *     flag: BB_SET or BB_UNSET
        !           169:  *     bb_set_in_p: input bb_set_in structure to RPC call
        !           170:  *     bb_set_out_p: RPC returned bb_set_out structure
        !           171:  *
        !           172:  * Output:
        !           173:  *     Output goes to stdout, error goes to stderr.
        !           174:  *
        !           175:  * Returns:
        !           176:  *
        !           177:  * Side Effects:
        !           178:  *
        !           179:  * Notes:
        !           180:  *
        !           181:  ******************************************************************************
        !           182:  */
        !           183: void
        !           184: bb_set_unset_print_result(flag, bb_set_in_p, bb_set_out_p)
        !           185: int            flag;
        !           186: BB_set_in      *bb_set_in_p;
        !           187: BB_set_out     *bb_set_out_p;
        !           188: {
        !           189: 
        !           190:        printf("\n");
        !           191:        switch (bb_set_out_p->status) {
        !           192:        case    BB_SUCCESS:
        !           193:                                if (flag == BB_SET)
        !           194:                                        printf("The following client and server implementation is tested succesfully:\n");
        !           195:                                else
        !           196:                                        printf("The following client and server implementation is set as being untested:\n");
        !           197:                                printf("Client:\n");
        !           198:                                bb_print_vendor_info(&bb_set_out_p->client);    
        !           199:                                printf("Server:\n");
        !           200:                                bb_print_vendor_info(&bb_set_out_p->server);    
        !           201:                                break;
        !           202:        case    BB_FAILURE:
        !           203:                                fprintf(stderr, "Operation failed\.n");
        !           204:                                break;
        !           205:        case    BB_BAD_CLIENT:
        !           206:                                fprintf(stderr, "Bad client identifier: %s.\n",
        !           207:                                        bb_set_in_p->client);
        !           208:                                break;
        !           209:        case    BB_BAD_SERVER:
        !           210:                                fprintf(stderr, "Bad server identifier: %s.\n",
        !           211:                                        bb_set_in_p->server);
        !           212:                                break;
        !           213:        case    BB_ALREADY_SET:
        !           214:                                fprintf(stderr, 
        !           215:                "Client %s against server %s has already been set as tested.\n",
        !           216:                                bb_set_in_p->client, bb_set_in_p->server);
        !           217:                                break;
        !           218:        case    BB_ALREADY_UNSET:
        !           219:                                fprintf(stderr, 
        !           220:                "Client %s against server %s has already been set as untested.\n",
        !           221:                                bb_set_in_p->client, bb_set_in_p->server);
        !           222:                                break;
        !           223: 
        !           224:        case    BB_BAD_PASSWD:
        !           225:                                fprintf(stderr, "Bad password.\n");
        !           226:                                break;
        !           227: 
        !           228:        case    BB_BAD_PHASE:
        !           229:                                fprintf(stderr, "You have to complete testing against a Sun server before proceeding.\n");
        !           230:                                break;
        !           231: 
        !           232:        default:
        !           233:                                fprintf(stderr, "Unexpected error code %d.\n",
        !           234:                                        bb_set_out_p->status);
        !           235:                                break;
        !           236:        }
        !           237: 
        !           238:        return;
        !           239: }
        !           240: 
        !           241: /*
        !           242:  ******************************************************************************
        !           243:  *
        !           244:  * Function: bb_list
        !           245:  *
        !           246:  * Description: calls the RPC procedure, and prompted for password if needed.
        !           247:  *
        !           248:  * Input: 
        !           249:  *     bb_list_in_p -- input bb_list_in structure to RPC call
        !           250:  *
        !           251:  * Output:
        !           252:  *
        !           253:  * Returns:
        !           254:  *
        !           255:  * Side Effects:
        !           256:  *
        !           257:  * Notes:
        !           258:  *
        !           259:  ******************************************************************************
        !           260:  */
        !           261: void
        !           262: bb_list(flag, bb_list_in_p)
        !           263: int    flag;
        !           264: BB_list_in     *bb_list_in_p;
        !           265: {
        !           266: BB_list_out    *(*func)();
        !           267: BB_list_out    *bb_list_out_p;
        !           268: 
        !           269:        /*
        !           270:         * set the RPC procedure
        !           271:         */
        !           272:        switch  (flag) {
        !           273:        case    BB_ALIST:
        !           274:                                func= bb_alist_1;
        !           275:                                break;
        !           276:        case    BB_BLIST:
        !           277:                                func= bb_blist_1;
        !           278:                                break;
        !           279:        case    BB_CLIST:
        !           280:                                func= bb_clist_1;
        !           281:                                break;
        !           282:        case    BB_DLIST:
        !           283:                                func= bb_dlist_1;
        !           284:                                break;
        !           285:        default:
        !           286:                                return;
        !           287:        }
        !           288: 
        !           289:        /*
        !           290:         * initialise the password buffer, and copy existing one if exists
        !           291:         */
        !           292:        memset(bb_list_in_p->passwd, NUL, BB_PASSWD_LEN);
        !           293:        strncpy(bb_list_in_p->passwd, _pwbuff, BB_PASSWD_LEN-1);
        !           294: 
        !           295:        bb_list_out_p= (BB_list_out *) bb_call_rpc(func, bb_list_in_p);
        !           296:        if (bb_list_out_p == NULL) {
        !           297:                clnt_perror(client_handle_p, server_name);
        !           298:                return;
        !           299:        }
        !           300: 
        !           301:        if (bb_list_out_p->status == BB_BAD_PASSWD) {
        !           302:                /*
        !           303:                 * password is needed, so get one
        !           304:                 */
        !           305:                memset(bb_list_in_p->passwd, NUL, BB_PASSWD_LEN);
        !           306:                strncpy(bb_list_in_p->passwd, 
        !           307:                        crypt(getpass("Password:"), _bb_salt), BB_PASSWD_LEN-1);
        !           308:                /*
        !           309:                 * save the password to be re-used if the tool is in
        !           310:                 * interactive mode
        !           311:                 */
        !           312:                strncpy(_pwbuff, bb_list_in_p->passwd, BB_PASSWD_LEN);
        !           313: 
        !           314:                /* 
        !           315:                 * issue the RPC call 
        !           316:                 */
        !           317:                bb_list_out_p= (BB_list_out *) bb_call_rpc(func, bb_list_in_p);
        !           318:                if (bb_list_out_p == NULL) {
        !           319:                        clnt_perror(client_handle_p, server_name);
        !           320:                        return;
        !           321:                }
        !           322:                bb_list_print_result(flag, bb_list_in_p, bb_list_out_p);
        !           323:        } else 
        !           324:                bb_list_print_result(flag, bb_list_in_p, bb_list_out_p);
        !           325: 
        !           326:        return;
        !           327: }
        !           328: 
        !           329: /*
        !           330:  ******************************************************************************
        !           331:  *
        !           332:  * Function: bb_list_print_result
        !           333:  *
        !           334:  * Description: print result of RPC call to get list of clients or servers.
        !           335:  *
        !           336:  * Input:
        !           337:  *     flag -- BB_ALIST, BB_BLIST, BB_CLIST or BB_DLIST
        !           338:  *     bb_list_in_p -- input bb_list_in structure to RPC call
        !           339:  *     bb_list_out_p -- RPC returned bb_list_out structure
        !           340:  *
        !           341:  * Output:
        !           342:  *     Output goes to stdout, error goes to stderr.
        !           343:  *
        !           344:  * Returns:
        !           345:  *
        !           346:  * Side Effects:
        !           347:  *
        !           348:  * Notes:
        !           349:  *
        !           350:  ******************************************************************************
        !           351:  */
        !           352: void
        !           353: bb_list_print_result(flag, bb_list_in_p, bb_list_out_p)
        !           354: int            flag;
        !           355: BB_list_in     *bb_list_in_p;
        !           356: BB_list_out    *bb_list_out_p;
        !           357: {
        !           358: int    i;
        !           359: int    data_len;
        !           360: register BB_vendor     *vendor_p;
        !           361: 
        !           362:        printf("\n");
        !           363:        switch (bb_list_out_p->status) {
        !           364:        case    BB_SUCCESS:
        !           365: 
        !           366:                                if ((data_len= bb_list_out_p->data.data_len) 
        !           367:                                        > 0) {
        !           368:                                        switch (flag) {
        !           369:                                        case BB_ALIST:
        !           370:        printf("List of servers successfully tested against client %s:\n", 
        !           371:                bb_list_in_p->id);
        !           372:                                                        break;
        !           373:                                        case BB_BLIST:
        !           374:        printf("List of servers not tested against client %s:\n", 
        !           375:                bb_list_in_p->id);
        !           376:                                                        break;
        !           377:                                        case BB_CLIST:
        !           378:        printf("List of clients successfully tested against server %s:\n", 
        !           379:                bb_list_in_p->id);
        !           380:                                                        break;
        !           381:                                        case BB_DLIST:
        !           382:        printf("List of clients not tested against server %s:\n", 
        !           383:                bb_list_in_p->id);
        !           384:                                                        break;
        !           385:                                        }
        !           386:                                        vendor_p= bb_list_out_p->data.data_val;
        !           387: 
        !           388:                                        for (i= 0; i < data_len; i++) {
        !           389:                                                printf("%d)\n", i+1);
        !           390:                                                bb_print_vendor_info(&vendor_p[i]);
        !           391:                                        }
        !           392:                                } else {
        !           393:                                        switch (flag) {
        !           394:                                        case BB_ALIST:
        !           395:        printf("No servers successfully tested against client %s.\n", 
        !           396:                bb_list_in_p->id);
        !           397:                                                        break;
        !           398:                                        case BB_BLIST:
        !           399:        printf("All servers are successfully tested against client %s.\n", 
        !           400:                bb_list_in_p->id);
        !           401:                                                        break;
        !           402:                                        case BB_CLIST:
        !           403:        printf("No clients successfully tested against server %s.\n", 
        !           404:                bb_list_in_p->id);
        !           405:                                                        break;
        !           406:                                        case BB_DLIST:
        !           407:        printf("All clients are successfully tested against server %s.\n", 
        !           408:                bb_list_in_p->id);
        !           409:                                                        break;
        !           410:                                        }
        !           411:                                }
        !           412:                                break;
        !           413:        case    BB_FAILURE:
        !           414:                                fprintf(stderr, "Operation failed.\n");
        !           415:                                break;
        !           416:        case    BB_BAD_CLIENT:
        !           417:                                fprintf(stderr, "Bad client identifier: %s.\n",
        !           418:                                        bb_list_in_p->id);
        !           419:                                break;
        !           420:        case    BB_BAD_SERVER:
        !           421:                                fprintf(stderr, "Bad server identifier: %s.\n",
        !           422:                                        bb_list_in_p->id);
        !           423:                                break;
        !           424:        case    BB_BAD_PASSWD:
        !           425:                                fprintf(stderr, "Bad password.\n");
        !           426:                                break;
        !           427: 
        !           428:        default:
        !           429:                                fprintf(stderr, "Unknown error code %d.\n",
        !           430:                                        bb_list_out_p->status);
        !           431:                                break;
        !           432:        }
        !           433: 
        !           434:        return;
        !           435: }
        !           436: 
        !           437: 
        !           438: /*
        !           439:  ******************************************************************************
        !           440:  *
        !           441:  * Function: bb_change_passwd
        !           442:  *
        !           443:  * Description: handles RPC call to change the password.  Make the RPC call
        !           444:  *             and prints the status.
        !           445:  *
        !           446:  * Input: 
        !           447:  *     bb_passwd_in_p -- input bb_passwd_in structure to RPC call
        !           448:  *
        !           449:  * Output:
        !           450:  *     Output goes to stdout, error goes to stderr.
        !           451:  *
        !           452:  * Returns:
        !           453:  *
        !           454:  * Side Effects:
        !           455:  *
        !           456:  * Notes:
        !           457:  *
        !           458:  ******************************************************************************
        !           459:  */
        !           460: void
        !           461: bb_change_passwd(bb_passwd_in_p)
        !           462: BB_passwd_in   *bb_passwd_in_p;
        !           463: {
        !           464: int    *status_p;
        !           465: 
        !           466:        /*
        !           467:         * issue the RPC call
        !           468:         */
        !           469:        if ((status_p= (int *)bb_call_rpc(bb_passwd_set_1, bb_passwd_in_p)) 
        !           470:                != NULL) {
        !           471:                printf("\n");
        !           472:                switch (*status_p) {
        !           473:                case    BB_SUCCESS:
        !           474:                                printf("Password changed\n");
        !           475:                                break;
        !           476:                case    BB_FAILURE:
        !           477:                                fprintf(stderr, "Operation failed.\n");
        !           478:                                break;
        !           479:                case    BB_BAD_CLIENT:
        !           480:                                fprintf(stderr, "Bad client identifier: %s.\n",
        !           481:                                        bb_passwd_in_p->client);
        !           482:                                break;
        !           483:                case    BB_BAD_PASSWD:
        !           484:                                fprintf(stderr, "Bad password.\n");
        !           485:                                break;
        !           486:                default:
        !           487:                                fprintf(stderr, "Unexpected error code %d.\n",
        !           488:                                        *status_p);
        !           489:                                break;
        !           490:                }
        !           491:        } else
        !           492:                clnt_perror(client_handle_p, server_name);
        !           493: 
        !           494:        return;
        !           495: }
        !           496: 
        !           497: /*
        !           498:  ******************************************************************************
        !           499:  *
        !           500:  * Function: bb_print_vendor_info
        !           501:  *
        !           502:  * Description: print vendor information from returned RPC call
        !           503:  *
        !           504:  * Input:
        !           505:  *     bb_vendor_p -- vendor info
        !           506:  *
        !           507:  * Output:
        !           508:  *     prints vendor info on stdout
        !           509:  *
        !           510:  * Returns:
        !           511:  *
        !           512:  * Side Effects:
        !           513:  *
        !           514:  * Notes:
        !           515:  *
        !           516:  ******************************************************************************
        !           517:  */
        !           518: void
        !           519: bb_print_vendor_info(bb_vendor_p)
        !           520: BB_vendor      *bb_vendor_p;
        !           521: {
        !           522:        printf("\tBooth: %d\n", bb_vendor_p->booth);
        !           523:        printf("\tCompany: %s\n", bb_vendor_p->company);
        !           524:        printf("\tImplementation: %s\n", bb_vendor_p->imp);
        !           525:        printf("\tIdentifier: %s\n\n", bb_vendor_p->id);
        !           526: 
        !           527:        return;
        !           528: }
        !           529: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.