return buf[0] == '1';
}
-char *smack_get_peer_label(int fd)
+char *smack_get_self_label()
{
- char dummy;
- int ret;
- socklen_t length = 1;
char *label;
+ int fd;
+ int ret;
- ret = getsockopt(fd, SOL_SOCKET, SO_PEERSEC, &dummy, &length);
- if (ret < 0 && errno != ERANGE)
+ label = calloc(LABEL_LEN + 1, 1);
+ if (label == NULL)
return NULL;
- label = calloc(length, 1);
- if (label == NULL)
+ fd = open(SELF_LABEL_FILE, O_RDONLY);
+ if (fd < 0) {
+ free(label);
return NULL;
+ }
- ret = getsockopt(fd, SOL_SOCKET, SO_PEERSEC, label, &length);
+ ret = read(fd, label, LABEL_LEN);
+ close(fd);
if (ret < 0) {
free(label);
return NULL;
return label;
}
-char *smack_get_self_label()
+char *smack_get_peer_label(int fd)
{
- char *label;
- int fd;
+ char dummy;
int ret;
+ socklen_t length = 1;
+ char *label;
- label = calloc(LABEL_LEN + 1, 1);
- if (label == NULL)
+ ret = getsockopt(fd, SOL_SOCKET, SO_PEERSEC, &dummy, &length);
+ if (ret < 0 && errno != ERANGE)
return NULL;
- fd = open(SELF_LABEL_FILE, O_RDONLY);
- if (fd < 0) {
- free(label);
+ label = calloc(length, 1);
+ if (label == NULL)
return NULL;
- }
- ret = read(fd, label, LABEL_LEN);
- close(fd);
+ ret = getsockopt(fd, SOL_SOCKET, SO_PEERSEC, label, &length);
if (ret < 0) {
free(label);
return NULL;
const char *access_type);
/*!
- * Get the label that is associated with a peer on the other end of an
- * Unix socket. Caller is responsible of freeing the returned label.
+ * Get the label that is associated with the callers process.
+ * Caller is responsible of freeing the returned label.
*
- * @param fd socket file descriptor
- * @return label on success and NULL of failure.
+ * @return Callers label on success and NULL of failure.
*/
-extern char *smack_get_peer_label(int fd);
+extern char *smack_get_self_label();
/*!
- * Allow a process to determine its own smack label
+ * Get the label that is associated with a peer on the other end of an
+ * Unix socket. Caller is responsible of freeing the returned label.
*
- * @return The label of the process, NULL on error.
+ * @param fd socket file descriptor
+ * @return Peers label on success and NULL of failure.
*/
-extern char *smack_get_self_label();
+extern char *smack_get_peer_label(int fd);
#ifdef __cplusplus
}