#include <stdarg.h>
#include <stdlib.h>
#include <errno.h>
+#include <glib.h>
#include <gnome-keyring.h>
/*
#define CREDENTIAL_INIT \
{ NULL,NULL,0,NULL,NULL,NULL }
-void credential_init(struct credential *c);
-void credential_clear(struct credential *c);
-int credential_read(struct credential *c);
-void credential_write(const struct credential *c);
-
typedef int (*credential_op_cb)(struct credential*);
struct credential_operation
#define CREDENTIAL_OP_END \
{ NULL,NULL }
-/*
- * Table with operation callbacks is defined in concrete
- * credential helper implementation and contains entries
- * like { "get", function_to_get_credential } terminated
- * by CREDENTIAL_OP_END.
- */
-struct credential_operation const credential_helper_ops[];
-
/* ---------------- common helper functions ----------------- */
static inline void free_password(char *password)
va_end(ap);
}
-static inline void die(const char *fmt, ...)
-{
- va_list ap;
-
- va_start(ap,fmt);
- error(fmt, ap);
- va_end(ap);
- exit(EXIT_FAILURE);
-}
-
static inline void die_errno(int err)
{
error("%s", strerror(err));
return object;
object = (char*) malloc(strlen(c->host)+strlen(c->path)+8);
- if(!object)
+ if (!object)
die_errno(errno);
- if(c->port)
+ if (c->port)
sprintf(object,"%s:%hd/%s",c->host,c->port,c->path);
else
sprintf(object,"%s/%s",c->host,c->path);
return object;
}
-int keyring_get(struct credential *c)
+static int keyring_get(struct credential *c)
{
char* object = NULL;
GList *entries;
}
-int keyring_store(struct credential *c)
+static int keyring_store(struct credential *c)
{
guint32 item_id;
char *object = NULL;
return EXIT_SUCCESS;
}
-int keyring_erase(struct credential *c)
+static int keyring_erase(struct credential *c)
{
char *object = NULL;
GList *entries;
* Table with helper operation callbacks, used by generic
* credential helper main function.
*/
-struct credential_operation const credential_helper_ops[] =
+static struct credential_operation const credential_helper_ops[] =
{
{ "get", keyring_get },
{ "store", keyring_store },
/* ------------------ credential functions ------------------ */
-void credential_init(struct credential *c)
+static void credential_init(struct credential *c)
{
memset(c, 0, sizeof(*c));
}
-void credential_clear(struct credential *c)
+static void credential_clear(struct credential *c)
{
free(c->protocol);
free(c->host);
credential_init(c);
}
-int credential_read(struct credential *c)
+static int credential_read(struct credential *c)
{
char buf[1024];
- ssize_t line_len = 0;
+ size_t line_len;
char *key = buf;
char *value;
{
line_len = strlen(buf);
- if(buf[line_len-1]=='\n')
+ if (line_len && buf[line_len-1] == '\n')
buf[--line_len]='\0';
- if(!line_len)
+ if (!line_len)
break;
value = strchr(buf,'=');
- if(!value) {
+ if (!value) {
warning("invalid credential line: %s", key);
return -1;
}
return 0;
}
-void credential_write_item(FILE *fp, const char *key, const char *value)
+static void credential_write_item(FILE *fp, const char *key, const char *value)
{
if (!value)
return;
fprintf(fp, "%s=%s\n", key, value);
}
-void credential_write(const struct credential *c)
+static void credential_write(const struct credential *c)
{
/* only write username/password, if set */
credential_write_item(stdout, "username", c->username);
basename = (basename) ? basename + 1 : name;
fprintf(stderr, "usage: %s <", basename);
- while(try_op->name) {
+ while (try_op->name) {
fprintf(stderr,"%s",(try_op++)->name);
- if(try_op->name)
+ if (try_op->name)
fprintf(stderr,"%s","|");
}
fprintf(stderr,"%s",">\n");
if (!argv[1]) {
usage(argv[0]);
- goto out;
+ exit(EXIT_FAILURE);
}
+ g_set_application_name("Git Credential Helper");
+
/* lookup operation callback */
- while(try_op->name && strcmp(argv[1], try_op->name))
+ while (try_op->name && strcmp(argv[1], try_op->name))
try_op++;
/* unsupported operation given -- ignore silently */
- if(!try_op->name || !try_op->op)
+ if (!try_op->name || !try_op->op)
goto out;
ret = credential_read(&cred);
- if(ret)
+ if (ret)
goto out;
/* perform credential operation */