void nis_ping(nis_name name, uint32_t mtime, nis_object *obj) { nis_server **srvs; nis_server *s, *list; int i, ns; nis_name thishost = nis_local_host(); if (obj) { if (name == 0) name = obj->DI_data.do_name; list = obj->DI_data.do_servers.do_servers_val; ns = obj->DI_data.do_servers.do_servers_len; for (i = 0, s = &(list[0]); i < ns; i++, s = &(list[i])) { if (nis_dir_cmp(s->name, thishost) == SAME_NAME) { continue; } __nis_pingproc(s, name, mtime); } } else { srvs = nis_getservlist(name); if (! srvs) return; for (i = 0, s = srvs[0]; s; i++, s = srvs[i]) { if (nis_dir_cmp(s->name, thishost) == SAME_NAME) { continue; } __nis_pingproc(s, name, mtime); } nis_freeservlist(srvs); } }
/* Check that someone else don't have the same auth information already */ static nis_error auth_exists(char *princname, char *auth_name, char *auth_type, char *domain) { char sname[NIS_MAXNAMELEN+MAXHOSTNAMELEN+64]; nis_result *res; nis_error status; char *foundprinc; (void) sprintf(sname, "[auth_name=%s,auth_type=%s],%s.%s", auth_name, auth_type, CRED_TABLE, domain); if (sname[strlen(sname)-1] != '.') strcat(sname, "."); /* Don't want FOLLOW_PATH here */ res = nis_list(sname, MASTER_ONLY+USE_DGRAM+NO_AUTHINFO+FOLLOW_LINKS, NULL, NULL); status = res->status; switch (res->status) { case NIS_NOTFOUND: break; case NIS_TRYAGAIN : (void) fprintf(stderr, "%s: NIS+ server busy, try again later.\n", program_name); exit(1); case NIS_PERMISSION : (void) fprintf(stderr, "%s: insufficient permission to look up old credentials.\n", program_name); exit(1); case NIS_SUCCESS: foundprinc = ENTRY_VAL(res->objects.objects_val, 0); if (nis_dir_cmp(foundprinc, princname) != SAME_NAME) { (void) fprintf(stderr, "%s: %s credentials with auth_name '%s' already belong to '%s'.\n", program_name, auth_type, auth_name, foundprinc); exit(1); } break; default: (void) fprintf(stderr, "%s: error looking at cred table, NIS+ error: %s\n", program_name, nis_sperrno(res->status)); exit(1); } nis_freeresult(res); return (status); }
/* * __nis_path * * Given two path strings, *from and *to, work out the list of names * between them. The length of that path and the pointer to the list * of pointers to the name strings are returned to the caller using * path_length and namesp. As the names list is a pointer to a list of * pointers, the caller must pass the address of the pointer to the * pointer to the list of pointers, hence the unusual "char ***" * type. It is the callers responsibility to free **namesp. */ nis_error __nis_path(char *from, char *to, int *path_length, char ***namesp) { int i; int n; int start; int end; int st, dircmp, lastdircmp; char *tfrom = from; char *tto = to; char **names; dircmp = st = nis_dir_cmp(from, to); if (st == BAD_NAME) return (NIS_BADNAME); /* figure out how long path is */ n = 0; if (st == HIGHER_NAME) { while ((dircmp = nis_dir_cmp(from, to)) == HIGHER_NAME) { n++; to = nis_domain_of(to); } if (dircmp != SAME_NAME) { /* Unrecoverable error */ dircmp = BAD_NAME; } } else if (st == LOWER_NAME) { from = nis_domain_of(from); while ((dircmp = nis_dir_cmp(from, to)) == LOWER_NAME) { n++; from = nis_domain_of(from); } if (dircmp != SAME_NAME) { /* Unrecoverable error */ dircmp = BAD_NAME; } n++; /* include actual target */ } else if (st == NOT_SEQUENTIAL) { /* names are not sequential */ from = nis_domain_of(from); while ((dircmp = nis_dir_cmp(from, to)) == NOT_SEQUENTIAL) { n++; from = nis_domain_of(from); } n++; /* include common parent */ lastdircmp = dircmp; /* Handle HIGHER or LOWER */ while ((dircmp = nis_dir_cmp(from, to)) == lastdircmp) { n++; lastdircmp = dircmp; to = nis_domain_of(to); } if (dircmp != SAME_NAME) { /* Unrecoverable error */ dircmp = BAD_NAME; } } if (dircmp == BAD_NAME) { syslog(LOG_WARNING, "__nis_path: Unable to walk " "from %s to %s", tfrom, tto); return (NIS_BADNAME); } names = malloc(n * sizeof (char *)); if (names == NULL) return (NIS_NOMEMORY); start = 0; end = n; from = tfrom; to = tto; /* * Go through again, this time storing names. * We shouldn't need to check the loops will terminate * on the SAME_NAME condition as we've already checked for * errors in the previous loop. */ if (st == HIGHER_NAME) { while (nis_dir_cmp(from, to) != SAME_NAME) { names[--end] = strdup(to); to = nis_domain_of(to); } } else if (st == LOWER_NAME) { from = nis_domain_of(from); while (nis_dir_cmp(from, to) != SAME_NAME) { names[start++] = strdup(from); from = nis_domain_of(from); } names[start++] = strdup(to); /* include actual target */ } else if (st == NOT_SEQUENTIAL) { /* names are not sequential */ from = nis_domain_of(from); while (nis_dir_cmp(from, to) == NOT_SEQUENTIAL) { names[start++] = strdup(from); from = nis_domain_of(from); } names[start++] = strdup(from); /* include common parent */ while (nis_dir_cmp(from, to) != SAME_NAME) { names[--end] = strdup(to); to = nis_domain_of(to); } } /* make sure all of the allocations were successful */ for (i = 0; i < n; i++) { if (names[i] == NULL) { __nis_path_free(names, n); names = NULL; break; } } /* Set the return values */ *path_length = n; *namesp = names; return (NIS_SUCCESS); }