/*#include #include #include #include */ #include "xendpw.h" char *get_default_vnc_passwd(){ FILE *fp = fopen("/etc/xen/xend-config.sxp", "r"); char line[1024]; char *passwd = NULL; /* error checking */ if ( fp ) { while ( fgets(line, 1024, fp) != NULL ) { char *entry = NULL; if(!strstr(line, "vncpasswd")) continue; entry = strstr(line, "("); if(!entry) continue; else{ //fprintf(stderr, "line: %s", &line); //fprintf(stderr, "entry: %s", entry); int len = entry-line; if(len != 0){ char *substring = (char*)malloc(sizeof(char)*len); memset(substring, 0, sizeof(char)*len); strncpy(substring, line, len); //fprintf(stderr, "substring (%s)\n\n", substring); if(strstr(substring, "#")){ free(substring); //fprintf(stderr, "comment found, moving on\n"); continue; } free(substring); } else { //fprintf(stderr, "no comment involved\n\n"); } char *data = NULL; data = strstr(entry, "'"); if(data && data[1] != '\''){ char *end = strrchr(data, '\''); int passlen = end-data; passwd = (char *)malloc(sizeof(char)*passlen+1); //move it past initial quote and //adjust length for previous operation strncpy(passwd, data+1, passlen-1); passwd[passlen] = 0; break; } data = strstr(entry, "\""); if(data && data[1] != '"'){ char *end = strrchr(data, '"'); int passlen = end-data; passwd = (char *)malloc(sizeof(char)*passlen+1); //move it past initial quote and //adjust length for previous operation strncpy(passwd, data+1, passlen-1); passwd[passlen] = 0; break; } passwd = strdup("not set"); break; } } } return passwd; }