- printf ("Check given files have...\n");
- printf (" -p permission file must have required permissions\n");
- printf (" -t dir|file|link file must be of the specified type\n");
- printf (" -l link_name file must be a link to the given name\n");
- printf (" -s size file must have the given size\n");
- printf (" -u user file must be owned by given user\n");
- printf (" -g group file must be owned by given group\n");
- printf (" -f follow symlinks\n");
- printf (" -a file must be absent\n");
- printf (" -v increase verbosity\n");
- printf (" -h print help\n");
- printf (" Exit status is 0 on success, 1 on failure\n");
+ printf("Check given files have...\n");
+ printf(" -p permission file must have required permissions\n");
+ printf(" -t dir|file|link file must be of the specified type\n");
+ printf(" -l link_name file must be a link to the given name\n");
+ printf(" -s size file must have the given size\n");
+ printf(" -u user file must be owned by given user\n");
+ printf(" -g group file must be owned by given group\n");
+ printf(" -f follow symlinks\n");
+ printf(" -a file must be absent\n");
+ printf(" -v increase verbosity\n");
+ printf(" -h print help\n");
+ printf(" Exit status is 0 on success, 1 on failure\n");
+}
+
+/* using realpath() implies the paths must be resolved/exist
+ * so this will fail for dangling links
+ */
+int check_canonical(char *lname, char *checklink, int verbose)
+{
+ char *lname_canon;
+ char *checklink_canon;
+
+ lname_canon = realpath(lname, NULL);
+ if (lname_canon == NULL) {
+ if (verbose)
+ printf("%s: can't canonicalize: %s\n",
+ lname, strerror(errno));
+ return 1;
+ }
+
+ checklink_canon = realpath(checklink, NULL);
+ if (checklink_canon == NULL) {
+ if (verbose)
+ printf("%s: can't canonicalize: %s\n",
+ checklink, strerror(errno));
+ return 1;
+ }
+
+ if (strcmp(checklink_canon, lname_canon)) {
+ free(lname_canon);
+ free(checklink_canon);
+ return 1;
+ }
+ free(lname_canon);
+ free(checklink_canon);
+ return 0;