|
|
1.1 ! root 1: /* ! 2: ****************************************************************************** ! 3: * ! 4: * Module: billboard.c ! 5: * ! 6: * Description: billboard.c ! 7: * Billboard is an RPC program that handles information about ! 8: * testsuites completions. The module here is the user program ! 9: * that communicates with the billboard server. This program ! 10: * allows user to update and modify information maintained ! 11: * by the server. The features supported are (described below ! 12: * using the command line options): ! 13: * i) -s <client identifier> <server identifier> ! 14: * to set test between <client identifier> and ! 15: * <server identifier> as successfully tested ! 16: * ii) -u <client identifier> <server identifier> ! 17: * to set test between <client identifier> and ! 18: * <server identifier> as NOT successfully tested ! 19: * iii) -a <client identifier> ! 20: * to list server implementations that are successfully ! 21: * tested against client <client identifier> ! 22: * iv) -b <client identifier> ! 23: * to list server implementations that are NOT ! 24: * successfully tested against client <client identifier> ! 25: * v) -c <server identifier> ! 26: * to list client implementations that are successfully ! 27: * tested against server <server identifier> ! 28: * vi) -d <server identifier> ! 29: * to list client implementations that are NOT ! 30: * successfully tested against server <server identifier> ! 31: * vii) -p <identifier> ! 32: * to change the password of the <identifier> ! 33: * implementation ! 34: * ! 35: * where <client identifier> and <server identifier> is ! 36: * identifier of the client and server implementation ! 37: * respectively. ! 38: * ! 39: * This user program also supports interactive interface whereby ! 40: * the user is presented with a list of options (same as the ! 41: * features described above) to choose from. User will be prompted ! 42: * for any additional data. ! 43: * ! 44: * Functions: ! 45: * main(argc, argv) ! 46: * _cmd_line_option(argc, argv) ! 47: * _interactive_option() ! 48: * _bb_get_passwd(bb_passwd_in_p) ! 49: * ! 50: * ! 51: ****************************************************************************** ! 52: */ ! 53: ! 54: /* ! 55: ****************************************************************************** ! 56: * Include Files ! 57: ****************************************************************************** ! 58: */ ! 59: #include <stdio.h> ! 60: #include "common.h" ! 61: #include "protocol.h" ! 62: ! 63: ! 64: /* ! 65: ****************************************************************************** ! 66: * Manifest Constants ! 67: ****************************************************************************** ! 68: */ ! 69: #define _CONTROL_STR_SIZE 5 /* sscanf control string size */ ! 70: ! 71: /* ! 72: ****************************************************************************** ! 73: * Macro Definitions ! 74: ****************************************************************************** ! 75: */ ! 76: /* print error messages */ ! 77: #define PRINT_ERROR() { fprintf(stderr, _Usage, argv[0]);\ ! 78: return(1); \ ! 79: } ! 80: ! 81: ! 82: /* ! 83: ****************************************************************************** ! 84: * Module Local Definitions ! 85: ****************************************************************************** ! 86: */ ! 87: /* usage message */ ! 88: char *_Usage= ! 89: "Usage: %s [-s|-u client_idenitfier server_identifier]\n\ ! 90: [-a|-b client_idenitfier]\n\ ! 91: [-c|-d server_identifier]\n\ ! 92: [-p identifier]\n"; ! 93: ! 94: /* ! 95: *randomly picked salt key for password encryption ! 96: * This may be modified if other algorithm is preferred ! 97: */ ! 98: char *_bb_salt= "kR"; ! 99: ! 100: /* ! 101: ****************************************************************************** ! 102: * External Declarations ! 103: ****************************************************************************** ! 104: */ ! 105: extern char *optarg; ! 106: extern int optind; ! 107: ! 108: ! 109: /* ! 110: ****************************************************************************** ! 111: * Function Declarations ! 112: ****************************************************************************** ! 113: */ ! 114: int main(); ! 115: static int _cmd_line_option(); ! 116: static void _interactive_option(); ! 117: static int _bb_get_passwd(); ! 118: ! 119: ! 120: /* ! 121: ****************************************************************************** ! 122: * ! 123: * Function: main ! 124: * ! 125: * Description: ! 126: * Invokes modules to handle command line interface or ! 127: * interactive according to the user invocation. ! 128: * ! 129: * Input: ! 130: * argc ! 131: * argv ! 132: * ! 133: * Output: ! 134: * Output goes to stdout, error goes to stderr. ! 135: * ! 136: * Returns: ! 137: * 1 -- operation failed ! 138: * 0 -- operation succeeded. ! 139: * ! 140: * Side Effects: ! 141: * ! 142: * Notes: ! 143: * ! 144: ****************************************************************************** ! 145: */ ! 146: int ! 147: main(argc, argv) ! 148: int argc; ! 149: char *argv[]; ! 150: { ! 151: if (argc > 1) ! 152: return(_cmd_line_option(argc, argv)); ! 153: else ! 154: _interactive_option(); ! 155: ! 156: exit(0); ! 157: } ! 158: ! 159: /* ! 160: ****************************************************************************** ! 161: * ! 162: * Function: _cmd_line_option ! 163: * ! 164: * Description: ! 165: * Parses command line input and perform the requested ! 166: * operation accordingly. ! 167: * ! 168: * Input: ! 169: * argc ! 170: * argv ! 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: static int ! 184: _cmd_line_option(argc, argv) ! 185: int argc; ! 186: char *argv[]; ! 187: { ! 188: int option; ! 189: BB_set_in bb_set_in; ! 190: BB_list_in bb_list_in; ! 191: BB_passwd_in bb_passwd_in; ! 192: ! 193: /* initialise termination of string buffers */ ! 194: bb_set_in.client[BB_ID_NAME_LEN-1]= bb_set_in.server[BB_ID_NAME_LEN-1] ! 195: = '\0'; ! 196: bb_list_in.id[BB_ID_NAME_LEN-1]= '\0'; ! 197: ! 198: /* ! 199: * parses the command line input, and make the remote procedure call ! 200: */ ! 201: if ((option= getopt(argc, argv, "s:u:a:b:c:d:p:")) != -1) { ! 202: switch (option) { ! 203: /* ! 204: * gets client and server identifier and ! 205: * calls bb_call_set_unset to handle the ! 206: * remote procedure call ! 207: */ ! 208: case 's': strncpy(bb_set_in.client, optarg, ! 209: BB_ID_NAME_LEN-1); ! 210: strncpy(bb_set_in.server, argv[optind], ! 211: BB_ID_NAME_LEN-1); ! 212: bb_call_set_unset(BB_SET, &bb_set_in); ! 213: break; ! 214: ! 215: case 'u': strncpy(bb_set_in.client, optarg, ! 216: BB_ID_NAME_LEN-1); ! 217: strncpy(bb_set_in.server, argv[optind], ! 218: BB_ID_NAME_LEN-1); ! 219: bb_call_set_unset(BB_UNSET, &bb_set_in); ! 220: break; ! 221: ! 222: /* ! 223: * gets client or server identifier and ! 224: * calls bb_list to handle the remote procedure ! 225: * call ! 226: */ ! 227: case 'a': strncpy(bb_list_in.id, optarg, ! 228: BB_ID_NAME_LEN-1); ! 229: bb_list(BB_ALIST, &bb_list_in); ! 230: break; ! 231: ! 232: case 'b': strncpy(bb_list_in.id, optarg, ! 233: BB_ID_NAME_LEN-1); ! 234: bb_list(BB_BLIST, &bb_list_in); ! 235: break; ! 236: ! 237: case 'c': strncpy(bb_list_in.id, optarg, ! 238: BB_ID_NAME_LEN-1); ! 239: bb_list(BB_CLIST, &bb_list_in); ! 240: break; ! 241: ! 242: case 'd': strncpy(bb_list_in.id, optarg, ! 243: BB_ID_NAME_LEN-1); ! 244: bb_list(BB_DLIST, &bb_list_in); ! 245: break; ! 246: ! 247: /* to change password */ ! 248: case 'p': ! 249: strncpy(bb_passwd_in.client, optarg, ! 250: BB_ID_NAME_LEN-1); ! 251: if (_bb_get_passwd(&bb_passwd_in) == TRUE) ! 252: bb_change_passwd(&bb_passwd_in); ! 253: break; ! 254: ! 255: case '?': PRINT_ERROR(); ! 256: } ! 257: ! 258: } else ! 259: PRINT_ERROR(); ! 260: ! 261: return(0); ! 262: } ! 263: ! 264: /* ! 265: ****************************************************************************** ! 266: * ! 267: * Function: _interactive_option ! 268: * ! 269: * Description: ! 270: * Handles the interactive interface. Promt user for inforamtion and ! 271: * performs the operation selected by the user. ! 272: * ! 273: * Input: ! 274: * ! 275: * Output: ! 276: * Output goes to stdout, error goes to stderr. ! 277: * ! 278: * Returns: ! 279: * ! 280: * Side Effects: ! 281: * ! 282: * Notes: ! 283: * ! 284: ****************************************************************************** ! 285: */ ! 286: static void ! 287: _interactive_option() ! 288: { ! 289: int option= 0; ! 290: BB_id client_id; ! 291: BB_id server_id; ! 292: char buffer[BB_MAX_LINE_LEN]; ! 293: char control_str[_CONTROL_STR_SIZE]; ! 294: ! 295: BB_set_in bb_set_in; ! 296: BB_list_in bb_list_in; ! 297: BB_passwd_in bb_passwd_in; ! 298: ! 299: /* terminate the string buffers */ ! 300: bb_set_in.client[BB_ID_NAME_LEN-1]= bb_set_in.server[BB_ID_NAME_LEN-1] ! 301: = '\0'; ! 302: bb_list_in.id[BB_ID_NAME_LEN-1]= '\0'; ! 303: ! 304: sprintf(control_str, "%%%ds", BB_ID_NAME_LEN-1); ! 305: ! 306: /* ! 307: * requests for user input, and call the remote procedure to ! 308: * handle the operation ! 309: */ ! 310: for (;;) { ! 311: /* print user interface options */ ! 312: printf("\n\ ! 313: Options:\n\ ! 314: -------:\n\ ! 315: 1) set test passed\n\ ! 316: 2) set test failed\n\ ! 317: 3) list servers successfully tested against\n\ ! 318: 4) list servers not tested against\n\ ! 319: 5) list clients successfully tested against\n\ ! 320: 6) list clients not tested against\n\ ! 321: 7) set/change password\n\ ! 322: 8) exit\n\n"); ! 323: ! 324: printf("Enter option: "); ! 325: gets(buffer); ! 326: sscanf(buffer, "%d", &option); ! 327: switch (option) { ! 328: /* ! 329: * gets client and server identifier and ! 330: * calls bb_call_set_unset to handle the ! 331: * remote procedure call ! 332: */ ! 333: case 1: ! 334: printf("Client Identifier: "); ! 335: gets(buffer); ! 336: sscanf(buffer, control_str, bb_set_in.client); ! 337: printf("Server Identifier: "); ! 338: gets(buffer); ! 339: sscanf(buffer, control_str, bb_set_in.server); ! 340: bb_call_set_unset(BB_SET, &bb_set_in); ! 341: break; ! 342: ! 343: case 2: ! 344: printf("Client Identifier: "); ! 345: gets(buffer); ! 346: sscanf(buffer, control_str, bb_set_in.client); ! 347: printf("Server Identifier: "); ! 348: gets(buffer); ! 349: sscanf(buffer, control_str, bb_set_in.server); ! 350: bb_call_set_unset(BB_UNSET, &bb_set_in); ! 351: break; ! 352: ! 353: /* ! 354: * gets client or server identifier and ! 355: * calls bb_list to handle the remote procedure ! 356: * call ! 357: */ ! 358: case 3: ! 359: printf("Client Identifier: "); ! 360: gets(buffer); ! 361: sscanf(buffer, control_str, bb_list_in.id); ! 362: bb_list(BB_ALIST, &bb_list_in); ! 363: break; ! 364: ! 365: case 4: ! 366: printf("Client Identifier: "); ! 367: gets(buffer); ! 368: sscanf(buffer, control_str, bb_list_in.id); ! 369: bb_list(BB_BLIST, &bb_list_in); ! 370: break; ! 371: ! 372: case 5: ! 373: printf("Server Identifier: "); ! 374: gets(buffer); ! 375: sscanf(buffer, control_str, bb_list_in.id); ! 376: bb_list(BB_CLIST, &bb_list_in); ! 377: break; ! 378: ! 379: case 6: ! 380: printf("Server Identifier: "); ! 381: gets(buffer); ! 382: sscanf(buffer, control_str, bb_list_in.id); ! 383: bb_list(BB_DLIST, &bb_list_in); ! 384: break; ! 385: ! 386: /* to change password */ ! 387: case 7: ! 388: printf("Identifier: "); ! 389: gets(buffer); ! 390: sscanf(buffer, control_str, bb_passwd_in.client); ! 391: if (_bb_get_passwd(&bb_passwd_in) == TRUE) ! 392: bb_change_passwd(&bb_passwd_in); ! 393: break; ! 394: ! 395: case 8: return; ! 396: ! 397: default: ! 398: printf("invalid option\n\n"); ! 399: break; ! 400: } ! 401: } ! 402: } ! 403: ! 404: /* ! 405: ****************************************************************************** ! 406: * ! 407: * Function: _bb_get_passwd ! 408: * ! 409: * Description: ! 410: * Prompt for old and new passwords, and verifies the new one. ! 411: * Both passwords are then encrypted. ! 412: * We use Unix DES with fixed salt key for the password ! 413: * encryption for simplicity, you are welcome to use ! 414: * your own algorithms. ! 415: * ! 416: * Input: ! 417: * bb_passwd_in_p -- input structure to RPC call ! 418: * ! 419: * Output: ! 420: * ! 421: * Returns: ! 422: * ! 423: * Side Effects: ! 424: * ! 425: * Notes: ! 426: * ! 427: ****************************************************************************** ! 428: */ ! 429: static bool_t ! 430: _bb_get_passwd(bb_passwd_in_p) ! 431: BB_passwd_in *bb_passwd_in_p; ! 432: { ! 433: char buffer[BB_MAX_LINE_LEN]; ! 434: ! 435: /* initialised password buffers */ ! 436: memset(bb_passwd_in_p->old, NUL, BB_PASSWD_LEN); ! 437: memset(bb_passwd_in_p->new, NUL, BB_PASSWD_LEN); ! 438: memset(buffer, NUL, BB_MAX_LINE_LEN); ! 439: ! 440: /* ! 441: * get old and new password, and verify the new password ! 442: */ ! 443: strncpy(bb_passwd_in_p->old, crypt(getpass("Old password:"), _bb_salt), ! 444: BB_PASSWD_LEN-1); ! 445: strcpy(buffer, getpass("New password:")); ! 446: if (strcmp(buffer, getpass("Retype new password: ")) != 0) { ! 447: printf("Mismatch - password unchanged.\n"); ! 448: return(FALSE); ! 449: } else ! 450: strncpy(bb_passwd_in_p->new, crypt(buffer, _bb_salt), ! 451: BB_PASSWD_LEN-1); ! 452: return(TRUE); ! 453: } ! 454:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.