/* This routine maintains a list of strings preventing duplication. */
int ll_add_string(linked_list *list, char *string)
{
  ll_node *node;
  char *new_string;

  if (!ll_string_check(list, string))
    {
      node = ll_add_node(list, ll_tail);
      if (node)
	{
	  new_string = strdup(string);
	  if (new_string)
	    ll_add_data(node, new_string);
	  else
	    return LL_FAILURE;
	}
      else
	return LL_FAILURE;
    }
  return LL_SUCCESS;
}
Exemple #2
0
/* This routine maintains a list of strings preventing duplication. */
int ll_string(linked_list *list, ll_s_action action, char *string)
{
    int status = LL_SUCCESS;
    ll_node *cur_node;

    switch(action) {
      case ll_s_check:
	/* Scan the list until we find the string in question */
	for (cur_node = list->first; cur_node && (status == FALSE); 
	     cur_node = cur_node->next)
	    status = (strcmp(string, cur_node->data) == 0);
	break;
      case ll_s_add:
	/* Add a string to the list. */
	if (!ll_string(list, ll_s_check, string)) {
	    if ((cur_node = ll_add_node(list, ll_tail))) {
		char *new_string;
		if ((new_string = (char *)calloc(strlen(string) + 1, 
						sizeof(char)))) {
		    strcpy(new_string, string);
		    ll_add_data(cur_node, new_string);
		}
		else 
		    status = LL_FAILURE;
	    }
	    else
		status = LL_FAILURE;
	}
	break;
      default:
	/* This should never happen */
	status = LL_FAILURE;
	break;
    }

    return(status);
}
Exemple #3
0
void test_linked_lists()
{
    linked_list list;
    ll_create_list(&list);    

    for (int i = 0; i < 10; i++)
    {
        printf("Writing data. Size: %d\n", list->size);
        point *p = malloc(sizeof(point));
        p->x = 2 * i;
        p->y = 3 * i;
        printf("Size of list: %d\n", sizeof(list));
        list_node node;
        node.data = p;
        ll_add_node(&list, node, TAIL);
    }

    print_linkedlist(list, "\n", print_ll_node);
    printf("\n\n");
    
    point p1;
    p1.x = 100000;
    p1.y = 150000;

    // point p2;
    // p2.x = 20;
    // p2.y = 40;
    
    list_node node;    
    
    node.data = &p1;
    ll_add_node(&list, node, 5);
    // ll_add_node(&list, node, 20);

    ll_remove_node(&list, 1);

    print_linkedlist(list, "\n", print_ll_node);

    for (int i = 0; i < 10; i++)
    {
        ll_remove_node(&list, HEAD);
    }

    ll_remove_node(&list, HEAD);

    print_linkedlist(list, "\n", print_ll_node);

    // node.data = &p2;
    // ll_add_node(list, node);
    // ll_add_node(list, node);
    // ll_add_node(list, node);
    // ll_add_node(list, node);

    // list_node tmp = ll_get_node(list, 2);
    // list_node tmp = *(list->head);

    // void *data = tmp.data;    
    // point *p_tmp = (point *)data;
    // printf("%d %d\n", p_tmp->x, p_tmp->y);
    printf("Size: %d\n", list->size);

}
Exemple #4
0
int main(int argc, char *argv[])
{
    int status = AKLOG_SUCCESS;
    int i;
    int somethingswrong = FALSE;

    cellinfo_t cellinfo;

    extern char *progname;	/* Name of this program */

    extern int dflag;		/* Debug mode */

    int cmode = FALSE;		/* Cellname mode */
    int pmode = FALSE;		/* Path name mode */

    char realm[REALM_SZ];		/* Kerberos realm of afs server */
    char cell[BUFSIZ];		/* Cell to which we are authenticating */
    char path[MAXPATHLEN + 1];	/* Path length for path mode */

    linked_list cells;		/* List of cells to log to */
    linked_list paths;		/* List of paths to log to */
    ll_node *cur_node;

    memset(&cellinfo, 0, sizeof(cellinfo));

    memset(realm, 0, sizeof(realm));
    memset(cell, 0, sizeof(cell));
    memset(path, 0, sizeof(path));

    ll_init(&cells);
    ll_init(&paths);

    /* Store the program name here for error messages */
    if (progname = LastComponent(argv[0]))
        progname++;
    else
        progname = argv[0];

    /* Initialize list of cells to which we have authenticated */
    (void)ll_init(&authedcells);

    /* Parse commandline arguments and make list of what to do. */
    for (i = 1; i < argc; i++)
    {
        if (strcmp(argv[i], "-d") == 0)
            dflag++;
        else if (strcmp(argv[i], "-5") == 0)
            usev5++;
#ifdef HAVE_KRB4
        else if (strcmp(argv[i], "-m") == 0)
            use524++;
        else if (strcmp(argv[i], "-4") == 0)
            usev5 = 0;
#endif
        else if (strcmp(argv[i], "-noprdb") == 0)
            noprdb++;
        else if (strcmp(argv[i], "-force") == 0)
            force++;
        else if (((strcmp(argv[i], "-cell") == 0) ||
                   (strcmp(argv[i], "-c") == 0)) && !pmode)
        {       
            if (++i < argc)
            {
                cmode++;
                strcpy(cell, argv[i]);
            }
            else
                usage();
        }
        else if (((strcmp(argv[i], "-path") == 0) ||
                   (strcmp(argv[i], "-p") == 0)) && !cmode)
        {       
            if (++i < argc)
            {
                pmode++;
                strcpy(path, argv[i]);
            }
            else
                usage();
        }
        else if (argv[i][0] == '-')
            usage();
        else if (!pmode && !cmode)
        {
            if (FirstComponent(argv[i]) || (strcmp(argv[i], ".") == 0) ||
                 (strcmp(argv[i], "..") == 0))
            {
                pmode++;
                strcpy(path, argv[i]);
            }
            else
            {
                cmode++;
                strcpy(cell, argv[i]);
            }
        }
        else
            usage();

        if (cmode)
        {
            if (((i + 1) < argc) && (strcmp(argv[i + 1], "-k") == 0))
            {
                i += 2;
                if (i < argc)
                    strcpy(realm, argv[i]);
                else
                    usage();
            }
            /* Add this cell to list of cells */
            strcpy(cellinfo.cell, cell);
            strcpy(cellinfo.realm, realm);
            if (cur_node = ll_add_node(&cells, ll_tail))
            {
                char *new_cellinfo;
                if (new_cellinfo = copy_cellinfo(&cellinfo))
                    ll_add_data(cur_node, new_cellinfo);
                else
                {
                    fprintf(stderr, "%s: failure copying cellinfo.\n", progname);
                    akexit(AKLOG_MISC);
                }
            }
            else
            {
                fprintf(stderr, "%s: failure adding cell to cells list.\n",
                         progname);
                akexit(AKLOG_MISC);
            }
            memset(&cellinfo, 0, sizeof(cellinfo));
            cmode = FALSE;
            memset(cell, 0, sizeof(cell));
            memset(realm, 0, sizeof(realm));
        }
        else if (pmode)
        {
            /* Add this path to list of paths */
            if (cur_node = ll_add_node(&paths, ll_tail))
            {
                char *new_path;
                if (new_path = strdup(path))
                    ll_add_data(cur_node, new_path);
                else
                {
                    fprintf(stderr, "%s: failure copying path name.\n",
                             progname);
                    akexit(AKLOG_MISC);
                }
            }
            else
            {
                fprintf(stderr, "%s: failure adding path to paths list.\n",
                         progname);
                akexit(AKLOG_MISC);
            }
            pmode = FALSE;
            memset(path, 0, sizeof(path));
        }
    }

    if (!noprdb)
        initialize_PT_error_table();

    if (usev5) {
        validate_krb5_availability();
        if (krb5_init_context(&context))
            return(AKLOG_KERBEROS);
        load_krb5_error_message_funcs();
    } else 
        validate_krb4_availability();
    afs_set_com_err_hook(redirect_errors);

    /* If nothing was given, log to the local cell. */
    if ((cells.nelements + paths.nelements) == 0)
        status = auth_to_cell(context, NULL, NULL);
    else
    {
        /* Log to all cells in the cells list first */
        for (cur_node = cells.first; cur_node; cur_node = cur_node->next)
        {
            memcpy(&cellinfo, cur_node->data, sizeof(cellinfo));
            if (status = auth_to_cell(context, 
                                       cellinfo.cell, cellinfo.realm))
                somethingswrong++;
        }       

        /* Then, log to all paths in the paths list */
        for (cur_node = paths.first; cur_node; cur_node = cur_node->next)
        {
            if (status = auth_to_path(context, 
                                       cur_node->data))
                somethingswrong++;
        }

        /*
        * If only one thing was logged to, we'll return the status
        * of the single call.  Otherwise, we'll return a generic
        * something failed status.
        */
        if (somethingswrong && ((cells.nelements + paths.nelements) > 1))
            status = AKLOG_SOMETHINGSWRONG;
    }       

    akexit(status);
}