📄 nsfunc.c
字号:
return(nreq); } oldpass = newpass = rec->rr_desc; while (*newpass != ':') newpass ++; *newpass = '\0'; newpass ++; while (*newpass == ':' && *newpass != '\0') newpass ++; ret = vpasswd(oldpass, namepart(qp->q_name),dom); if (ret >= 0) { nhp->h_rcode = ret; } else { if (ret == -1) /* password was correct */ nhp->h_rcode = changepw(newpass, namepart(qp->q_name),dom); else nhp->h_rcode = R_INVPW; } } else { if (addind(dom,nreq) == RFS_SUCCESS) nhp->h_rcode = R_NOERR; else nhp->h_rcode = R_NSFAIL; } return(nreq); } default: LOG3(L_TRANS,"(%5d) nsfunc: unknown request type = %d\n", Logstamp,type); nhp->h_rcode = R_IMP; return(nreq); }}/* * addind adds indirect name server references to a request. */intaddind(dom,req)char *dom;struct request *req;{ struct header *hp = req->rq_head; int i; if ((req->rq_ns = findind(dom)) == NULL) return(RFS_FAILURE); for (i=0; req->rq_ns[i] != NULL; i++) ; hp->h_nscnt = i; if ((hp->h_arcnt = getars(req->rq_ns, &(req->rq_ar), hp->h_nscnt)) == 0) { freelist(req->rq_ns); req->rq_ns = NULL; hp->h_nscnt = 0; return(RFS_FAILURE); } return(RFS_SUCCESS);}/* copy resource record list and return # of entries */intcopyrlist(target,source)struct res_rec ***target;struct res_rec **source;{ int i; if (!source) { return(0); } for (i=0; source[i] != NULL; i++) ; if (*target == NULL && (*target = (struct res_rec **) calloc(i+1,sizeof(struct res_rec *))) == NULL) { LOG4(L_TRANS,"(%5d) copyrlist: calloc(%d,%d) fails\n", Logstamp,i+1,sizeof(struct res_rec *)); return(0); } for (i=0; source[i] != NULL; i++) (*target)[i] = source[i]; (*target)[i] = NULL; return(i);}/* * * getars gets additional records that match the data part of * records passed in rlist. The only kind of additional * records retrieved are of type A, which are retrieved * for NSTYPE, and RN type records. If the A record is * not found or the record in rlist is not of the right * type, a record of type NULLREC is put in the corresponding * place in arlist. The result is a list with each record * corresponding to the record in the same position in rlist. * If all records that would be put into arlist are of type * NULLREC, no records are returned. * getars returns the number of records in arlist, which * should be 0 or count. * */intgetars(rlist,arlist,count)struct res_rec **rlist;struct res_rec ***arlist;int count;{ static struct res_rec nullrec; int i; int tcount=0; struct res_rec **tlist; LOG2(L_TRANS,"(%5d) getars: enter\n",Logstamp); if (count == 0) return(0); /* set up nullrec */ strcpy(nullrec.rr_name,"NULL"); nullrec.rr_type = NULLREC; nullrec.rr_data = NULL; if (((*arlist) = (struct res_rec **) calloc(count+1, sizeof(struct res_rec *))) == NULL) { LOG4(L_TRANS,"(%5d) getars: can't calloc(%d,%d)\n", Logstamp,count,sizeof(struct res_rec *)); return(0); } for (i=0; i < count; i++) { switch (rlist[i]->rr_type&MASKNS) { case NSTYPE: if ((tlist = findrr(rlist[i]->rr_ns,A)) != NULL && (*tlist)->rr_type == A) { tcount++; (*arlist)[i] = *tlist; free(tlist); } else { (*arlist)[i] = duprec(&nullrec); } break; case RN: if ((tlist = findrr(rlist[i]->rr_owner,A)) != NULL && (*tlist)->rr_type == A) { tcount++; (*arlist)[i] = *tlist; free(tlist); } else { (*arlist)[i] = duprec(&nullrec); } break; default: (*arlist)[i] = duprec(&nullrec); } } if (tcount == 0) { free(*arlist); *arlist = NULL; } else (*arlist)[count] = NULL; LOG4(L_TRANS,"(%5d) getars: returns %d records, %d found\n", Logstamp,(tcount)?count:0, tcount); return((tcount)?count:0);}/* * Verify the password for machine "mach" in domain "dom" matches * the password in the password file. */vpasswd(passwd, mach, dom)char *passwd;char *mach;char *dom;{ char filename[BUFSIZ]; char buf[BUFSIZ]; char *pw; char *m_name, *m_pass, *ptr; FILE *fp; int no_pw = 0; char *crypt(); LOG5(L_TRANS,"(%5d) vpasswd: passwd=%s, mach=%s, dom=%s\n", Logstamp,passwd,mach,dom); sprintf(filename, DOMPASSWD, dom); if ((fp = fopen(filename, "r")) != NULL) { while(fgets(buf, BUFSIZ, fp) != NULL) { if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = '\0'; m_name = ptr = buf; while (*ptr != ':' && *ptr != '\0') ptr ++; if (*ptr == '\0') no_pw = 1; else { no_pw = 0; *ptr = '\0'; } if (strcmp(mach, m_name) == 0) { m_pass = no_pw? ptr: ++ptr; while (*ptr != ':' && *ptr != '\0') ptr ++; *ptr = '\0'; pw = crypt(passwd, m_pass); fclose(fp); if (strcmp(pw, m_pass) == 0) return(-1); /* correct */ else return(-2); /* incorrect */ } } fclose(fp); } else return(R_EPASS); /* * Get here is no entry in password file. */ return(R_NOPW);}changepw(newpass, mach, dom)char *newpass, *mach, *dom;{ unsigned sleep(); char filename[BUFSIZ]; char tempfile[BUFSIZ]; char buf[BUFSIZ]; char newbuf[BUFSIZ]; int i; int ret; int colon = 0; char *m_name, *ptr; FILE *fp_t; FILE *fp; LOG5(L_TRANS,"(%5d) changepw: newpass=%s, mach=%s, dom=%s\n", Logstamp,newpass,mach,dom); sprintf(filename, DOMPASSWD, dom); strcpy(tempfile, filename); strcat(tempfile, ".t"); i = 0; while (access(tempfile, 0) >= 0) { sleep(20); if (i++ > 5) return(R_EPASS); } if ((fp_t = fopen(tempfile, "w")) == NULL) { unlink(tempfile); return(R_EPASS); } ret = R_NOPW; if ((fp = fopen(filename, "r")) != NULL) { while(fgets(buf, 512, fp) != NULL) { if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = '\0'; m_name = ptr = buf; while (*ptr != ':' && *ptr != '\0') ptr ++; if (*ptr == ':') { colon = 1; *ptr = '\0'; } else { colon = 0; } if (strcmp(mach, m_name) != 0) *ptr = colon? ':' : '\0'; else { ret = R_NOERR; strcpy(newbuf, mach); strcat(newbuf, ":"); strcat(newbuf, newpass); if (colon) ++ptr; while (*ptr != ':' && *ptr != '\0') ptr ++; strcat(newbuf, ptr); strcpy(buf, newbuf); } fputs(buf, fp_t); fputs("\n", fp_t); } fclose(fp); fclose(fp_t); if (unlink(filename) || link(tempfile, filename) || unlink(tempfile)) return(R_EPASS); } return(ret);}intns_unadv(name, type, dname)char *name;int type;char *dname;{ int ret; struct res_rec **rlist; if ((rlist = findrr(name,type)) == NULL) { ret = R_NONAME; LOG4(L_TRANS,"(%5d) nsfunc: %s, no such name %s\n", Logstamp,fntype(NS_UNADV),name); } else if ((Primary && strcmp(Dname,dname) == NULL) || strcmp(rlist[0]->rr_owner,dname) == NULL) { ret = remrr(name,rlist[0]); } else { ret = R_PERM; LOG4(L_TRANS,"(%5d) nsfunc: %s, no permission to unadv %s\n", Logstamp, dname, name); } freelist(rlist); return(ret);}intns_adv(name, rec, addr)char *name;struct res_rec *rec;struct address *addr;{ int ret; struct res_rec *arec; struct res_rec **rlist; ret = addrr(name,rec); /* save address for future use */ if ((rlist=findrr(rec->rr_owner,A)) == NULL) { if ((arec=(struct res_rec *) calloc(sizeof(struct res_rec),1)) == NULL) { PLOG3("(%5d) nsfunc: calloc(%d,1) FAILED\n", Logstamp,sizeof(struct res_rec)); return(R_NSFAIL); /* give up */ } if (addr && (arec->rr_a=aatos((struct address *)NULL,addr,HEX)) != NULL) { arec->rr_type = A; strncpy(arec->rr_name, namepart(rec->rr_owner),NAMSIZ); addrr(rec->rr_owner,arec); } freerec(arec); } else freelist(rlist); return(ret);}struct request *newreq(opcode,flags,dname)int opcode;int flags;char *dname;{ struct header *nhp; struct request *nreq; if ((nreq = (struct request *)calloc(1,sizeof(struct request))) == NULL) { PLOG3("(%5d) newreq: calloc(1,%d) FAILED\n", Logstamp,sizeof(struct request)); return(NULL); } if ((nhp = (struct header *)calloc(1,sizeof(struct header))) == NULL) { PLOG3("(%5d) newreq: calloc(1,%d) FAILED\n", Logstamp,sizeof(struct header)); return(NULL); } nreq->rq_head = nhp; nhp->h_opcode = opcode; nhp->h_flags = flags; nhp->h_qdcnt = 0; nhp->h_ancnt = 0; nhp->h_nscnt = 0; nhp->h_arcnt = 0; nhp->h_dname = copystr(dname); return(nreq);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -