.\"
.TH "SMACK_HAVE_ACCESS" "3" "06/20/2012" "Libsmack 1\&.0"
.SH NAME
-smack_have_access, smack_new_label_from_self, smack_new_label_from_socket \- Userspace interaction with Smack
+smack_have_access, smack_new_label_from_self, smack_new_label_from_socket, smack_label_length \- Userspace interaction with Smack
.SH SYNOPSIS
.B #include <sys/smack.h>
.sp
.BI "int smack_set_label_for_self(char **" label ");"
.br
.BI "int smack_new_label_from_socket(int " fd ", char **" label ");"
+.br
+.BI "int smack_label_length(const char *" label ");"
.sp
.SH DESCRIPTION
Smack is a Mandatory Access Control (MAC) based security mechanism for the Linux kernel. It works on the basis of context, which is stored as a label in the extended attributes (xattr) of a file. When a process is started the kernel ensures that this context is assigned to the running process. By default a process can only interact with processes and filesystem objects that have the same context as itself and is denied access to all other contexts. Rules can be created to grant access to other contexts, these are generally created on package installation and can only be modified by a process that has the CAP_MAC_ADMIN capability.
on return. It is the callers responsibility to free
.I label
when it is no longer required.
+.PP
+.BR smack_label_length ()
+calculates length of
+.IR label ,
+and validates it.
.SH RETURN VALUE
.BR smack_new_label_from_self ()
and
returns 1 if allowed, 0 if no access and \-1 on error (in which case,
.I errno
is set appropriately).
+
+.BR smack_label_length ()
+returns length of
+.I label
+if it is valid and negative value if it's not.
}
}
+int smack_label_length(const char *label)
+{
+ int i;
+
+ if (!label || label[0] == '\0' || label[0] == '-')
+ return 0;
+
+ for (i = 0; i < (SMACK_LABEL_LEN + 1) && label[i]; i++) {
+ switch (label[i]) {
+ case ' ':
+ case '/':
+ case '"':
+ case '\\':
+ case '\'':
+ return -1;
+ default:
+ break;
+ }
+ }
+ return i < (SMACK_LABEL_LEN + 1) ? i : -1;
+}
*/
int smack_revoke_subject(const char *subject);
+/*!
+ * Validate a SMACK label and calculate its length.
+ *
+ * @param label label to verify
+ * @return Returns length of the label on success and negative on failure.
+ */
+int smack_label_length(const char *label);
+
#ifdef __cplusplus
}
#endif