📄 rfadmin.c
字号:
fclose(fp); fclose(tempfp); if (!found) { fprintf(stderr, "%s: host <%s> not in password file\n", cmd_name, name); unlink(tempfile); return(1); } /* * Move the temporary password file back to the real * password file. */ if (unlink(filename) == -1 || link(tempfile, filename) == -1 || unlink(tempfile) == -1 || chmod(filename, 0600) == -1) { fprintf(stderr, "%s: error in creating new password file <%s>\n", cmd_name, filename); return(1); } return(0);}staticis_prime(mach, domain, flag)char *mach;char *domain;int flag;{ FILE *fp; char buf[BUFSIZ]; char morebuf[BUFSIZ]; char *dname, *cmd, *mname; char *ptr; int i, size; int line = 0; if ((fp = fopen(NETMASTER, "r")) == NULL) { fprintf(stderr, "%s: cannot open master file <%s>\n", cmd_name, NETMASTER); return(NO); } while (fgets(buf, sizeof(buf), fp) != NULL) { line ++; size = strlen(buf); while (buf[size-2] == '\\' && buf[size-1] == '\n') { buf[size-2] = '\0'; if (fgets(morebuf, sizeof(morebuf), fp) == NULL) { break; } if ((size = (size - 2 + strlen(morebuf))) > BUFSIZ) { fprintf("%s: warning: line %d of rfmaster too long\n", cmd_name, line); break; } strcat(buf, morebuf); } if ((dname = strtok(buf, " \t")) == NULL) continue; if ((cmd = strtok(NULL, " \t")) == NULL) continue; if ((mname = namepart(strtok(NULL, " \t\n"))) == NULL) continue; for (i = 0; cmd[i] != '\0'; i ++) cmd[i] = tolower(cmd[i]); if (flag == PRIMARY) { if ((EQ(cmd, "p") || EQ(cmd, "soa")) && (EQ(dname, domain) && EQ(mname, mach))) return(YES); } else { if ((EQ(cmd, "s") || EQ(cmd, "ns")) && (EQ(dname, domain) && EQ(mname, mach))) return(YES); } } return(NO);}staticprimary_rtn(){ struct nssend send; struct nssend *rtn; struct nssend *ns_getblock(); /* * Initialize the information structure to send to the * name server. */ send.ns_code = NS_REL; send.ns_name = NULL; send.ns_flag = 0; send.ns_type = 0; send.ns_desc = NULL; send.ns_path = NULL; send.ns_addr = NULL; send.ns_mach = NULL; /* * ns_getblock withe the given structure will tell the * name server to relinquish primary responsibility. */ if ((rtn = ns_getblock(&send)) == (struct nssend *)NULL) { if (ns_errno == R_PERM) { fprintf(stderr, "%s: not currently primary name server\n", cmd_name); return(1); } if (ns_errno == R_NONAME) { fprintf(stderr, "%s: could not relinquish primary responsibilities\n", cmd_name); fprintf(stderr, "%s: possible cause: no secondary name servers running\n", cmd_name); return(2); } nserror(cmd_name); return(1); } return(0);}staticpr_primary(){ struct nssend send; struct nssend *rtn; struct nssend *ns_getblock(); char key[MAXDNAME+1]; char *dname = getdname(); /* * Determine if RFS is running. */ if (rfs_up() != 0) { perror(cmd_name); return(1); } /* * Initialize the information structure to send to the * name server. */ if (dname == NULL) { fprintf(stderr, "%s: cannot obtain the domain name\n", cmd_name); return(1); } sprintf(key, "%s%s", dname, "."); send.ns_code = NS_FINDP; send.ns_name = key; send.ns_flag = 0; send.ns_type = 0; send.ns_desc = NULL; send.ns_path = NULL; send.ns_addr = NULL; send.ns_mach = NULL; /* * Get the name of the primary from the name server. */ if ((rtn = ns_getblock(&send)) != (struct nssend *)NULL) { printf("the acting name server for domain %s is %s\n", dname, *rtn->ns_mach); return(0); } if (ns_errno == R_INREC) { nserror(cmd_name); } else { fprintf(stderr, "%s: cannot obtain the name of the primary name server for domain <%s>\n", cmd_name, dname); } return(1);}staticchar *getdname(){ static char dname[MAXDNAME]; FILE *fp; /* * If the domain name cannot be obtained from the system, * get it from the domain file. */ if (rfsys(RF_GETDNAME, dname, MAXDNAME) < 0) { if (((fp = fopen(NSDOM,"r")) == NULL) || (fgets(dname,MAXDNAME,fp) == NULL)) return(NULL); /* * get rid of trailing newline, if there */ if (dname[strlen(dname)-1] == '\n') dname[strlen(dname)-1] = '\0'; fclose(fp); } return(dname);}staticmake_file(filename)char filename[];{ char buf[512]; char cmd[512]; char *ptr; struct stat sbuf; /* * This routine takes a file name of the form /x/y/z/w/v * and creates and executes the command * mkdir /x /x/y /x/y/z /x/y/z/w 2>/dev/null */ strncpy(buf, filename, sizeof(buf)); ptr = buf; strcpy(cmd, "mkdir "); while (*ptr != '\0') { if (*ptr == '/') { *ptr = '\0'; strcat(cmd, buf); strcat(cmd, " "); *ptr = '/'; } ptr ++; } strcat(cmd, " 2>/dev/null"); system(cmd); if (stat(filename, &sbuf) == -1) close(creat(filename, 0600)); return(stat(filename, &sbuf));}staticchar *getnewpass(name)char *name;{ char buf[10]; char saltc[2]; long salt; int flags; int insist = 0; int typerror = 0; char u_newpass[10]; char mess[80]; int c, i; char *p; char *crypt(); for (;;) { if (insist >= 3) { fprintf(stderr, "too many failures - try again\n"); return((char *)NULL); } if (typerror >= 3) { fprintf(stderr, "too many tries - try again\n"); return((char *)NULL); } sprintf(mess, "Enter password for %s:", name); strncpy(u_newpass, getpass(mess), 10); /* * The empty string is a valid password in this * situation. */ if (u_newpass[0] == '\0') { sprintf(mess, "Re-enter password for %s:", name); strncpy(buf, getpass(mess), 10); if (buf[0] == '\0') { time(&salt); salt += getpid(); saltc[0] = salt & 077; saltc[1] = (salt >> 6) & 077; for (i=0; i<2; i++) { c = saltc[i] + '.'; if (c>'9') c += 7; if (c>'Z') c += 6; saltc[i] = c; } return(crypt(u_newpass, saltc)); } fprintf(stderr, "They don't match; try again.\n"); typerror ++; continue; } /* * Make sure new password is long enough */ if (strlen(u_newpass) < MINLENGTH) { fprintf(stderr, "Password is too short - must be at least %d digits\n", MINLENGTH); insist ++; continue; } /* * Insure passwords contain at least two alpha * characters and one numeric or special character */ flags = 0; p = u_newpass; while (c = *p++) { if (isalpha(c)) { if (flags & 1) flags |= 2; else flags |= 1; } else flags |= 4; } if (flags != 7) { fprintf(stderr,"Password must contain at least two alphabetic characters and\n"); fprintf(stderr,"at least one numeric or special character.\n"); insist ++; continue; } /* * Insure password was typed correctly, user gets * three chances */ sprintf(mess, "Re-enter password for %s:", name); strncpy(buf, getpass(mess), 10); if (!EQ(buf, u_newpass)) { fprintf(stderr, "They don't match; try again.\n"); typerror ++; continue; } /* * Construct salt, then encrypt the new password */ time(&salt); salt += getpid(); saltc[0] = salt & 077; saltc[1] = (salt >> 6) & 077; for (i=0; i<2; i++) { c = saltc[i] + '.'; if (c>'9') c += 7; if (c>'Z') c += 6; saltc[i] = c; } return(crypt(u_newpass, saltc)); }}/* * Handle -o options here. * NOTE: Individual options are required to validate that the user * is super user, if necessary. *//*handle_opt(opt)int *opt;{ int tmp; if (strcmp(opt, "loopback") == 0) { if (geteuid() != 0) { fprintf(stderr, "%s: option \"%s\": must be super user\n",cmd_name, opt); return(1); } rdebug(DB_LOOPBCK); } else if (strcmp(opt, "noloopback") == 0) { if (geteuid() != 0) { fprintf(stderr, "%s: option \"%s\": must be super user\n",cmd_name, opt); return(1); } tmp = rdebug(-2); rdebug(0); rdebug(tmp & ~DB_LOOPBCK); } else if (strcmp(opt, "loopmode") == 0) { if (geteuid() != 0) { fprintf(stderr, "%s: option \"%s\": must be super user\n",cmd_name, opt); return(1); } tmp = rdebug(-2); */ /* -2 returns dudebug level *//* if (tmp & DB_LOOPBCK) printf("on\n"); else printf("off\n"); } else { fprintf(stderr,"%s: option \"%s\" not known\n",cmd_name,opt); return(1); } return(0);}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -