static int authenticate_to_floppyd(char fullauth, int sock, char *display, int protoversion) { off_t filelen=0; Byte buf[16]; const char *command[] = { "xauth", "xauth", "extract", "-", 0, 0 }; char *xcookie = NULL; Dword errcode; int bytesRead; if (fullauth) { command[4] = display; filelen=strlen(display); filelen += 100; xcookie = (char *) safe_malloc(filelen+4); filelen = safePopenOut(command, xcookie+4, filelen); if(filelen < 1) return AUTH_AUTHFAILED; } dword2byte(4,buf); dword2byte(protoversion,buf+4); write(sock, buf, 8); bytesRead = read_dword(sock); if (bytesRead != 4 && bytesRead != 12) { return AUTH_WRONGVERSION; } errcode = read_dword(sock); if (errcode != AUTH_SUCCESS) { return errcode; } if(bytesRead == 8) { protoversion = read_dword(sock); read_dword(sock); } fprintf(stderr, "Protocol Version=%d\n", protoversion); if (fullauth) { dword2byte(filelen, (Byte *) xcookie); write(sock, xcookie, filelen+4); if (read_dword(sock) != 4) { return AUTH_PACKETOVERSIZE; } errcode = read_dword(sock); } return errcode; }
const char *expand(const char *input, char *ans) { int last; char buf[256]; char *command[] = { "/bin/sh", "sh", "-c", 0, 0 }; ans[EXPAND_BUF-1]='\0'; if (input == NULL) return(NULL); if (*input == '\0') return(""); /* any thing to expand? */ if (!strpbrk(input, "$*(){}[]\\?`~")) { strncpy(ans, input, EXPAND_BUF-1); return(ans); } /* popen an echo */ #ifdef HAVE_SNPRINTF snprintf(buf, 255, "echo %s", input); #else sprintf(buf, "echo %s", input); #endif command[3]=buf; last=safePopenOut(command, ans, EXPAND_BUF-1); if(last<0) { perror("Pipe read error"); exit(1); } if(last) ans[last-1] = '\0'; else strncpy(ans, input, EXPAND_BUF-1); return ans; }