Ejemplo n.º 1
0
int
_gss_ntlm_get_user_cred(const ntlm_name target_name,
			ntlm_cred *rcred)
{
    ntlm_cred cred;
    int ret;

    cred = calloc(1, sizeof(*cred));
    if (cred == NULL)
	return ENOMEM;

    ret = get_user_file(target_name,
                        &cred->domain, &cred->username, &cred->key);
    if (ret)
	ret = get_user_ccache(target_name,
                              &cred->domain, &cred->username, &cred->key);
    if (ret) {
	free(cred);
	return ret;
    }

    *rcred = cred;

    return ret;
}
Ejemplo n.º 2
0
gboolean save_selected_color ()
{
	GtkEntry *entry;
	FILE     *fp;
	gchar     old[512] = "";
	
	/* get entry text */
	entry = GTK_ENTRY (lookup_widget (savedialog, "save_entry"));
	colorname = g_strdup (gtk_entry_get_text (entry));
	
	if (!strcmp (colorname, ""))
		return FALSE;

	/* save color in user file - write at top of the file */
	
	/* if file exists already, get its contents, otherwise just write to it */
	if (g_file_test (get_user_file (), G_FILE_TEST_EXISTS))
	{
		fp = fopen (get_user_file (), "r");
		if (fp)
		{
			fread (old, sizeof (old), 1, fp);
			fclose (fp);
		}
		else
		{
			show_file_error (FILE_READ);
			return FALSE;
		}
	}
	
	fp = fopen (get_user_file (), "w");
	if (!fp)
	{
		show_file_error (FILE_WRITE);
		return FALSE;
	}
	
	fprintf (fp, "%3d %3d %3d\t\t%s\n%s", colorvalue.red/256, colorvalue.green/256,
	         colorvalue.blue/256, colorname, old);
	fclose (fp);
	return TRUE;
}
Ejemplo n.º 3
0
/**
 * displays a simple file error dialog, where type specifies the
 * access that failed (read, write).
 */
void show_file_error (gchar* type)
{
	GtkDialog *d;

	d = GTK_DIALOG (
		gtk_message_dialog_new (GTK_WINDOW (gcolor2), GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR,
			GTK_BUTTONS_OK, _(FILE_ERROR), get_user_file (), type)
	);

	gtk_dialog_run (d);
	gtk_widget_destroy (GTK_WIDGET (d));
}
Ejemplo n.º 4
0
/**
 * Deletes the first matching line from the rgb user file
 * that matches the color name and color value specified.
 *
 * color_value is given in hex format
 */
gboolean delete_color (gchar* color_name, gchar* color_value)
{
	FILE     *fp;
	gchar    *p;
	gchar    *file_color_name;
	gchar     file_color_value[8];
	gint      r, g, b;
	gchar     buffer[512] = "";
	gchar     newstuff[512] = "";
	gboolean  found = FALSE;

	
	/* remove from file */
	fp = fopen (get_user_file (), "r");
	if (!fp)
	{
		show_file_error (FILE_READ);
		return FALSE;
	}

	while ((p = fgets (buffer, sizeof buffer, fp)) != NULL)
	{
		if (buffer[0] == '!')
			continue;
		r = g_ascii_strtoull (p, &p, 10);
		g = g_ascii_strtoull (p, &p, 10);
		b = g_ascii_strtoull (p, &p, 10);
		p += strspn (p, " \t");
		g_sprintf (file_color_value, "#%2X%2X%2X", r, g, b);
		file_color_name = g_strchomp (g_strdup (p));
		
		/* make sure to only remove the first matching color. both value and
		   name must match */
		if (found || strcmp (file_color_name, color_name) != 0 ||
		    strcmp (g_ascii_strup (file_color_value, -1), color_value) != 0)
		{
			g_sprintf (newstuff, "%s%3d %3d %3d\t\t%s\n", newstuff, r, g, b, file_color_name);
		}
		else
		{
			found = TRUE;
		}
	}
	fclose (fp);
	
	/* only rewrite the file if we found a match */
	if (found)
	{
		fp = fopen (get_user_file (), "w");
		if (!fp)
		{
			show_file_error (FILE_WRITE);
			return FALSE;
		}
		
		fprintf (fp, "%s", newstuff);
		fclose (fp);
		return TRUE;
	}
	return FALSE;
}