这篇教程C++ CfReadLine函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中CfReadLine函数的典型用法代码示例。如果您正苦于以下问题:C++ CfReadLine函数的具体用法?C++ CfReadLine怎么用?C++ CfReadLine使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了CfReadLine函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: VerifyUnmountint VerifyUnmount(char *name, Attributes a, Promise *pp){ char comm[CF_BUFSIZE], line[CF_BUFSIZE]; FILE *pfp; char *mountpt; mountpt = name; if (!DONTDO) { snprintf(comm, CF_BUFSIZE, "%s %s", VUNMOUNTCOMM[VSYSTEMHARDCLASS], mountpt); if ((pfp = cf_popen(comm, "r")) == NULL) { CfOut(cf_error, "", " !! Failed to open pipe from %s/n", VUNMOUNTCOMM[VSYSTEMHARDCLASS]); return 0; } CfReadLine(line, CF_BUFSIZE, pfp); if ((strstr(line, "busy")) || (strstr(line, "Busy"))) { cfPS(cf_inform, CF_INTERPT, "", pp, a, " !! The device under %s cannot be unmounted/n", mountpt); cf_pclose(pfp); return 1; } cf_pclose(pfp); } cfPS(cf_inform, CF_CHG, "", pp, a, " -> Unmounting %s to keep promise/n", mountpt); return 0;}
开发者ID:werkt,项目名称:cfengine-community,代码行数:33,
示例2: SupportsOptionstatic bool SupportsOption(const char *cmd, const char *option){ bool supports_option = false; char help_argument[] = " --help"; char help_command[strlen(cmd) + sizeof(help_argument)]; xsnprintf(help_command, sizeof(help_command), "%s%s", cmd, help_argument); FILE *fptr = cf_popen(help_command, "r", true); char *buf = NULL; size_t bufsize = 0; size_t optlen = strlen(option); while (CfReadLine(&buf, &bufsize, fptr) >= 0) { char *m_pos = buf; while ((m_pos = strstr(m_pos, option))) { // Check against false alarms, e.g. hyphenated words in normal text or an // option (say, "-M") that is part of "--M". if ((m_pos == buf || (m_pos[-1] != '-' && (isspace(m_pos[-1]) || ispunct(m_pos[-1])))) && (m_pos[optlen] == '/0' || (isspace(m_pos[optlen]) || ispunct(m_pos[optlen])))) { supports_option = true; // Break out of strstr loop, but read till the end to avoid broken pipes. break; } m_pos++; } } cf_pclose(fptr); free(buf); return supports_option;}
开发者ID:basvandervlies,项目名称:core,代码行数:35,
示例3: VerifyMountint VerifyMount(char *name, Attributes a, Promise *pp){ char comm[CF_BUFSIZE], line[CF_BUFSIZE]; FILE *pfp; char *host, *rmountpt, *mountpt; host = a.mount.mount_server; rmountpt = a.mount.mount_source; mountpt = name; if (!DONTDO) { snprintf(comm, CF_BUFSIZE, "%s %s:%s %s", GetArg0(VMOUNTCOMM[VSYSTEMHARDCLASS]), host, rmountpt, mountpt); if ((pfp = cf_popen(comm, "r")) == NULL) { CfOut(cf_error, "", " !! Failed to open pipe from %s/n", GetArg0(VMOUNTCOMM[VSYSTEMHARDCLASS])); return 0; } CfReadLine(line, CF_BUFSIZE, pfp); if (strstr(line, "busy") || strstr(line, "Busy")) { cfPS(cf_inform, CF_INTERPT, "", pp, a, " !! The device under %s cannot be mounted/n", mountpt); cf_pclose(pfp); return 1; } cf_pclose(pfp); } cfPS(cf_inform, CF_CHG, "", pp, a, " -> Mounting %s to keep promise/n", mountpt); return 0;}
开发者ID:joegen,项目名称:sipx-externals,代码行数:35,
示例4: SelectExecRegexMatchstatic int SelectExecRegexMatch(char *filename, char *crit, char *prog){ char line[CF_BUFSIZE]; FILE *pp; char buf[CF_MAXVARSIZE];// insert real value of $(this.promiser) in command ReplaceStr(prog, buf, sizeof(buf), "$(this.promiser)", filename); ReplaceStr(prog, buf, sizeof(buf), "${this.promiser}", filename); if ((pp = cf_popen(buf, "r")) == NULL) { CfOut(cf_error, "cf_popen", "Couldn't open pipe to command %s/n", buf); return false; } while (!feof(pp)) { line[0] = '/0'; CfReadLine(line, CF_BUFSIZE, pp); /* One buffer only */ if (FullTextMatch(crit, line)) { cf_pclose(pp); return true; } } cf_pclose(pp); return false;}
开发者ID:xrg,项目名称:cfengine-core,代码行数:32,
示例5: Unix_GatherProcessUsersstatic int Unix_GatherProcessUsers(struct Item **userList, int *userListSz, int *numRootProcs, int *numOtherProcs){FILE *pp;char pscomm[CF_BUFSIZE];char user[CF_MAXVARSIZE];char vbuff[CF_BUFSIZE];snprintf(pscomm,CF_BUFSIZE,"%s %s",VPSCOMM[VSYSTEMHARDCLASS],VPSOPTS[VSYSTEMHARDCLASS]);if ((pp = cf_popen(pscomm,"r")) == NULL) { return false; }CfReadLine(vbuff,CF_BUFSIZE,pp); while (!feof(pp)) { CfReadLine(vbuff,CF_BUFSIZE,pp); sscanf(vbuff,"%s",user); if (strcmp(user,"USER") == 0) { continue; } if (!IsItemIn(*userList,user)) { PrependItem(userList,user,NULL); (*userListSz)++; } if (strcmp(user,"root") == 0) { (*numRootProcs)++; } else { (*numOtherProcs)++; } }cf_pclose(pp);return true;}
开发者ID:Kegeruneku,项目名称:Cfengine-debian,代码行数:45,
示例6: VerifyMountint VerifyMount(EvalContext *ctx, char *name, Attributes a, Promise *pp){ char comm[CF_BUFSIZE], line[CF_BUFSIZE]; FILE *pfp; char *host, *rmountpt, *mountpt, *opts=NULL; host = a.mount.mount_server; rmountpt = a.mount.mount_source; mountpt = name; /* Check for options required for this mount - i.e., -o ro,rsize, etc. */ if (a.mount.mount_options) { opts = Rlist2String(a.mount.mount_options, ","); } else { opts = xstrdup(VMOUNTOPTS[VSYSTEMHARDCLASS]); } if (!DONTDO) { snprintf(comm, CF_BUFSIZE, "%s -o %s %s:%s %s", CommandArg0(VMOUNTCOMM[VSYSTEMHARDCLASS]), opts, host, rmountpt, mountpt); if ((pfp = cf_popen(comm, "r", true)) == NULL) { Log(LOG_LEVEL_ERR, "Failed to open pipe from %s", CommandArg0(VMOUNTCOMM[VSYSTEMHARDCLASS])); return 0; } ssize_t res = CfReadLine(line, CF_BUFSIZE, pfp); if (res == -1) { Log(LOG_LEVEL_ERR, "Unable to read output of mount command. (fread: %s)", GetErrorStr()); cf_pclose(pfp); return 0; } if (res != 0 && ((strstr(line, "busy")) || (strstr(line, "Busy")))) { cfPS(ctx, LOG_LEVEL_INFO, PROMISE_RESULT_INTERRUPTED, pp, a, "The device under %s cannot be mounted/n", mountpt); cf_pclose(pfp); return 1; } cf_pclose(pfp); } /* Since opts is either Rlist2String or xstrdup'd, we need to always free it */ free(opts); cfPS(ctx, LOG_LEVEL_INFO, PROMISE_RESULT_CHANGE, pp, a, "Mounting %s to keep promise/n", mountpt); return 0;}
开发者ID:ouafae31,项目名称:core,代码行数:55,
示例7: VerifyMountint VerifyMount(char *name, Attributes a, Promise *pp){ char comm[CF_BUFSIZE], line[CF_BUFSIZE]; FILE *pfp; char *host, *rmountpt, *mountpt, *opts=NULL; host = a.mount.mount_server; rmountpt = a.mount.mount_source; mountpt = name; /* Check for options required for this mount - i.e., -o ro,rsize, etc. */ if (a.mount.mount_options) { opts = Rlist2String(a.mount.mount_options, ","); } else { opts = xstrdup(VMOUNTOPTS[VSYSTEMHARDCLASS]); } if (!DONTDO) { snprintf(comm, CF_BUFSIZE, "%s -o %s %s:%s %s", GetArg0(VMOUNTCOMM[VSYSTEMHARDCLASS]), opts, host, rmountpt, mountpt); if ((pfp = cf_popen(comm, "r")) == NULL) { CfOut(cf_error, "", " !! Failed to open pipe from %s/n", GetArg0(VMOUNTCOMM[VSYSTEMHARDCLASS])); return 0; } if (CfReadLine(line, CF_BUFSIZE, pfp) == -1) { FatalError("Error in CfReadLine"); } if ((strstr(line, "busy")) || (strstr(line, "Busy"))) { cfPS(cf_inform, CF_INTERPT, "", pp, a, " !! The device under %s cannot be mounted/n", mountpt); cf_pclose(pfp); return 1; } cf_pclose(pfp); } /* Since opts is either Rlist2String or xstrdup'd, we need to always free it */ free(opts); cfPS(cf_inform, CF_CHG, "", pp, a, " -> Mounting %s to keep promise/n", mountpt); return 0;}
开发者ID:bruvik,项目名称:cfengine-core,代码行数:51,
示例8: MD5Randomstatic void MD5Random(unsigned char digest[EVP_MAX_MD_SIZE + 1]) /* Make a decent random number by crunching some system states & garbage through MD5. We can use this as a seed for pseudo random generator */{ unsigned char buffer[CF_BUFSIZE]; char pscomm[CF_BUFSIZE]; char uninitbuffer[100]; int md_len; const EVP_MD *md; EVP_MD_CTX context; FILE *pp; CfOut(cf_verbose, "", "Looking for a random number seed.../n");#ifdef HAVE_NOVA md = EVP_get_digestbyname("sha256");#else md = EVP_get_digestbyname("md5");#endif EVP_DigestInit(&context, md); CfOut(cf_verbose, "", ".../n"); snprintf(buffer, CF_BUFSIZE, "%d%d%25s", (int) CFSTARTTIME, (int) *digest, VFQNAME); EVP_DigestUpdate(&context, buffer, CF_BUFSIZE); snprintf(pscomm, CF_BUFSIZE, "%s %s", VPSCOMM[VSYSTEMHARDCLASS], VPSOPTS[VSYSTEMHARDCLASS]); if ((pp = cf_popen(pscomm, "r")) != NULL) { CfOut(cf_error, "cf_popen", "Couldn't open the process list with command %s/n", pscomm); while (!feof(pp)) { CfReadLine(buffer, CF_BUFSIZE, pp); EVP_DigestUpdate(&context, buffer, CF_BUFSIZE); } } uninitbuffer[99] = '/0'; snprintf(buffer, CF_BUFSIZE - 1, "%ld %s", time(NULL), uninitbuffer); EVP_DigestUpdate(&context, buffer, CF_BUFSIZE); cf_pclose(pp); EVP_DigestFinal(&context, digest, &md_len);}
开发者ID:fbettag,项目名称:core,代码行数:49,
示例9: VerifyUnmountPromiseResult VerifyUnmount(EvalContext *ctx, char *name, const Attributes *a, const Promise *pp){ char comm[CF_BUFSIZE]; FILE *pfp; char *mountpt; mountpt = name; PromiseResult result = PROMISE_RESULT_NOOP; if (!DONTDO) { snprintf(comm, CF_BUFSIZE, "%s %s", VUNMOUNTCOMM[VSYSTEMHARDCLASS], mountpt); if ((pfp = cf_popen(comm, "r", true)) == NULL) { Log(LOG_LEVEL_ERR, "Failed to open pipe from %s", VUNMOUNTCOMM[VSYSTEMHARDCLASS]); return result; } size_t line_size = CF_BUFSIZE; char *line = xmalloc(line_size); ssize_t res = CfReadLine(&line, &line_size, pfp); if (res == -1) { cf_pclose(pfp); free(line); if (!feof(pfp)) { Log(LOG_LEVEL_ERR, "Unable to read output of unmount command. (fread: %s)", GetErrorStr()); return result; } } else if (res > 0 && ((strstr(line, "busy")) || (strstr(line, "Busy")))) { cfPS(ctx, LOG_LEVEL_INFO, PROMISE_RESULT_INTERRUPTED, pp, a, "The device under '%s' cannot be unmounted", mountpt); result = PromiseResultUpdate(result, PROMISE_RESULT_INTERRUPTED); cf_pclose(pfp); free(line); return result; } } cfPS(ctx, LOG_LEVEL_INFO, PROMISE_RESULT_CHANGE, pp, a, "Unmounting '%s' to keep promise", mountpt); result = PromiseResultUpdate(result, PROMISE_RESULT_CHANGE); return result;}
开发者ID:basvandervlies,项目名称:core,代码行数:48,
示例10: SelectExecRegexMatchstatic bool SelectExecRegexMatch(EvalContext *ctx, char *filename, char *crit, char *prog){ // insert real value of $(this.promiser) in command char *buf_tmp = SearchAndReplace(prog, "$(this.promiser)", filename); char *buf = SearchAndReplace(buf_tmp, "${this.promiser}", filename); free(buf_tmp); FILE *pp = cf_popen(buf, "r", true); if (pp == NULL) { Log(LOG_LEVEL_ERR, "Couldn't open pipe to command '%s'. (cf_popen: %s)", buf, GetErrorStr()); free(buf); return false; } size_t line_size = CF_BUFSIZE; char *line = xmalloc(line_size); for (;;) { ssize_t res = CfReadLine(&line, &line_size, pp); if (res == -1) { if (!feof(pp)) { Log(LOG_LEVEL_ERR, "Error reading output from command '%s'. (fgets: %s)", buf, GetErrorStr()); } cf_pclose(pp); free(line); free(buf); return false; } if (FullTextMatch(ctx, crit, line)) { cf_pclose(pp); free(line); free(buf); return true; } } cf_pclose(pp); free(line); free(buf); return false;}
开发者ID:AsherBond,项目名称:core,代码行数:48,
示例11: CheckPsLineLimitationsstatic void CheckPsLineLimitations(void){#ifdef __hpux FILE *ps_fd; int ret; char limit[21]; char *buf = NULL; size_t bufsize = 0; ps_fd = fopen("/etc/default/ps", "r"); if (!ps_fd) { Log(LOG_LEVEL_VERBOSE, "Could not open '/etc/default/ps' " "to check ps line length limitations."); return; } while (true) { ret = CfReadLine(&buf, &bufsize, ps_fd); if (ret < 0) { break; } ret = sscanf(buf, "DEFAULT_CMD_LINE_WIDTH = %20[0-9]", limit); if (ret == 1) { if (atoi(limit) < 1024) { Log(LOG_LEVEL_VERBOSE, "ps line length limit is less than 1024. " "Consider adjusting the DEFAULT_CMD_LINE_WIDTH setting in /etc/default/ps " "in order to guarantee correct process matching."); } break; } } free(buf); fclose(ps_fd);#endif // __hpux}
开发者ID:atsaloli,项目名称:core,代码行数:43,
示例12: test_cfreadline_corruptedstatic void test_cfreadline_corrupted(void){ int read = 0; char output[CF_BUFSIZE] = { 0 }; FILE *fin; CreateCorruptedGarbage(FILE_NAME); fin = fopen(FILE_NAME, "r"); //test with non-empty file and valid file pointer read = CfReadLine(output, CF_BUFSIZE, fin); assert_true(read > 0); assert_string_not_equal(output, FILE_LINE); if (fin) { fclose(fin); }}
开发者ID:cduclos,项目名称:core,代码行数:19,
示例13: SelectExecRegexMatchstatic bool SelectExecRegexMatch(EvalContext *ctx, char *filename, char *crit, char *prog){ char line[CF_BUFSIZE]; FILE *pp; char buf[CF_MAXVARSIZE];// insert real value of $(this.promiser) in command ReplaceStr(prog, buf, sizeof(buf), "$(this.promiser)", filename); ReplaceStr(prog, buf, sizeof(buf), "${this.promiser}", filename); if ((pp = cf_popen(buf, "r", true)) == NULL) { Log(LOG_LEVEL_ERR, "Couldn't open pipe to command '%s'. (cf_popen: %s)", buf, GetErrorStr()); return false; } for (;;) { ssize_t res = CfReadLine(line, CF_BUFSIZE, pp); if (res == -1) { Log(LOG_LEVEL_ERR, "Error reading output from command '%s'. (fgets: %s)", buf, GetErrorStr()); cf_pclose(pp); return false; } if (res == 0) { cf_pclose(pp); return false; } if (FullTextMatch(ctx, crit, line)) { cf_pclose(pp); return true; } } cf_pclose(pp); return false;}
开发者ID:nperron,项目名称:core,代码行数:43,
示例14: PrintFilestatic bool PrintFile(const char *filename, size_t max_lines){ if (!filename) { Log(LOG_LEVEL_VERBOSE, "Printfile promise was incomplete, with no filename."); return false; } FILE *fp = safe_fopen(filename, "r"); if (!fp) { Log(LOG_LEVEL_ERR, "Printing of file '%s' was not possible. (fopen: %s)", filename, GetErrorStr()); return false; } size_t line_size = CF_BUFSIZE; char *line = xmalloc(line_size); for (size_t i = 0; i < max_lines; i++) { if (CfReadLine(&line, &line_size, fp) == -1) { if (ferror(fp)) { Log(LOG_LEVEL_ERR, "Failed to read line from stream, (getline: %s)", GetErrorStr()); free(line); return false; } else { break; } } ReportToLog(line); } fclose(fp); free(line); return true;}
开发者ID:dstam,项目名称:core,代码行数:42,
示例15: VerifyUnmountint VerifyUnmount(EvalContext *ctx, char *name, Attributes a, Promise *pp){ char comm[CF_BUFSIZE], line[CF_BUFSIZE]; FILE *pfp; char *mountpt; mountpt = name; if (!DONTDO) { snprintf(comm, CF_BUFSIZE, "%s %s", VUNMOUNTCOMM[VSYSTEMHARDCLASS], mountpt); if ((pfp = cf_popen(comm, "r", true)) == NULL) { Log(LOG_LEVEL_ERR, "Failed to open pipe from %s", VUNMOUNTCOMM[VSYSTEMHARDCLASS]); return 0; } ssize_t res = CfReadLine(line, CF_BUFSIZE, pfp); if (res == -1) { Log(LOG_LEVEL_ERR, "Unable to read output of unmount command. (fread: %s)", GetErrorStr()); cf_pclose(pfp); return 0; } if (res != 0 && ((strstr(line, "busy")) || (strstr(line, "Busy")))) { cfPS(ctx, LOG_LEVEL_INFO, PROMISE_RESULT_INTERRUPTED, pp, a, "The device under %s cannot be unmounted/n", mountpt); cf_pclose(pfp); return 1; } cf_pclose(pfp); } cfPS(ctx, LOG_LEVEL_INFO, PROMISE_RESULT_CHANGE, pp, a, "Unmounting %s to keep promise/n", mountpt); return 0;}
开发者ID:ouafae31,项目名称:core,代码行数:40,
示例16: LoadProcessTableint LoadProcessTable(EvalContext *ctx, Item **procdata){ FILE *prp; char pscomm[CF_MAXLINKSIZE], vbuff[CF_BUFSIZE], *sp; Item *rootprocs = NULL; Item *otherprocs = NULL; if (PROCESSTABLE) { Log(LOG_LEVEL_VERBOSE, "Reusing cached process table"); return true; } const char *psopts = GetProcessOptions(); snprintf(pscomm, CF_MAXLINKSIZE, "%s %s", VPSCOMM[VSYSTEMHARDCLASS], psopts); Log(LOG_LEVEL_VERBOSE, "Observe process table with %s", pscomm); if ((prp = cf_popen(pscomm, "r", false)) == NULL) { Log(LOG_LEVEL_ERR, "Couldn't open the process list with command '%s'. (popen: %s)", pscomm, GetErrorStr()); return false; } for (;;) { ssize_t res = CfReadLine(vbuff, CF_BUFSIZE, prp); if (res == 0) { break; } if (res == -1) { Log(LOG_LEVEL_ERR, "Unable to read process list with command '%s'. (fread: %s)", pscomm, GetErrorStr()); cf_pclose(prp); return false; } for (sp = vbuff + strlen(vbuff) - 1; (sp > vbuff) && (isspace((int)*sp)); sp--) { *sp = '/0'; } if (ForeignZone(vbuff)) { continue; } AppendItem(procdata, vbuff, ""); } cf_pclose(prp);/* Now save the data */ snprintf(vbuff, CF_MAXVARSIZE, "%s/state/cf_procs", CFWORKDIR); RawSaveItemList(*procdata, vbuff); CopyList(&rootprocs, *procdata); CopyList(&otherprocs, *procdata); while (DeleteItemNotContaining(ctx, &rootprocs, "root")) { } while (DeleteItemContaining(ctx, &otherprocs, "root")) { } if (otherprocs) { PrependItem(&rootprocs, otherprocs->name, NULL); } snprintf(vbuff, CF_MAXVARSIZE, "%s/state/cf_rootprocs", CFWORKDIR); RawSaveItemList(rootprocs, vbuff); DeleteItemList(rootprocs); snprintf(vbuff, CF_MAXVARSIZE, "%s/state/cf_otherprocs", CFWORKDIR); RawSaveItemList(otherprocs, vbuff); DeleteItemList(otherprocs); return true;}
开发者ID:zined,项目名称:core,代码行数:86,
示例17: GetExecOutputbool GetExecOutput(const char *command, char *buffer, bool useshell)/* Buffer initially contains whole exec string */{ int offset = 0; char line[CF_EXPANDSIZE]; FILE *pp; CfDebug("GetExecOutput(%s,%s) - use shell = %d/n", command, buffer, useshell); if (useshell) { pp = cf_popen_sh(command, "r"); } else { pp = cf_popen(command, "r", true); } if (pp == NULL) { CfOut(OUTPUT_LEVEL_ERROR, "cf_popen", "Couldn't open pipe to command %s/n", command); return false; } memset(buffer, 0, CF_EXPANDSIZE); for (;;) { ssize_t res = CfReadLine(line, CF_EXPANDSIZE, pp); if (res == 0) { break; } if (res == -1) { CfOut(OUTPUT_LEVEL_ERROR, "fread", "Unable to read output of command %s", command); cf_pclose(pp); return false; } if (strlen(line) + offset > CF_EXPANDSIZE - 10) { CfOut(OUTPUT_LEVEL_ERROR, "", "Buffer exceeded %d bytes in exec %s/n", CF_EXPANDSIZE, command); break; } snprintf(buffer + offset, CF_EXPANDSIZE, "%s/n", line); offset += strlen(line) + 1; } if (offset > 0) { if (Chop(buffer, CF_EXPANDSIZE) == -1) { CfOut(OUTPUT_LEVEL_ERROR, "", "Chop was called on a string that seemed to have no terminator"); } } CfDebug("GetExecOutput got: [%s]/n", buffer); cf_pclose(pp); return true;}
开发者ID:rpoyner,项目名称:core,代码行数:65,
示例18: LocalExec//.........这里部分代码省略......... fclose(fp); return; } CfOut(cf_verbose, "", " -> Command is executing...%s/n", esc_command); while (!feof(pp)) { if(!IsReadReady(fileno(pp), (config->agent_expireafter * SECONDS_PER_MINUTE))) { char errmsg[CF_MAXVARSIZE]; snprintf(errmsg, sizeof(errmsg), "cf-execd: !! Timeout waiting for output from agent (agent_expireafter=%d) - terminating it", config->agent_expireafter); CfOut(cf_error, "", "%s", errmsg); fprintf(fp, "%s/n", errmsg); count++; pid_t pid_agent; if(PipeToPid(&pid_agent, pp)) { ProcessSignalTerminate(pid_agent); } else { CfOut(cf_error, "", "!! Could not get PID of agent"); } break; } { ssize_t num_read = CfReadLine(line, CF_BUFSIZE, pp); if (num_read == -1) { FatalError("Cannot continue on CfReadLine error"); } else if (num_read == 0) { break; } } if(!CfReadLine(line, CF_BUFSIZE, pp)) { break; } if (ferror(pp)) { fflush(pp); break; } print = false; for (sp = line; *sp != '/0'; sp++) { if (!isspace((int) *sp)) { print = true; break; } }
开发者ID:FraserMCampbell,项目名称:core,代码行数:66,
示例19: GetLMSensorsstatic bool GetLMSensors(double *cf_this){ FILE *pp; Item *ip, *list = NULL; double temp = 0; char name[CF_BUFSIZE]; int count; cf_this[ob_temp0] = 0.0; cf_this[ob_temp1] = 0.0; cf_this[ob_temp2] = 0.0; cf_this[ob_temp3] = 0.0; if ((pp = cf_popen("/usr/bin/sensors", "r", true)) == NULL) { LMSENSORS = false; /* Broken */ return false; } { size_t vbuff_size = CF_BUFSIZE; char *vbuff = xmalloc(vbuff_size); ssize_t res = CfReadLine(&vbuff, &vbuff_size, pp); if (res <= 0) { /* FIXME: do we need to log anything here? */ cf_pclose(pp); free(vbuff); return false; } for (;;) { ssize_t res = CfReadLine(&vbuff, &vbuff_size, pp); if (res == -1) { if (!feof(pp)) { /* FIXME: Do we need to log anything here? */ cf_pclose(pp); free(vbuff); return false; } else { break; } } if (strstr(vbuff, "Temp") || strstr(vbuff, "temp")) { PrependItem(&list, vbuff, NULL); } } cf_pclose(pp); free(vbuff); } if (ListLen(list) > 0) { Log(LOG_LEVEL_DEBUG, "LM Sensors seemed to return ok data"); } else { return false; }/* lmsensor names are hopelessly inconsistent - so try a few things */ for (ip = list; ip != NULL; ip = ip->next) { for (count = 0; count < 4; count++) { snprintf(name, 16, "CPU%d Temp:", count); if (strncmp(ip->name, name, strlen(name)) == 0) { sscanf(ip->name, "%*[^:]: %lf", &temp); switch (count) { case 0: cf_this[ob_temp0] = temp; break; case 1: cf_this[ob_temp1] = temp; break; case 2: cf_this[ob_temp2] = temp; break; case 3: cf_this[ob_temp3] = temp; break; } Log(LOG_LEVEL_DEBUG, "Set temp%d to %lf from what looks like cpu temperature", count, temp); } }//.........这里部分代码省略.........
开发者ID:AsherBond,项目名称:core,代码行数:101,
示例20: LoadFileAsItemListint LoadFileAsItemList(Item **liststart, const char *file, EditDefaults edits){ { struct stat statbuf; if (stat(file, &statbuf) == -1) { Log(LOG_LEVEL_VERBOSE, "The proposed file '%s' could not be loaded. (stat: %s)", file, GetErrorStr()); return false; } if (edits.maxfilesize != 0 && statbuf.st_size > edits.maxfilesize) { Log(LOG_LEVEL_INFO, "File '%s' is bigger than the limit edit.max_file_size = %jd > %d bytes", file, (intmax_t) statbuf.st_size, edits.maxfilesize); return (false); } if (!S_ISREG(statbuf.st_mode)) { Log(LOG_LEVEL_INFO, "%s is not a plain file", file); return false; } } FILE *fp = safe_fopen(file, "r"); if (!fp) { Log(LOG_LEVEL_INFO, "Couldn't read file '%s' for editing. (fopen: %s)", file, GetErrorStr()); return false; } Buffer *concat = BufferNew(); size_t line_size = CF_BUFSIZE; char *line = xmalloc(line_size); bool result = true; for (;;) { ssize_t num_read = CfReadLine(&line, &line_size, fp); if (num_read == -1) { if (!feof(fp)) { Log(LOG_LEVEL_ERR, "Unable to read contents of '%s'. (fread: %s)", file, GetErrorStr()); result = false; } break; } if (edits.joinlines && *(line + strlen(line) - 1) == '//') { *(line + strlen(line) - 1) = '/0'; BufferAppend(concat, line, num_read); } else { BufferAppend(concat, line, num_read); if (!feof(fp) || (BufferSize(concat) > 0)) { AppendItem(liststart, BufferData(concat), NULL); } } BufferZero(concat); } free(line); BufferDestroy(concat); fclose(fp); return result;}
开发者ID:rcorrieri,项目名称:core,代码行数:75,
示例21: MountAllvoid MountAll(){ char line[CF_BUFSIZE]; FILE *pp; if (DONTDO) { CfOut(cf_verbose, "", "Promised to mount filesystem, but not on this trial run/n"); return; } else { CfOut(cf_verbose, "", " -> Attempting to mount all filesystems./n"); }#if defined(__CYGWIN__) /* This is a shell script. Make sure it hasn't been compromised. */ struct stat sb; if (cfstat("/etc/fstab", &sb) == -1) { int fd; if ((fd = creat("/etc/fstab", 0755)) > 0) { if (write(fd, "#!/bin/sh/n/n", 10) != 10) { UnexpectedError("Failed to write to file '/etc/fstab'"); } close(fd); } else { if (sb.st_mode & (S_IWOTH | S_IWGRP)) { CfOut(cf_error, "", "File /etc/fstab was insecure. Cannot mount filesystems./n"); return; } } }#endif SetTimeOut(RPCTIMEOUT); if ((pp = cf_popen(VMOUNTCOMM[VSYSTEMHARDCLASS], "r")) == NULL) { CfOut(cf_error, "cf_popen", "Failed to open pipe from %s/n", VMOUNTCOMM[VSYSTEMHARDCLASS]); return; } while (!feof(pp)) { if (ferror(pp)) /* abortable */ { CfOut(cf_inform, "ferror", "Error mounting filesystems/n"); break; } if (CfReadLine(line, CF_BUFSIZE, pp) == -1) { FatalError("Error in CfReadLine"); } if (ferror(pp)) /* abortable */ { CfOut(cf_inform, "ferror", "Error mounting filesystems/n"); break; } if ((strstr(line, "already mounted")) || (strstr(line, "exceeded")) || (strstr(line, "determined"))) { continue; } if (strstr(line, "not supported")) { continue; } if ((strstr(line, "denied")) || (strstr(line, "RPC"))) { CfOut(cf_error, "", "There was a mount error, trying to mount one of the filesystems on this host./n"); break; } if ((strstr(line, "trying")) && (!strstr(line, "NFS version 2")) && (!strstr(line, "vers 3"))) { CfOut(cf_error, "", "Attempting abort because mount went into a retry loop./n"); break; } } alarm(0); signal(SIGALRM, SIG_DFL); cf_pclose(pp);}
开发者ID:bruvik,项目名称:cfengine-core,代码行数:96,
示例22: LoadMountInfoint LoadMountInfo(Rlist **list)/* This is, in fact, the most portable way to read the mount info! *//* Depressing, isn't it? */{ FILE *pp; char buf1[CF_BUFSIZE], buf2[CF_BUFSIZE], buf3[CF_BUFSIZE]; char host[CF_MAXVARSIZE], source[CF_BUFSIZE], mounton[CF_BUFSIZE], vbuff[CF_BUFSIZE]; int i, nfs = false; for (i = 0; VMOUNTCOMM[VSYSTEMHARDCLASS][i] != ' '; i++) { buf1[i] = VMOUNTCOMM[VSYSTEMHARDCLASS][i]; } buf1[i] = '/0'; SetTimeOut(RPCTIMEOUT); if ((pp = cf_popen(buf1, "r")) == NULL) { CfOut(cf_error, "cf_popen", "Can't open %s/n", buf1); return false; } do { vbuff[0] = buf1[0] = buf2[0] = buf3[0] = source[0] = '/0'; if (ferror(pp)) /* abortable */ { CfOut(cf_error, "ferror", "Error getting mount info/n"); break; } if (CfReadLine(vbuff, CF_BUFSIZE, pp) == -1) { FatalError("Error in CfReadLine"); } if (ferror(pp)) /* abortable */ { CfOut(cf_error, "ferror", "Error getting mount info/n"); break; } if (strstr(vbuff, "nfs")) { nfs = true; } sscanf(vbuff, "%s%s%s", buf1, buf2, buf3); if ((vbuff[0] == '/0') || (vbuff[0] == '/n')) { break; } if (strstr(vbuff, "not responding")) { CfOut(cf_error, "", "%s/n", vbuff); } if (strstr(vbuff, "be root")) { CfOut(cf_error, "", "Mount access is denied. You must be root./n"); CfOut(cf_error, "", "Use the -n option to run safely."); } if ((strstr(vbuff, "retrying")) || (strstr(vbuff, "denied")) || (strstr(vbuff, "backgrounding"))) { continue; } if ((strstr(vbuff, "exceeded")) || (strstr(vbuff, "busy"))) { continue; } if (strstr(vbuff, "RPC")) { CfOut(cf_inform, "", "There was an RPC timeout. Aborting mount operations./n"); CfOut(cf_inform, "", "Session failed while trying to talk to remote host/n"); CfOut(cf_inform, "", "%s/n", vbuff); cf_pclose(pp); return false; }#if defined(__sun) || defined(__hpux) if (IsAbsoluteFileName(buf3)) { strcpy(host, "localhost"); strcpy(mounton, buf1); } else { sscanf(buf1, "%[^:]:%s", host, source); strcpy(mounton, buf1); }#elif defined(_AIX) /* skip header *///.........这里部分代码省略.........
开发者ID:bruvik,项目名称:cfengine-core,代码行数:101,
示例23: VerifyNotInFstabint VerifyNotInFstab(char *name, Attributes a, Promise *pp)/* Ensure filesystem is NOT in fstab, and return no of changes */{ char regex[CF_BUFSIZE]; char *host, *mountpt, *opts; Item *ip; if (!FSTABLIST) { if (!LoadFileAsItemList(&FSTABLIST, VFSTAB[VSYSTEMHARDCLASS], a, pp)) { CfOut(cf_error, "", "Couldn't open %s!/n", VFSTAB[VSYSTEMHARDCLASS]); return false; } else { FSTAB_EDITS = 0; } } if (a.mount.mount_options) { opts = Rlist2String(a.mount.mount_options, ","); } else { opts = xstrdup(VMOUNTOPTS[VSYSTEMHARDCLASS]); } host = a.mount.mount_server; mountpt = name; if (MatchFSInFstab(mountpt)) { if (a.mount.editfstab) {#if defined(_AIX) FILE *pfp; char line[CF_BUFSIZE], aixcomm[CF_BUFSIZE]; snprintf(aixcomm, CF_BUFSIZE, "/usr/sbin/rmnfsmnt -f %s", mountpt); if ((pfp = cf_popen(aixcomm, "r")) == NULL) { cfPS(cf_error, CF_FAIL, "", pp, a, "Failed to invoke /usr/sbin/rmnfsmnt to edit fstab"); return 0; } while (!feof(pfp)) { if (CfReadLine(line, CF_BUFSIZE, pfp) == -1) { FatalError("Error in CfReadLine"); } if (line[0] == '#') { continue; } if (strstr(line, "busy")) { cfPS(cf_inform, CF_INTERPT, "", pp, a, "The device under %s cannot be removed from %s/n", mountpt, VFSTAB[VSYSTEMHARDCLASS]); return 0; } } cf_pclose(pfp); return 0; /* ignore internal editing for aix , always returns 0 changes */#else snprintf(regex, CF_BUFSIZE, ".*[//s]+%s[//s]+.*", mountpt); for (ip = FSTABLIST; ip != NULL; ip = ip->next) { if (FullTextMatch(regex, ip->name)) { cfPS(cf_inform, CF_CHG, "", pp, a, "Deleting file system mounted on %s./n", host); // Check host name matches too? DeleteThisItem(&FSTABLIST, ip); FSTAB_EDITS++; } }#endif } } if (a.mount.mount_options) { free(opts); } return 0;}
开发者ID:bruvik,项目名称:cfengine-core,代码行数:95,
示例24: CompareResultstatic int CompareResult(const char *filename, const char *prev_file){ Log(LOG_LEVEL_VERBOSE, "Comparing files %s with %s", prev_file, filename); int rtn = 0; FILE *old_fp = safe_fopen(prev_file, "r"); FILE *new_fp = safe_fopen(filename, "r"); if (old_fp && new_fp) { const char *errptr; int erroffset; pcre_extra *regex_extra = NULL; // Match timestamps and remove them. Not Y21K safe! :-) pcre *regex = pcre_compile(LOGGING_TIMESTAMP_REGEX, PCRE_MULTILINE, &errptr, &erroffset, NULL); if (!regex) { UnexpectedError("Compiling regular expression failed"); rtn = 1; } else { regex_extra = pcre_study(regex, 0, &errptr); } while (regex) { char old_line[CF_BUFSIZE]; char new_line[CF_BUFSIZE]; char *old_msg = old_line; char *new_msg = new_line; if (CfReadLine(old_line, sizeof(old_line), old_fp) <= 0) { old_msg = NULL; } if (CfReadLine(new_line, sizeof(new_line), new_fp) <= 0) { new_msg = NULL; } if (!old_msg || !new_msg) { if (old_msg != new_msg) { rtn = 1; } break; } char *index; if (pcre_exec(regex, regex_extra, old_msg, strlen(old_msg), 0, 0, NULL, 0) >= 0) { index = strstr(old_msg, ": "); if (index != NULL) { old_msg = index + 2; } } if (pcre_exec(regex, regex_extra, new_msg, strlen(new_msg), 0, 0, NULL, 0) >= 0) { index = strstr(new_msg, ": "); if (index != NULL) { new_msg = index + 2; } } if (strcmp(old_msg, new_msg) != 0) { rtn = 1; break; } } if (regex_extra) { free(regex_extra); } free(regex); } else { /* no previous file */ rtn = 1; } if (old_fp) { fclose(old_fp); } if (new_fp) { fclose(new_fp); } if (!ThreadLock(cft_count)) { Log(LOG_LEVEL_ERR, "Severe lock error when mailing in exec"); return 1; }//.........这里部分代码省略.........
开发者ID:gc3-uzh-ch,项目名称:cfengine,代码行数:101,
示例25: LoadProcessTableint LoadProcessTable(){ FILE *prp; char pscomm[CF_MAXLINKSIZE]; Item *rootprocs = NULL; Item *otherprocs = NULL; if (PROCESSTABLE) { Log(LOG_LEVEL_VERBOSE, "Reusing cached process table"); return true; } LoadPlatformExtraTable(); CheckPsLineLimitations(); const char *psopts = GetProcessOptions(); snprintf(pscomm, CF_MAXLINKSIZE, "%s %s", VPSCOMM[VPSHARDCLASS], psopts); Log(LOG_LEVEL_VERBOSE, "Observe process table with %s", pscomm); if ((prp = cf_popen(pscomm, "r", false)) == NULL) { Log(LOG_LEVEL_ERR, "Couldn't open the process list with command '%s'. (popen: %s)", pscomm, GetErrorStr()); return false; } size_t vbuff_size = CF_BUFSIZE; char *vbuff = xmalloc(vbuff_size);# ifdef HAVE_GETZONEID char *names[CF_PROCCOLS]; int start[CF_PROCCOLS]; int end[CF_PROCCOLS]; Seq *pidlist = SeqNew(1, NULL); Seq *rootpidlist = SeqNew(1, NULL); bool global_zone = IsGlobalZone(); if (global_zone) { int res = ZLoadProcesstable(pidlist, rootpidlist); if (res == false) { Log(LOG_LEVEL_ERR, "Unable to load solaris zone process table."); return false; } }# endif ARG_UNUSED bool header = true; /* used only if HAVE_GETZONEID */ for (;;) { ssize_t res = CfReadLine(&vbuff, &vbuff_size, prp); if (res == -1) { if (!feof(prp)) { Log(LOG_LEVEL_ERR, "Unable to read process list with command '%s'. (fread: %s)", pscomm, GetErrorStr()); cf_pclose(prp); free(vbuff); return false; } else { break; } } Chop(vbuff, vbuff_size);# ifdef HAVE_GETZONEID if (global_zone) { if (header) { /* this is the banner so get the column header names for later use*/ GetProcessColumnNames(vbuff, &names[0], start, end); } else { int gpid = ExtractPid(vbuff, names, end); if (!IsGlobalProcess(gpid, pidlist, rootpidlist)) { continue; } } }# endif AppendItem(&PROCESSTABLE, vbuff, ""); header = false; }//.........这里部分代码省略.........
开发者ID:atsaloli,项目名称:core,代码行数:101,
示例26: GetAIXShadowHash/* * Format of passwd file on AIX is: * * user1: * password = hash * lastupdate = 12783612 * user2: * password = hash * lastupdate = 12783612 * <...> */static bool GetAIXShadowHash(const char *puser, const char **result){ FILE *fptr = fopen("/etc/security/passwd", "r"); if (fptr == NULL) { return false; } // Not super pretty with a static variable, but it is how POSIX functions // getspnam() and friends do it. static char hash_buf[CF_BUFSIZE]; bool ret = false; char *buf = NULL; size_t bufsize = 0; size_t puser_len = strlen(puser); char name_regex_str[strlen(puser) + 3]; pcre *name_regex = CompileRegex("^(//S+):"); pcre *hash_regex = CompileRegex("^//s+password//s*=//s*(//S+)"); bool in_user_section = false; while (true) { ssize_t read_result = CfReadLine(&buf, &bufsize, fptr); if (read_result < 0) { if (feof(fptr)) { errno = 0; } goto end; } int submatch_vec[6]; int pcre_result = pcre_exec(name_regex, NULL, buf, strlen(buf), 0, 0, submatch_vec, 6); if (pcre_result >= 0) { if (submatch_vec[3] - submatch_vec[2] == puser_len && strncmp(buf + submatch_vec[2], puser, puser_len) == 0) { in_user_section = true; } else { in_user_section = false; } continue; } else if (pcre_result != PCRE_ERROR_NOMATCH) { errno = EINVAL; goto end; } if (!in_user_section) { continue; } pcre_result = pcre_exec(hash_regex, NULL, buf, strlen(buf), 0, 0, submatch_vec, 6); if (pcre_result >= 0) { memcpy(hash_buf, buf + submatch_vec[2], submatch_vec[3] - submatch_vec[2]); *result = hash_buf; ret = true; goto end; } else if (pcre_result != PCRE_ERROR_NOMATCH) { errno = EINVAL; goto end; } }end: pcre_free(name_regex); pcre_free(hash_regex); free(buf); fclose(fptr); return ret;}
开发者ID:basvandervlies,项目名称:core,代码行数:94,
示例27: LoadMountInfoint LoadMountInfo(Rlist **list)/* This is, in fact, the most portable way to read the mount info! *//* Depressing, isn't it? */{ FILE *pp; char buf1[CF_BUFSIZE], buf2[CF_BUFSIZE], buf3[CF_BUFSIZE]; char host[CF_MAXVARSIZE], source[CF_BUFSIZE], mounton[CF_BUFSIZE], vbuff[CF_BUFSIZE]; int i, nfs = false; for (i = 0; VMOUNTCOMM[VSYSTEMHARDCLASS][i] != ' '; i++) { buf1[i] = VMOUNTCOMM[VSYSTEMHARDCLASS][i]; } buf1[i] = '/0'; SetTimeOut(RPCTIMEOUT); if ((pp = cf_popen(buf1, "r")) == NULL) { CfOut(cf_error, "cf_popen", "Can't open %s/n", buf1); return false; } do { vbuff[0] = buf1[0] = buf2[0] = buf3[0] = source[0] = '/0'; if (ferror(pp)) /* abortable */ { CfOut(cf_error, "ferror", "Error getting mount info/n"); break; } CfReadLine(vbuff, CF_BUFSIZE, pp); if (ferror(pp)) /* abortable */ { CfOut(cf_error, "ferror", "Error getting mount info/n"); break; } if (strstr(vbuff, "nfs")) { nfs = true; } sscanf(vbuff, "%s%s%s", buf1, buf2, buf3); if ((vbuff[0] == '/0') || (vbuff[0] == '/n')) { break; } if (strstr(vbuff, "not responding")) { CfOut(cf_error, "", "%s/n", vbuff); } if (strstr(vbuff, "be root")) { CfOut(cf_error, "", "Mount access is denied. You must be root./n"); CfOut(cf_error, "", "Use the -n option to run safely."); } if ((strstr(vbuff, "retrying")) || (strstr(vbuff, "denied")) || (strstr(vbuff, "backgrounding"))) { continue; } if ((strstr(vbuff, "exceeded")) || (strstr(vbuff, "busy"))) { continue; } if (strstr(vbuff, "RPC")) { CfOut(cf_inform, "", "There was an RPC timeout. Aborting mount operations./n"); CfOut(cf_inform, "", "Session failed while trying to talk to remote host/n"); CfOut(cf_inform, "", "%s/n", vbuff); cf_pclose(pp); return false; } switch (VSYSTEMHARDCLASS) { case darwin: case linuxx: case unix_sv: case freebsd: case netbsd: case openbsd: case qnx: case crayos: case dragonfly: if (IsAbsoluteFileName(buf1)) { strcpy(host, "localhost"); strcpy(mounton, buf3); }//.........这里部分代码省略.........
开发者ID:werkt,项目名称:cfengine-community,代码行数:101,
示例28: MonNetworkGatherDatavoid MonNetworkGatherData(double *cf_this){ FILE *pp; char local[CF_BUFSIZE], remote[CF_BUFSIZE], comm[CF_BUFSIZE]; Item *in[ATTR], *out[ATTR]; char *sp; int i; char vbuff[CF_BUFSIZE]; enum cf_netstat_type { cfn_new, cfn_old } type = cfn_new; enum cf_packet_type { cfn_tcp4, cfn_tcp6 } packet = cfn_tcp4; CfDebug("GatherSocketData()/n"); for (i = 0; i < ATTR; i++) { in[i] = out[i] = NULL; } DeleteItemList(ALL_INCOMING); ALL_INCOMING = NULL; sscanf(VNETSTAT[VSYSTEMHARDCLASS], "%s", comm); strcat(comm, " -an"); if ((pp = cf_popen(comm, "r")) == NULL) { return; } while (!feof(pp)) { memset(local, 0, CF_BUFSIZE); memset(remote, 0, CF_BUFSIZE); CfReadLine(vbuff, CF_BUFSIZE, pp); if (strstr(vbuff, "UNIX")) { break; } if (!(strstr(vbuff, ":") || strstr(vbuff, "."))) { continue; } /* Different formats here ... ugh.. pick a model */ // If this is old style, we look for chapter headings, e.g. "TCP: IPv4" if (strncmp(vbuff,"TCP:",4) == 0 && strstr(vbuff+4,"6")) { packet = cfn_tcp6; type = cfn_old; continue; } else if (strncmp(vbuff,"TCP:",4) == 0 && strstr(vbuff+4,"4")) { packet = cfn_tcp4; type = cfn_old; continue; } // Line by line state in modern/linux output if (strncmp(vbuff,"tcp6",4) == 0) { packet = cfn_tcp6; type = cfn_new; } else if (strncmp(vbuff,"tcp",3) == 0) { packet = cfn_tcp4; type = cfn_new; } // End extract type switch (type) { case cfn_new: sscanf(vbuff, "%*s %*s %*s %s %s", local, remote); /* linux-like */ break; case cfn_old: sscanf(vbuff, "%s %s", local, remote); break; } if (strlen(local) == 0) { continue; } // Extract the port number from the end of the string for (sp = local + strlen(local); (*sp != '.') && (*sp != ':') && (sp > local); sp--) { }//.........这里部分代码省略.........
开发者ID:dnaeon,项目名称:core,代码行数:101,
示例29: ChangePasswordHashUsingLckpwdfstatic bool ChangePasswordHashUsingLckpwdf(const char *puser, const char *password){ bool result = false; struct stat statbuf; const char *passwd_file = "/etc/shadow"; if (stat(passwd_file, &statbuf) == -1) { passwd_file = "/etc/passwd"; } Log(LOG_LEVEL_VERBOSE, "Changing password hash for user '%s' by editing '%s'.", puser, passwd_file); if (lckpwdf() != 0) { Log(LOG_LEVEL_ERR, "Not able to obtain lock on password database."); return false; } char backup_file[strlen(passwd_file) + strlen(".cf-backup") + 1]; xsnprintf(backup_file, sizeof(backup_file), "%s.cf-backup", passwd_file); unlink(backup_file); char edit_file[strlen(passwd_file) + strlen(".cf-edit") + 1]; xsnprintf(edit_file, sizeof(edit_file), "%s.cf-edit", passwd_file); unlink(edit_file); if (!CopyRegularFileDisk(passwd_file, backup_file)) { Log(LOG_LEVEL_ERR, "Could not back up existing password database '%s' to '%s'.", passwd_file, backup_file); goto unlock_passwd; } FILE *passwd_fd = fopen(passwd_file, "r"); if (!passwd_fd) { Log(LOG_LEVEL_ERR, "Could not open password database '%s'. (fopen: '%s')", passwd_file, GetErrorStr()); goto unlock_passwd; } int edit_fd_int = open(edit_file, O_WRONLY | O_CREAT | O_EXCL, S_IWUSR); if (edit_fd_int < 0) { if (errno == EEXIST) { Log(LOG_LEVEL_CRIT, "Temporary file already existed when trying to open '%s'. (open: '%s') " "This should NEVER happen and could mean that someone is trying to break into your system!!", edit_file, GetErrorStr()); } else { Log(LOG_LEVEL_ERR, "Could not open password database temporary file '%s'. (open: '%s')", edit_file, GetErrorStr()); } goto close_passwd_fd; } FILE *edit_fd = fdopen(edit_fd_int, "w"); if (!edit_fd) { Log(LOG_LEVEL_ERR, "Could not open password database temporary file '%s'. (fopen: '%s')", edit_file, GetErrorStr()); close(edit_fd_int); goto close_passwd_fd; } while (true) { size_t line_size = 0; char *line = NULL; int read_result = CfReadLine(&line, &line_size, passwd_fd); if (read_result < 0) { if (!feof(passwd_fd)) { Log(LOG_LEVEL_ERR, "Error while reading password database: %s", GetErrorStr()); free(line); goto close_both; } else { break; } } // Editing the password database is risky business, so do as little parsing as possible. // Just enough to get the hash in there. char *field_start = NULL; char *field_end = NULL; field_start = strchr(line, ':'); if (field_start) { field_end = strchr(field_start + 1, ':'); } if (!field_start || !field_end) { Log(LOG_LEVEL_ERR, "Unexpected format found in password database while editing user '%s'. Not updating.", puser); free(line); goto close_both; } // Worst case length: Existing password is empty plus one '/n' and one '/0'.//.........这里部分代码省略.........
开发者ID:basvandervlies,项目名称:core,代码行数:101,
示例30: IsReadReady//.........这里部分代码省略......... fclose(fp); return; } Log(LOG_LEVEL_VERBOSE, "Command is executing...%s", esc_command); int count = 0; for (;;) { if(!IsReadReady(fileno(pp), (config->agent_expireafter * SECONDS_PER_MINUTE))) { char errmsg[CF_MAXVARSIZE]; snprintf(errmsg, sizeof(errmsg), "cf-execd: !! Timeout waiting for output from agent (agent_expireafter=%d) - terminating it", config->agent_expireafter); Log(LOG_LEVEL_ERR, "%s", errmsg); fprintf(fp, "%s/n", errmsg); count++; pid_t pid_agent; if(PipeToPid(&pid_agent, pp)) { ProcessSignalTerminate(pid_agent); } else { Log(LOG_LEVEL_ERR, "Could not get PID of agent"); } break; } ssize_t res = CfReadLine(line, CF_BUFSIZE, pp); if (res == 0) { break; } if (res == -1) { Log(LOG_LEVEL_ERR, "Unable to read output from command '%s'. (cfread: %s)", cmd, GetErrorStr()); cf_pclose(pp); return; } bool print = false; for (const char *sp = line; *sp != '/0'; sp++) { if (!isspace((int) *sp)) { print = true; break; } } if (print) { char line_escaped[sizeof(line) * 2]; // we must escape print format chars (%) from output ReplaceStr(line, line_escaped, sizeof(line_escaped), "%", "%%");
开发者ID:gc3-uzh-ch,项目名称:cfengine,代码行数:66,
注:本文中的CfReadLine函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ Ch函数代码示例 C++ CfOut函数代码示例 |