static int password_lifetime() { void *d, *d1; int status; ni_id dir; ni_namelist nl; status = ni_open(NULL, ".", &d); while (status == NI_OK) { status = ni_pathsearch(d, &dir, "/users"); if (status == NI_OK) { status = ni_lookupprop(d, &dir, "password_lifetime", &nl); if (status == NI_OK) { if (nl.ni_namelist_val[0] != NULL) { ni_free(d); /* free namelist? */ return atoi(nl.ni_namelist_val[0]); } } } d1 = d; status = ni_open(d1, "..", &d); ni_free(d1); } return -1; }
static int secure_passwords() { void *d, *d1; int status; ni_index where; ni_id dir; ni_namelist nl; status = ni_open(NULL, ".", &d); while (status == NI_OK) { dir.nii_object = 0; status = ni_lookupprop(d, &dir, "security_options", &nl); if (status == NI_OK) { where = ni_namelist_match(nl, "secure_passwords"); if (where != NI_INDEX_NULL) { ni_free(d); return 1; } } d1 = d; status = ni_open(d1, "..", &d); ni_free(d1); } return 0; }
int NetInfoPrefsSource::GetValueByIndex(const char* inKey, UInt32 inIndex, char* ioValue) { ni_status status = NI_OK; ni_namelist nameList = {}; void* localDomain = NULL; ni_id qtssDir = {}; ioValue[0] = '\0'; status = ni_open(NULL, ".", &localDomain); if (status != NI_OK) return false; if (status == NI_OK) status = ni_pathsearch(localDomain, &qtssDir, gQTSSPropertiesPath); if (status == NI_OK) status = ni_lookupprop(localDomain, &qtssDir, inKey, &nameList); if (status == NI_OK) { if (nameList.ni_namelist_len > inIndex) strcpy(ioValue, nameList.ni_namelist_val[inIndex]); else status = NI_BADID; ni_namelist_free(&nameList); } ni_free(localDomain); return (status == NI_OK); }
krb5_error_code KRB5_LIB_FUNCTION krb5_config_parse_file (krb5_context context, const char *fname, krb5_config_section **res) { void *ni = NULL, *lastni = NULL; int i; ni_status nis; ni_id nid; ni_idlist children; krb5_config_section *s; int ret; s = NULL; for (i = 0; i < 256; i++) { if (i == 0) { nis = ni_open(NULL, ".", &ni); } else { if (lastni != NULL) ni_free(lastni); lastni = ni; nis = ni_open(lastni, "..", &ni); } if (nis != NI_OK) break; nis = ni_pathsearch(ni, &nid, "/locations/kerberos"); if (nis == NI_OK) { nis = ni_children(ni, &nid, &children); if (nis != NI_OK) break; nis = ni_idlist2binding(ni, &children, &s); break; } } if (ni != NULL) ni_free(ni); if (ni != lastni && lastni != NULL) ni_free(lastni); ret = (nis == NI_OK) ? 0 : -1; if (ret == 0) { *res = s; } else { *res = NULL; } return ret; }
void NetInfoPrefsSource::SetValueByIndex(char* inKey, char* inValue, UInt32 inIndex) { void* localDomain = NULL; ni_status status = NI_OK; ni_namelist nameList = {}; //ni_namelist_insert(&nameList, (char*)inValue, NI_INDEX_NULL); ni_namelist_insert(&nameList, inValue, inIndex); status = ni_open(NULL, ".", &localDomain); if (status == NI_OK) { //create the path if it doesn't already exist status = ni2_create(localDomain, gQTSSPropertiesPath); if (status == NI_OK) status = ni2_appendprop(localDomain, gQTSSPropertiesPath, inKey, nameList); } ni_namelist_free(&nameList); ni_free(localDomain); }
static void * domain_for_user(char *uname, char *locn, ni_id * dir) { char *upath; int status; void *d, *d1; struct sockaddr_in server; char *tag; int bytag; if (uname == NULL) return NULL; /* * Find the user in NetInfo. */ upath = malloc(8 + strlen(uname)); sprintf(upath, "/users/%s", uname); if (locn != NULL) { bytag = 1; if (locn[0] == '/') bytag = 0; else if (!strncmp(locn, "./", 2)) bytag = 0; else if (!strncmp(locn, "../", 3)) bytag = 0; if (bytag == 1) { parse_server_tag(locn, &server, &tag); d = ni_connect(&server, tag); if (d == (void *) NULL) return (void *) NULL; } else status = ni_open(NULL, locn, &d); status = ni_pathsearch(d, dir, upath); free(upath); if (status == NI_OK) return d; ni_free(d); return (void *) NULL; } status = ni_open(NULL, ".", &d); while (status == NI_OK) { status = ni_pathsearch(d, dir, upath); if (status == NI_OK) break; d1 = d; status = ni_open(d1, "..", &d); ni_free(d1); } free(upath); if (status == NI_OK) return d; return (void *) NULL; }
int do_open(char *tool, char *name, void **domain, bool bytag, int timeout, char *user, char *passwd) { /* do an ni_open or an ni_connect, as appropriate */ char *tag; enum ni_parse_status pstatus; ni_status status; struct sockaddr_in server; ni_id rootdir; if (bytag) { /* connect by tag */ /* call a function to parse the input arg */ pstatus = ni_parse_server_tag(name, &server, &tag); if (pstatus != NI_PARSE_OK) { qtss_fprintf(stderr, "%s: incorrect format for domain %s (%s)\n", tool, name, ni_parse_error_string(pstatus)); qtss_fprintf(stderr, "usage: -t <host>/<tag>\n"); qtss_fprintf(stderr, "<host> can be a host name or IP address\n"); return NI_FAILED + 1 + pstatus; } /* connect to the specified server */ *domain = ni_connect(&server, tag); if (*domain == NULL) { qtss_fprintf(stderr, "%s: can't connect to server %s\n", tool, name); free(tag); return NI_FAILED + 1; } } else { /* open domain */ status = ni_open(NULL, name, domain); if (status != NI_OK) { qtss_fprintf(stderr, "%s: can't connect to server for domain %s\n", tool, name); return status; } } /* abort on errors */ ni_setabort(*domain, 1); /* set timeouts */ ni_setreadtimeout(*domain, timeout); ni_setwritetimeout(*domain, timeout); /* authentication */ if (user != NULL) { ni_setuser(*domain, user); if (passwd != NULL) ni_setpassword(*domain, passwd); } /* get the root directory to see if the connection is alive */ status = ni_root(*domain, &rootdir); if (status != NI_OK) { if (bytag) qtss_fprintf(stderr, "%s: can't connect to server %s: %s\n", tool, name, ni_error(status)); else qtss_fprintf(stderr, "%s: can't connect to server for domain %s: %s\n", tool, name, ni_error(status)); return status; } return 0; }