Path: blob/main/crypto/krb5/src/util/ss/invocation.c
34907 views
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */1/*2* Copyright 2007 Massachusetts Institute of Technology.3* All Rights Reserved.4*5* Export of this software from the United States of America may6* require a specific license from the United States Government.7* It is the responsibility of any person or organization contemplating8* export to obtain such a license before exporting.9*10* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and11* distribute this software and its documentation for any purpose and12* without fee is hereby granted, provided that the above copyright13* notice appear in all copies and that both that copyright notice and14* this permission notice appear in supporting documentation, and that15* the name of M.I.T. not be used in advertising or publicity pertaining16* to distribution of the software without specific, written prior17* permission. Furthermore if you modify this software you must label18* your software as modified software and not distribute it in such a19* fashion that it might be confused with the original M.I.T. software.20* M.I.T. makes no representations about the suitability of21* this software for any purpose. It is provided "as is" without express22* or implied warranty.23*/24/*25* Copyright 1987, 1988 by MIT Student Information Processing Board26*27* For copyright information, see copyright.h.28*/29#include "ss_internal.h"30#include "copyright.h"31#define size sizeof(ss_data *)3233/* XXX The memory in _ss_table never gets freed up until program exit!34If you change the code to free it and stick a null pointer into35_ss_table[sci_idx], make sure you change the allocation routine to36not assume there are no null pointers in the middle of the37array. */38int39ss_create_invocation(char *subsystem_name, char *version_string,40char *info_ptr, ss_request_table *request_table_ptr,41int *code_ptr)42{43int sci_idx;44ss_data *new_table;45ss_data **table, **tmp;4647*code_ptr = 0;48table = _ss_table;49new_table = (ss_data *) malloc(sizeof(ss_data));50if (new_table == NULL) {51*code_ptr = errno;52return -1;53}5455if (table == (ss_data **) NULL) {56table = (ss_data **) malloc(2 * size);57if (table == NULL) {58*code_ptr = errno;59return -1;60}61table[0] = table[1] = (ss_data *)NULL;62_ss_table = table;63}64initialize_ss_error_table ();6566for (sci_idx = 1; table[sci_idx] != (ss_data *)NULL; sci_idx++)67;68tmp = (ss_data **) realloc((char *)table,69((unsigned)sci_idx+2)*size);70if (tmp == NULL) {71*code_ptr = errno;72return 0;73}74_ss_table = table = tmp;75table[sci_idx+1] = (ss_data *) NULL;76table[sci_idx] = NULL;7778new_table->subsystem_name = subsystem_name;79new_table->subsystem_version = version_string;80new_table->argv = (char **)NULL;81new_table->current_request = (char *)NULL;82new_table->info_dirs = (char **)malloc(sizeof(char *));83if (new_table->info_dirs == NULL) {84*code_ptr = errno;85free(new_table);86return 0;87}88*new_table->info_dirs = (char *)NULL;89new_table->info_ptr = info_ptr;90if (asprintf(&new_table->prompt, "%s: ", subsystem_name) < 0) {91*code_ptr = errno;92free(new_table->info_dirs);93free(new_table);94return 0;95}96new_table->abbrev_info = NULL;97new_table->flags.escape_disabled = 0;98new_table->flags.abbrevs_disabled = 0;99new_table->rqt_tables =100(ss_request_table **) calloc(2, sizeof(ss_request_table *));101if (new_table->rqt_tables == NULL) {102*code_ptr = errno;103free(new_table->prompt);104free(new_table->info_dirs);105free(new_table);106return 0;107}108*(new_table->rqt_tables) = request_table_ptr;109*(new_table->rqt_tables+1) = (ss_request_table *) NULL;110table[sci_idx] = new_table;111return(sci_idx);112}113114void115ss_delete_invocation(int sci_idx)116{117ss_data *t;118int ignored_code;119120t = ss_info(sci_idx);121free(t->prompt);122free(t->rqt_tables);123while(t->info_dirs[0] != (char *)NULL)124ss_delete_info_dir(sci_idx, t->info_dirs[0], &ignored_code);125free(t->info_dirs);126free(t);127}128129130