/* getxattrs.c * * by Dean Giles * * Version 1.0. * November 30, 2006 * * This program retrieves and displays the data kept in the netware.metadata extended attribute on * an NSS file on a Linux server. * * For the this Utility to work on SLES 9 OES1 SP2 the kernel needs to be at the 282 (2.6.5-7.282). * It also requires the following patches: * km-nss-4.9.26-0.1.i586.rpm * novell-nss-4.9.23-1.i586.rpm * novell-sms-zapishim-2.6.5_7.282-1.0.5.i586.rpm * * NSS must be installed and running. * * The following parameters must be set from NSSCON * NSS /ListXattrNWMetadata * NSS /CtimeISMetadataModTime * */ #include //Needed for malloc(). #include //Needed for listxattr(). #include //Needed for errno. void main(int argc, char** argv) { const char* path=argv[1]; // Holds the path and the file name. ssize_t result, newresult; // Holds the size of data or return codes for function calls. char* list; // Holds the list of extended attributes. char* value; int i; list = malloc(128); //Create storage for the list of extended attributs. result = listxattr(path, list, 128); // get the list of extended attributes. if (result == -1) // Return code of -1 means an error. errno is set with error code. printf("listxattr failed with errno set to %d.\n",errno); else { printf("The file %s ",path); printf("has the extended attribute(s) %s (the string takes up %d bytes).\n", list, result); } value = malloc(32); // Create storage for what is kept in the extended attribute. result = getxattr(path, "netware.metadata", value, 0); // This gets the size of the data in the extended attribute. if (result == -1) // Return code of -1 means an error. errno is set with error code. printf("getxattr failed with errno set to %d.",errno); else { printf("There are %d byts of data in the %s extended attribute(s).\n\n", result, list); printf("A dump of the extended attribute %s is the following:\n", list); free(value); value = malloc(result); // Allocate amount of storage needed for this extended attribute. newresult = getxattr(path, "netware.metadata", value, result); // This time get the data in the netware.metadata xattr. if (newresult == -1) // Return code of -1 means an error. errno is set with error code. printf("getxattr failed with errno set to %d.",errno); else { for (i = 0; i < result; i++) printf("%08x ", *(value + i)); //print out the data in hex as words. } printf("\n"); } free(list); // clean up allocated memory. free(value); }