home *** CD-ROM | disk | FTP | other *** search
- /*
- * niread
- *
- * usage: niread domain directory
- * compile with: cc -o niread niread.c
- *
- * Similar to "niutil -read domain directory"
- *
- * Sample output:
- *
- * myhost> niread . /users/me
- * "name": "me"
- * "passwd": "BBmuFjTkKx/f."
- * "uid": "20"
- * "gid": "20"
- * "realname": "My Account"
- * "home": "/me"
- * "shell": "/bin/csh"
- * "_writers_passwd": "me"
- *
- * Author: Marc Majka
- * You may freely copy, distribute and reuse the code in this example.
- * NeXT disclaims any warranty of any kind, expressed or implied, as to
- * its fitness for any particular use.
- */
-
- #import <ansi/stdio.h>
- #import <bsd/errno.h>
- #import <netinfo/ni.h>
-
- main(int argc, char *argv[]) {
-
- int pn, vn;
- ni_proplist plist;
- ni_property prop;
- ni_namelist values;
- void *dom;
- ni_id dir;
- ni_status ret;
-
- /* check usage */
- if (argc < 3) {
- fprintf(stderr, "usage: %s domain directory\n", argv[0]);
- exit(1);
- }
-
- /* argv[1] should be a domain name */
- ret = ni_open(NULL, argv[1], &dom);
- if (ret != NI_OK) {
- fprintf(stderr, "ni_open: %s\n", ni_error(ret));
- exit(1);
- }
-
- /* argv[2] should be a directory specification */
- ret = ni_pathsearch(dom, &dir, argv[2]);
- if (ret != NI_OK) {
- fprintf(stderr, "ni_pathsearch: %s\n", ni_error(ret));
- exit(1);
- }
-
- /* get the property list stored in the this directory */
- ret = ni_read(dom, &dir, &plist);
- if (ret != NI_OK) {
- fprintf(stderr, "ni_read: %s\n", ni_error(ret));
- exit(1);
- }
-
- /* for each property */
- for (pn = 0; pn < plist.ni_proplist_len; pn++) {
-
- prop = plist.ni_proplist_val[pn];
-
- /* print the property key enclosed in quotes */
- printf("\"%s\":", prop.nip_name);
-
- values = prop.nip_val;
-
- /* for each value in the namelist for this property */
- for (vn = 0; vn < values.ni_namelist_len; vn++) {
- /* print the value enclosed in quotes */
- printf(" \"%s\"", values.ni_namelist_val[vn]);
- }
- printf("\n");
- }
-
- /* clean up */
- ni_free(dom);
-
- exit(0);
- }