Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

reorganize source tree and split up files

  • Loading branch information...
commit f3127b525bab749f876a1ca4523a13e2f5c7a2ba 1 parent 78b51d9
@vodik authored
View
15 Makefile
@@ -17,12 +17,11 @@ LDLIBS = -lsystemd-daemon -ldbus-1
all: envoyd envoy envoy-exec pam_envoy.so
-pam_envoy.o: pam_envoy.c
-envoyd: envoyd.o lib/envoy.o \
+envoyd: envoyd.o agents.o socket.o util.o \
clique/systemd-scope.o clique/systemd-unit.o \
clique/dbus/dbus-shim.o clique/dbus/dbus-util.o
-envoy: envoy.o lib/envoy.o gpg-protocol.o
-envoy-exec: envoy-exec.o lib/envoy.o gpg-protocol.o
+envoy: envoy.o agents.o socket.o gpg-protocol.o util.o
+envoy-exec: envoy-exec.o agents.o socket.o gpg-protocol.o util.o
gpg-protocol.c: gpg-protocol.rl
ragel -F0 -C $< -o $@
@@ -30,10 +29,14 @@ gpg-protocol.c: gpg-protocol.rl
gpg-protocol.o: gpg-protocol.c
${CC} ${CFLAGS} -fPIC -o $@ -c $<
-lib/envoy.o pam_envoy.o:
+agents.o: agents.c
+ ${CC} ${CFLAGS} -fPIC -o $@ -c $<
+socket.o: socket.c
+ ${CC} ${CFLAGS} -fPIC -o $@ -c $<
+pam_envoy.o: pam_envoy.c
${CC} ${CFLAGS} -fPIC -o $@ -c $<
-pam_envoy.so: pam_envoy.o lib/envoy.o gpg-protocol.o
+pam_envoy.so: pam_envoy.o agents.o socket.o gpg-protocol.o
${CC} ${LDFLAGS} -shared -DPIC -o $@ $?
install: envoyd envoy pam_envoy.so
View
46 lib/envoy.c → agents.c
@@ -12,10 +12,10 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
- * Copyright (C) Simon Gomizelj, 2012
+ * Copyright (C) Simon Gomizelj, 2013
*/
-#include "envoy.h"
+#include "agents.h"
#include <stdlib.h>
#include <stdio.h>
@@ -27,6 +27,8 @@
#include <sys/socket.h>
#include <sys/un.h>
+#include "socket.h"
+
const struct agent_t Agent[LAST_AGENT] = {
[AGENT_SSH_AGENT] = {
.name = "ssh-agent",
@@ -38,36 +40,6 @@ const struct agent_t Agent[LAST_AGENT] = {
}
};
-static const char *get_socket_path(void)
-{
- const char *socket = getenv("ENVOY_SOCKET");
- return socket ? socket : "@/vodik/envoy";
-}
-
-size_t init_envoy_socket(struct sockaddr_un *un)
-{
- const char *socket = get_socket_path();
- off_t off = 0;
- size_t len;
-
- *un = (struct sockaddr_un){ .sun_family = AF_UNIX };
-
- if (socket[0] == '@')
- off = 1;
-
- len = strlen(socket);
- memcpy(&un->sun_path[off], &socket[off], len - off);
-
- return len + sizeof(un->sun_family);
-}
-
-void unlink_envoy_socket(void)
-{
- const char *socket = get_socket_path();
- if (socket[0] != '@')
- unlink(socket);
-}
-
static int read_agent(int fd, struct agent_data_t *data)
{
int nbytes_r;
@@ -126,12 +98,4 @@ enum agent lookup_agent(const char *string)
return i;
}
-void safe_asprintf(char **strp, const char *fmt, ...)
-{
- va_list ap;
-
- va_start(ap, fmt);
- if (vasprintf(strp, fmt, ap) < 0)
- err(EXIT_FAILURE, "failed to allocate memory");
- va_end(ap);
-}
+// vim: et:sts=4:sw=4:cino=(0
View
11 lib/envoy.h → agents.h
@@ -12,11 +12,11 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
- * Copyright (C) Simon Gomizelj, 2012
+ * Copyright (C) Simon Gomizelj, 2013
*/
-#ifndef LIBENVOY_H
-#define LIBENVOY_H
+#ifndef AGENT_H
+#define AGENT_H
#include <stdbool.h>
#include <limits.h>
@@ -55,12 +55,9 @@ struct agent_data_t {
extern const struct agent_t Agent[LAST_AGENT];
-size_t init_envoy_socket(struct sockaddr_un *un);
-void unlink_envoy_socket(void);
-
int envoy_agent(struct agent_data_t *data, enum agent id, bool start);
enum agent lookup_agent(const char *string);
-void safe_asprintf(char **strp, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
+/* void safe_asprintf(char **strp, const char *fmt, ...) __attribute__((format (printf, 2, 3))); */
#endif
View
3  envoy-exec.c
@@ -21,7 +21,8 @@
#include <errno.h>
#include <unistd.h>
-#include "lib/envoy.h"
+#include "agents.h"
+#include "socket.h"
#include "gpg-protocol.h"
static const char *exe_path;
View
3  envoy.c
@@ -29,7 +29,8 @@
#include <sys/socket.h>
#include <sys/un.h>
-#include "lib/envoy.h"
+#include "agents.h"
+#include "socket.h"
#include "gpg-protocol.h"
static struct termios old_termios;
View
4 envoyd.c
@@ -31,9 +31,11 @@
#include <sys/wait.h>
#include <systemd/sd-daemon.h>
-#include "lib/envoy.h"
#include "clique/systemd-unit.h"
#include "clique/systemd-scope.h"
+#include "agents.h"
+#include "socket.h"
+#include "util.h"
struct agent_info_t {
uid_t uid;
View
3  pam_envoy.c
@@ -32,7 +32,8 @@
#include <security/pam_appl.h>
#include <security/pam_modules.h>
-#include "lib/envoy.h"
+#include "agents.h"
+#include "socket.h"
#include "gpg-protocol.h"
#define UNUSED __attribute__((unused))
View
58 socket.c
@@ -0,0 +1,58 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (C) Simon Gomizelj, 2012
+ */
+
+#include "socket.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdbool.h>
+#include <stdarg.h>
+#include <errno.h>
+#include <err.h>
+#include <unistd.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+
+static const char *get_socket_path(void)
+{
+ const char *socket = getenv("ENVOY_SOCKET");
+ return socket ? socket : "@/vodik/envoy";
+}
+
+size_t init_envoy_socket(struct sockaddr_un *un)
+{
+ const char *socket = get_socket_path();
+ off_t off = 0;
+ size_t len;
+
+ *un = (struct sockaddr_un){ .sun_family = AF_UNIX };
+
+ if (socket[0] == '@')
+ off = 1;
+
+ len = strlen(socket);
+ memcpy(&un->sun_path[off], &socket[off], len - off);
+
+ return len + sizeof(un->sun_family);
+}
+
+void unlink_envoy_socket(void)
+{
+ const char *socket = get_socket_path();
+ if (socket[0] != '@')
+ unlink(socket);
+}
View
34 socket.h
@@ -0,0 +1,34 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (C) Simon Gomizelj, 2012
+ */
+
+#ifndef LIBENVOY_H
+#define LIBENVOY_H
+
+#include <stdbool.h>
+#include <limits.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+
+size_t init_envoy_socket(struct sockaddr_un *un);
+void unlink_envoy_socket(void);
+
+void safe_asprintf(char **strp, const char *fmt, ...);
+
+#endif
+
+// vim: et:sts=4:sw=4:cino=(0
View
16 util.c
@@ -0,0 +1,16 @@
+#include "util.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <err.h>
+
+void safe_asprintf(char **strp, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ if (vasprintf(strp, fmt, ap) < 0)
+ err(EXIT_FAILURE, "failed to allocate memory");
+ va_end(ap);
+}
View
25 util.h
@@ -0,0 +1,25 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (C) Simon Gomizelj, 2013
+ */
+
+#ifndef UTIL_H
+#define UTIL_H
+
+void safe_asprintf(char **strp, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
+
+#endif
+
+// vim: et:sts=4:sw=4:cino=(0
Please sign in to comment.
Something went wrong with that request. Please try again.