void factory_default( void ) { ADSL_ENV env; m_STATUS status; memset(&env, 0, sizeof(ADSL_ENV)); env.dmt_reset = FD_DMT_RESET; env.if_index = FD_INTERFACE_INDEX; strcpy(env.encap, FD_ENCAP); env.vpi = FD_VPI; env.vci = FD_VCI; env.mtu = FD_MTU; strcpy(env.ip_addr, FD_IP_ADDR); strcpy(env.netmask, FD_NETMASK); strcpy(env.root_id, FD_ROOT_ID); strcpy(env.root_pw, FD_ROOT_PW); strcpy(env.user_id, FD_USER_ID); strcpy(env.user_pw, FD_USER_PW); env.dhcp_use = FD_DHCP_USE; strcpy(env.dhcp_ip_from, FD_DHCP_IP_FROM); strcpy(env.dhcp_ip_to, FD_DHCP_IP_TO); strcpy(env.dhcp_interface, FD_DHCP_INTERFACE); strcpy(env.dhcp_netmask, FD_DHCP_NETMASK); strcpy(env.dhcp_gateway, FD_DHCP_GATEWAY); env.dhcp_lease_time = FD_DHCP_LEASE_TIME; strcpy(env.dns_primary, FD_DNS_PRIMARY); strcpy(env.dns_secondary, FD_DNS_SECONDARY); strcpy(env.ppp_id, FD_PPP_ID); strcpy(env.ppp_pw, FD_PPP_PW); env.ppp_default_route = FD_PPP_DEFAULT_ROUTE; env.ppp_mru = FD_PPP_MRU; env.ppp_mtu = FD_PPP_MTU; status = save_environment(&env); if (status != ST_OK) { m_print("Factory default saving failed! error code=%d\n", status); } }
void host_configure(void) { char **pext; HKEY key; DWORD disposition; char *u3_host_exec_path; char *u3_device_exec_path; char *u3_device_serial; char *u3_device_document_path; char wireshark_path[MAX_PATH+1]; char winpcap_path[MAX_PATH+1]; char vcredist_path[MAX_PATH+1]; char my_captures_path[MAX_PATH+1]; char reg_key[BUFSIZ]; char buffer[BUFSIZ]; int buflen = BUFSIZ; boolean hasWinPcap = FALSE; boolean hasRedist = FALSE; /* CREATE THE U3 Wireshark TYPE */ if(RegCreateKeyEx(HKEY_CLASSES_ROOT, WIRESHARK_ASSOC, 0, NULL, 0, (KEY_READ | KEY_WRITE), NULL, &key, &disposition) == ERROR_SUCCESS) { (void)RegSetValueEx(key, "", 0, REG_SZ, WIRESHARK_DESC, strlen(WIRESHARK_DESC) + 1); RegCloseKey(key); } /* compute the U3 path to wireshark */ u3_host_exec_path = getenv("U3_HOST_EXEC_PATH"); strncpy(wireshark_path, u3_host_exec_path, strlen(u3_host_exec_path) + 1); strncat(wireshark_path, U3UTIL_APPSTART, strlen(U3UTIL_APPSTART) + 1); strncpy(reg_key, WIRESHARK_ASSOC, strlen(WIRESHARK_ASSOC) + 1); strncat(reg_key, SHELL_OPEN_COMMAND, strlen(SHELL_OPEN_COMMAND) + 1); /* associate the application */ if(RegCreateKeyEx(HKEY_CLASSES_ROOT, reg_key, 0, NULL, 0, (KEY_READ | KEY_WRITE), NULL, &key, &disposition) == ERROR_SUCCESS) { (void)RegSetValueEx(key, "", 0, REG_SZ, wireshark_path, strlen(wireshark_path) + 1); RegCloseKey(key); } /* associate the icon */ strncpy(reg_key, WIRESHARK_ASSOC, strlen(WIRESHARK_ASSOC) + 1); strncat(reg_key, DEFAULT_ICON, strlen(DEFAULT_ICON) + 1); /* the icon is in the exe */ strncpy(wireshark_path, u3_host_exec_path, strlen(u3_host_exec_path) + 1); strncat(wireshark_path, WIRESHARK_EXE, strlen(WIRESHARK_EXE) + 1); strncat(wireshark_path, ",1", 3); /* associate the application */ if(RegCreateKeyEx(HKEY_CLASSES_ROOT, reg_key, 0, NULL, 0, (KEY_READ | KEY_WRITE), NULL, &key, &disposition) == ERROR_SUCCESS) { (void)RegSetValueEx(key, "", 0, REG_SZ, wireshark_path, strlen(wireshark_path) + 1); RegCloseKey(key); } /* CREATE THE FILE ASSOCIATIONS */ for(pext = extensions; *pext; pext++) associate(*pext); /* update icons */ SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0); /* START WINPCAP INSTALLATION IF NOT ALREADY INSTALLED */ if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, WINPCAP_KEY, 0, (KEY_READ), &key) == ERROR_SUCCESS) { if(RegQueryValueEx(key, WINPCAP_UNINSTALL, NULL, NULL, buffer, &buflen) == ERROR_SUCCESS) { if(buffer[0] != '\0') hasWinPcap = TRUE; } RegCloseKey(key); } if(!hasWinPcap && (MessageBox(NULL, TEXT("If you want to capture packets from the network you will need to install WinPcap.\nIt will be uninstalled when you remove your U3 device.\n\nDo you want to install WinPcap?"), TEXT("U3 Wireshark: Install WinPcap?"), MB_YESNO|MB_TOPMOST|MB_ICONQUESTION) == IDYES)) { /* compute the U3 path to the WinPcap installation package - it stays on the device */ u3_device_exec_path = getenv("U3_DEVICE_EXEC_PATH"); strncpy(winpcap_path, "\"", 2); strncat(winpcap_path, u3_device_exec_path, strlen(u3_device_exec_path) + 1); strncat(winpcap_path, WINPCAP_PACKAGE, strlen(WINPCAP_PACKAGE) + 1); strncat(winpcap_path, "\"", 2); ExecuteAndWait(winpcap_path); /* if installation was successful this key will now exist */ if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, WINPCAP_KEY, 0, (KEY_READ | KEY_WRITE), &key) == ERROR_SUCCESS) { u3_device_serial = getenv("U3_DEVICE_SERIAL"); (void)RegSetValueEx(key, WINPCAP_U3INSTALLED, 0, REG_SZ, u3_device_serial, strlen(u3_device_serial) + 1); winpcap_auto_start(); } } /* START VCREDIST INSTALLATION IF NOT ALREADY INSTALLED */ if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, VCREDIST_KEY, 0, (KEY_READ), &key) == ERROR_SUCCESS) { buflen = BUFSIZ; if(RegQueryValueEx(key, VCREDIST_UNINSTALL, NULL, NULL, buffer, &buflen) == ERROR_SUCCESS) { if(buffer[0] != '\0') hasRedist = TRUE; } RegCloseKey(key); } if(!hasRedist) { /* compute the U3 path to the Visual C++ redistributables package - it stays on the device */ u3_device_exec_path = getenv("U3_DEVICE_EXEC_PATH"); strncpy(vcredist_path, "\"", 2); strncat(vcredist_path, u3_device_exec_path, strlen(u3_device_exec_path) + 1); strncat(vcredist_path, VCREDIST_PACKAGE, strlen(VCREDIST_PACKAGE) + 1); strncat(vcredist_path, "\" /q", 5); /* do things quietly */ ExecuteAndWait(vcredist_path); if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, VCREDIST_KEY, 0, (KEY_READ | KEY_WRITE), &key) == ERROR_SUCCESS) { u3_device_serial = getenv("U3_DEVICE_SERIAL"); (void)RegSetValueEx(key, VCREDIST_U3INSTALLED, 0, REG_SZ, u3_device_serial, strlen(u3_device_serial) + 1); } } /* CREATE THE "My Captures" FOLDER IF IT DOESN'T ALREADY EXIST */ u3_device_document_path = getenv("U3_DEVICE_DOCUMENT_PATH"); strncpy(my_captures_path, u3_device_document_path, strlen(u3_device_document_path) + 1); strncat(my_captures_path, MY_CAPTURES, strlen(MY_CAPTURES) + 1); /* don't care if it succeeds or fails */ (void) CreateDirectory(my_captures_path, NULL); /* Save the environment so we can use it in the file assocation */ save_environment(); }
void CPCD::Process::do_exec() { unsigned i; #ifdef _WIN32 Vector<BaseString> saved; char *cwd = 0; save_environment(m_env.c_str(), saved); #endif setup_environment(m_env.c_str()); char **argv = BaseString::argify(m_path.c_str(), m_args.c_str()); if(strlen(m_cwd.c_str()) > 0) { #ifdef _WIN32 cwd = getcwd(0, 0); if(!cwd) { logger.critical("Couldn't getcwd before spawn"); } #endif int err = chdir(m_cwd.c_str()); if(err == -1) { BaseString err; logger.error("%s: %s\n", m_cwd.c_str(), strerror(errno)); _exit(1); } } #ifndef _WIN32 Vector<BaseString> ulimit; m_ulimit.split(ulimit); for(i = 0; i<ulimit.size(); i++){ if(ulimit[i].trim().length() > 0 && set_ulimit(ulimit[i]) != 0){ _exit(1); } } #endif const char *nul = IF_WIN("nul:", "/dev/null"); int fdnull = open(nul, O_RDWR, 0); if(fdnull == -1) { logger.error("Cannot open `%s': %s\n", nul, strerror(errno)); _exit(1); } BaseString * redirects[] = { &m_stdin, &m_stdout, &m_stderr }; int fds[3]; #ifdef _WIN32 int std_dups[3]; #endif for (i = 0; i < 3; i++) { #ifdef _WIN32 std_dups[i] = dup(i); #endif if (redirects[i]->empty()) { #ifndef DEBUG dup2(fdnull, i); #endif continue; } if((* redirects[i]) == "2>&1" && i == 2){ dup2(fds[1], 2); continue; } /** * Make file */ int flags = 0; int mode = S_IRUSR | S_IWUSR ; if(i == 0){ flags |= O_RDONLY; } else { flags |= O_WRONLY | O_CREAT | O_APPEND; } int f = fds[i]= open(redirects[i]->c_str(), flags, mode); if(f == -1){ logger.error("Cannot redirect %u to/from '%s' : %s\n", i, redirects[i]->c_str(), strerror(errno)); _exit(1); } dup2(f, i); #ifdef _WIN32 close(f); #endif } #ifndef _WIN32 /* Close all filedescriptors */ for(i = STDERR_FILENO+1; (int)i < getdtablesize(); i++) close(i); execv(m_path.c_str(), argv); /* XXX If we reach this point, an error has occurred, but it's kind of hard * to report it, because we've closed all files... So we should probably * create a new logger here */ logger.error("Exec failed: %s\n", strerror(errno)); /* NOTREACHED */ #else // Get full path to cygwins shell FILE *fpipe = _popen("sh -c 'cygpath -w `which sh`'", "rt"); char buf[MAX_PATH]; require(fgets(buf, MAX_PATH - 1, fpipe)); fclose(fpipe); BaseString sh; sh.assign(buf); sh.trim("\n"); sh.append(".exe"); BaseString shcmd; shcmd.assfmt("%s -c '%s %s'", sh.c_str(), m_path.c_str(), m_args.c_str()); PROCESS_INFORMATION pi = {0}; STARTUPINFO si = {sizeof(STARTUPINFO), 0}; si.dwFlags |= STARTF_USESTDHANDLES; si.hStdInput = (HANDLE)_get_osfhandle(0); si.hStdOutput = (HANDLE)_get_osfhandle(1); si.hStdError = (HANDLE)_get_osfhandle(2); if(!CreateProcessA(sh.c_str(), (LPSTR)shcmd.c_str(), NULL, NULL, TRUE, CREATE_SUSPENDED, // Resumed after assigned to Job NULL, NULL, &si, &pi)) { char* message; DWORD err = GetLastError(); FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&message, 0, NULL ); logger.error("CreateProcess failed, error: %d, message: '%s'", err, message); LocalFree(message); } HANDLE proc = pi.hProcess; require(proc); // Job control require(m_job = CreateJobObject(0, 0)); require(AssignProcessToJobObject(m_job, proc)); // Resum process after it has been added to Job ResumeThread(pi.hThread); CloseHandle(pi.hThread); // go back up to original cwd if(chdir(cwd)) { logger.critical("Couldn't go back to saved cwd after spawn()"); logger.critical("errno: %d, strerror: %s", errno, strerror(errno)); } free(cwd); // get back to original std i/o for(i = 0; i < 3; i++) { dup2(std_dups[i], i); close(std_dups[i]); } for (i = 0; i < saved.size(); i++) { putenv(saved[i].c_str()); } logger.debug("'%s' has been started", shcmd.c_str()); DWORD exitcode; BOOL result = GetExitCodeProcess(proc, &exitcode); //maybe a short running process if (result && exitcode != 259) { m_status = STOPPED; logger.warning("Process terminated early"); } int pid = GetProcessId(proc); if (!pid) logger.critical("GetProcessId failed, error: %d!", GetLastError()); logger.debug("new pid %d", pid); CloseHandle(proc); m_status = RUNNING; writePid(pid); #endif close(fdnull); }
int main(int argc, char **argv) { const char *av = NULL; int func_total, file_total; char arg_dbpath[MAXPATHLEN]; const char *index = NULL; int optchar; int option_index = 0; STATISTICS_TIME *tim; arg_dbpath[0] = 0; basic_check(); /* * Setup GTAGSCONF and GTAGSLABEL environment variable * according to the --gtagsconf and --gtagslabel option. */ preparse_options(argc, argv); /* * Load configuration values. */ if (!vgetcwd(cwdpath, sizeof(cwdpath))) die("cannot get current directory."); openconf(cwdpath); configuration(); /* * setup_langmap() is needed to use decide_lang(). */ setup_langmap(langmap); save_environment(argc, argv); /* * insert htags_options at the head of argv. */ setenv_from_config(); { char *env = getenv("HTAGS_OPTIONS"); if (env && *env) argv = prepend_options(&argc, argv, env); } while ((optchar = getopt_long(argc, argv, "acd:DfFghIm:nNoqst:Tvwx", long_options, &option_index)) != EOF) { switch (optchar) { case 0: /* already flags set */ break; case OPT_AUTO_COMPLETION: auto_completion = 1; if (optarg) { if (atoi(optarg) > 0) auto_completion_limit = optarg; else die("The option value of --auto-completion must be numeric."); } break; case OPT_CFLOW: call_file = optarg; break; case OPT_CALL_TREE: call_file = optarg; break; case OPT_CALLEE_TREE: callee_file = optarg; break; case OPT_CVSWEB: cvsweb_url = optarg; break; case OPT_CVSWEB_CVSROOT: cvsweb_cvsroot = optarg; break; case OPT_GTAGSCONF: case OPT_GTAGSLABEL: /* These options are already parsed in preparse_options() */ break; case OPT_INSERT_FOOTER: insert_footer = optarg; break; case OPT_INSERT_HEADER: insert_header = optarg; break; case OPT_HTML_HEADER: { STATIC_STRBUF(sb); if (!test("r", optarg)) die("file '%s' not found.", optarg); strbuf_clear(sb); loadfile(optarg, sb); html_header = strbuf_value(sb); } break; case OPT_ITEM_ORDER: item_order = optarg; break; case OPT_TABS: if (atoi(optarg) > 0) tabs = atoi(optarg); else die("--tabs option requires numeric value."); break; case OPT_NCOL: if (atoi(optarg) > 0) ncol = atoi(optarg); else die("--ncol option requires numeric value."); break; case OPT_TREE_VIEW: tree_view = 1; if (optarg) tree_view_type = optarg; break; case 'a': aflag++; break; case 'd': strlimcpy(arg_dbpath, optarg, sizeof(arg_dbpath)); break; case 'D': dynamic = 1; break; case 'f': fflag++; break; case 'F': Fflag++; break; case 'g': gflag++; break; case 'h': definition_header = AFTER_HEADER; if (optarg) { if (!strcmp(optarg, "before")) definition_header = BEFORE_HEADER; else if (!strcmp(optarg, "right")) definition_header = RIGHT_HEADER; else if (!strcmp(optarg, "after")) definition_header = AFTER_HEADER; else die("The option value of --func-header must be one of 'before', 'right' and 'after'."); } break; case 'I': Iflag++; break; case 'm': main_func = optarg; break; case 'n': nflag++; if (optarg) { if (atoi(optarg) > 0) ncol = atoi(optarg); else die("The option value of --line-number must be numeric."); } break; case 'o': other_files = 1; break; case 's': symbol = 1; break; case 'T': table_flist = 1; if (optarg) { if (atoi(optarg) > 0) flist_fields = atoi(optarg); else die("The option value of the --table-flist must be numeric."); } break; case 't': title = optarg; break; case 'q': qflag++; setquiet(); break; case 'v': vflag++; setverbose(); break; case 'w': wflag++; break; default: usage(); break; } } /* * Leaving everything to htags. * Htags selects popular options for you. */ if (suggest2) suggest = 1; if (suggest) { int gtags_not_found = 0; char dbpath[MAXPATHLEN]; aflag = Iflag = nflag = vflag = 1; setverbose(); definition_header = AFTER_HEADER; other_files = symbol = show_position = table_flist = fixed_guide = 1; if (arg_dbpath[0]) { if (!test("f", makepath(arg_dbpath, dbname(GTAGS), NULL))) gtags_not_found = 1; } else if (gtagsexist(".", dbpath, sizeof(dbpath), 0) == 0) { gtags_not_found = 1; } if (gtags_not_found) gflag = 1; } if (suggest2) { Fflag = 1; /* uses frame */ fflag = dynamic = 1; /* needs a HTTP server */ auto_completion = tree_view = 1; /* needs javascript */ } if (call_file && !test("fr", call_file)) die("cflow file not found. '%s'", call_file); if (callee_file && !test("fr", callee_file)) die("cflow file not found. '%s'", callee_file); if (insert_header && !test("fr", insert_header)) die("page header file '%s' not found.", insert_header); if (insert_footer && !test("fr", insert_footer)) die("page footer file '%s' not found.", insert_footer); if (!fflag) auto_completion = 0; argc -= optind; argv += optind; if (!av) av = (argc > 0) ? *argv : NULL; if (debug) setdebug(); settabs(tabs); /* setup tab skip */ if (qflag) { setquiet(); vflag = 0; } if (show_version) version(av, vflag); if (show_help) help(); /* * Invokes gtags beforehand. */ if (gflag) { STRBUF *sb = strbuf_open(0); strbuf_puts(sb, gtags_path); if (vflag) strbuf_puts(sb, " -v"); if (wflag) strbuf_puts(sb, " -w"); if (suggest2 && enable_idutils && usable("mkid")) strbuf_puts(sb, " -I"); if (arg_dbpath[0]) { strbuf_putc(sb, ' '); strbuf_puts(sb, arg_dbpath); } if (system(strbuf_value(sb))) die("cannot execute gtags(1) command."); strbuf_close(sb); } /* * get dbpath. */ if (arg_dbpath[0]) { strlimcpy(dbpath, arg_dbpath, sizeof(dbpath)); } else { int status = setupdbpath(0); if (status < 0) die_with_code(-status, "%s", gtags_dbpath_error); strlimcpy(dbpath, get_dbpath(), sizeof(dbpath)); } if (!title) { char *p = strrchr(cwdpath, sep); title = p ? p + 1 : cwdpath; } if (cvsweb_url && test("d", "CVS")) use_cvs_module = 1; /* * decide directory in which we make hypertext. */ if (av) { char realpath[MAXPATHLEN]; if (!test("dw", av)) die("'%s' is not writable directory.", av); if (chdir(av) < 0) die("directory '%s' not found.", av); if (!vgetcwd(realpath, sizeof(realpath))) die("cannot get current directory"); if (chdir(cwdpath) < 0) die("cannot return to original directory."); snprintf(distpath, sizeof(distpath), "%s/HTML", realpath); } else { snprintf(distpath, sizeof(distpath), "%s/HTML", cwdpath); } /* * Existence check of tag files. */ { int i; const char *path; GTOP *gtop; for (i = GPATH; i < GTAGLIM; i++) { path = makepath(dbpath, dbname(i), NULL); gtags_exist[i] = test("fr", path); } /* * Real GRTAGS includes virtual GSYMS. */ gtags_exist[GSYMS] = symbol ? 1 : 0; if (!gtags_exist[GPATH] || !gtags_exist[GTAGS] || !gtags_exist[GRTAGS]) die("GPATH, GTAGS and/or GRTAGS not found. Please reexecute htags with the -g option."); /* * version check. * Do nothing, but the version of tag file will be checked. */ gtop = gtags_open(dbpath, cwdpath, GTAGS, GTAGS_READ, 0); gtags_close(gtop); /* * Check whether GRTAGS is empty. */ gtop = gtags_open(dbpath, cwdpath, GRTAGS, GTAGS_READ, 0); if (gtags_first(gtop, NULL, 0) == NULL) grtags_is_empty = 1; gtags_close(gtop); } /* * make dbpath absolute. */ { char buf[MAXPATHLEN]; if (realpath(dbpath, buf) == NULL) die("cannot get realpath of dbpath."); strlimcpy(dbpath, buf, sizeof(dbpath)); } /* * The older version (4.8.7 or former) of GPATH doesn't have files * other than source file. The oflag requires new version of GPATH. */ if (other_files) { GFIND *gp = gfind_open(dbpath, NULL, 0, 0); if (gp->version < 2) die("GPATH is old format. Please remake it by invoking gtags(1)."); gfind_close(gp); } /* * for global(1) and gtags(1). */ set_env("GTAGSROOT", cwdpath); set_env("GTAGSDBPATH", dbpath); set_env("GTAGSLIBPATH", ""); /*------------------------------------------------------------------ * MAKE FILES *------------------------------------------------------------------ * HTML/cgi-bin/global.cgi ... CGI program (1) * HTML/cgi-bin/ghtml.cgi ... unzip script (1) * HTML/.htaccess ... skeleton of .htaccess (1) * HTML/help.html ... help file (2) * HTML/R/ ... references (3) * HTML/D/ ... definitions (3) * HTML/search.html ... search index (4) * HTML/defines.html ... definitions index (5) * HTML/defines/ ... definitions index (5) * HTML/files/ ... file index (6) * HTML/index.html ... index file (7) * HTML/mains.html ... main index (8) * HTML/null.html ... main null html (8) * HTML/S/ ... source files (9) * HTML/I/ ... include file index (9) * HTML/rebuild.sh ... rebuild script (10) * HTML/style.css ... style sheet (11) *------------------------------------------------------------------ */ /* for clean up */ signal_setup(); sethandler(clean); HTML = normal_suffix; message("[%s] Htags started", now()); init_statistics(); /* * (#) check if GTAGS, GRTAGS is the latest. */ if (get_dbpath()) message(" Using %s/GTAGS.", get_dbpath()); if (grtags_is_empty) message(" GRTAGS is empty."); if (gpath_open(dbpath, 0) < 0) die("GPATH not found."); if (!w32) { /* UNDER CONSTRUCTION */ } if (auto_completion || tree_view) { STATIC_STRBUF(sb); strbuf_clear(sb); strbuf_puts_nl(sb, "<script type='text/javascript' src='js/jquery.js'></script>"); if (auto_completion) loadfile(makepath(datadir, "gtags/jscode_suggest", NULL), sb); if (tree_view) loadfile(makepath(datadir, "gtags/jscode_treeview", NULL), sb); jscode = strbuf_value(sb); } /* * (0) make directories */ message("[%s] (0) making directories ...", now()); if (!test("d", distpath)) if (mkdir(distpath, 0777) < 0) die("cannot make directory '%s'.", distpath); make_directory_in_distpath("files"); make_directory_in_distpath("defines"); make_directory_in_distpath(SRCS); make_directory_in_distpath(INCS); make_directory_in_distpath(INCREFS); if (!dynamic) { make_directory_in_distpath(DEFS); make_directory_in_distpath(REFS); if (symbol) make_directory_in_distpath(SYMS); } if (fflag || dynamic) make_directory_in_distpath("cgi-bin"); if (Iflag) make_directory_in_distpath("icons"); if (auto_completion || tree_view) make_directory_in_distpath("js"); /* * (1) make CGI program */ if (fflag || dynamic) { char cgidir[MAXPATHLEN]; snprintf(cgidir, sizeof(cgidir), "%s/cgi-bin", distpath); message("[%s] (1) making CGI program ...", now()); if (fflag || dynamic) makeprogram(cgidir, "global.cgi", 0755); if (auto_completion) makeprogram(cgidir, "completion.cgi", 0755); makehtaccess(cgidir, ".htaccess", 0644); } else { message("[%s] (1) making CGI program ...(skipped)", now()); } if (av) { const char *path = makepath(distpath, "GTAGSROOT", NULL); FILE *op = fopen(path, "w"); if (op == NULL) die("cannot make file '%s'.", path); fputs(cwdpath, op); fputc('\n', op); fclose(op); } /* * (2) make help file */ message("[%s] (2) making help.html ...", now()); makehelp("help.html"); /* * (#) load GPATH */ load_gpath(dbpath); /* * (3) make function entries (D/ and R/) * MAKING TAG CACHE */ message("[%s] (3) making tag lists ...", now()); cache_open(); tim = statistics_time_start("Time of making tag lists"); func_total = makedupindex(); statistics_time_end(tim); message("Total %d functions.", func_total); /* * (4) search index. (search.html) */ if (Fflag && fflag) { message("[%s] (4) making search index ...", now()); makesearchindex("search.html"); } { STRBUF *defines = strbuf_open(0); STRBUF *files = strbuf_open(0); /* * (5) make definition index (defines.html and defines/) * PRODUCE @defines */ message("[%s] (5) making definition index ...", now()); tim = statistics_time_start("Time of making definition index"); func_total = makedefineindex("defines.html", func_total, defines); statistics_time_end(tim); message("Total %d functions.", func_total); /* * (6) make file index (files.html and files/) * PRODUCE @files, %includes */ message("[%s] (6) making file index ...", now()); init_inc(); tim = statistics_time_start("Time of making file index"); file_total = makefileindex("files.html", files); statistics_time_end(tim); message("Total %d files.", file_total); html_count += file_total; /* * (7) make call tree using cflow(1)'s output (cflow.html) */ if (call_file || callee_file) { message("[%s] (7) making cflow index ...", now()); tim = statistics_time_start("Time of making cflow index"); if (call_file) if (makecflowindex("call.html", call_file) < 0) call_file = NULL; if (callee_file) if (makecflowindex("callee.html", callee_file) < 0) callee_file = NULL; statistics_time_end(tim); } /* * [#] make include file index. */ message("[%s] (#) making include file index ...", now()); tim = statistics_time_start("Time of making include file index"); makeincludeindex(); statistics_time_end(tim); /* * [#] make a common part for mains.html and index.html * USING @defines @files */ message("[%s] (#) making a common part ...", now()); index = makecommonpart(title, strbuf_value(defines), strbuf_value(files)); strbuf_close(defines); strbuf_close(files); } /* * (7)make index file (index.html) */ message("[%s] (7) making index file ...", now()); makeindex("index.html", title, index); /* * (8) make main index (mains.html) */ message("[%s] (8) making main index ...", now()); makemainindex("mains.html", index); /* * (9) make HTML files (SRCS/) * USING TAG CACHE, %includes and anchor database. */ message("[%s] (9) making hypertext from source code ...", now()); tim = statistics_time_start("Time of making hypertext"); makehtml(file_total); statistics_time_end(tim); /* * (10) rebuild script. (rebuild.sh) * * Don't grant execute permission to rebuild script. */ makerebuild("rebuild.sh"); if (chmod(makepath(distpath, "rebuild.sh", NULL), 0640) < 0) die("cannot chmod rebuild script."); /* * (11) style sheet file (style.css) */ if (enable_xhtml) { char src[MAXPATHLEN]; char dist[MAXPATHLEN]; snprintf(src, sizeof(src), "%s/gtags/style.css", datadir); snprintf(dist, sizeof(dist), "%s/style.css", distpath); copyfile(src, dist); } if (auto_completion || tree_view) { char src[MAXPATHLEN]; char dist[MAXPATHLEN]; snprintf(src, sizeof(src), "%s/gtags/jquery", datadir); snprintf(dist, sizeof(dist), "%s/js", distpath); copydirectory(src, dist); snprintf(src, sizeof(src), "%s/gtags/jquery/images", datadir); snprintf(dist, sizeof(dist), "%s/js/images", distpath); copydirectory(src, dist); } message("[%s] Done.", now()); if (vflag && (fflag || dynamic || auto_completion)) { message("\n[Information]\n"); message(" o Htags was invoked with the -f, -c, -D or --auto-completion option. You should"); message(" start http server so that cgi-bin/*.cgi is executed as a CGI script."); message("\n If you are using Apache, 'HTML/.htaccess' might be helpful for you.\n"); message(" Good luck!\n"); } if (Iflag) { char src[MAXPATHLEN]; char dist[MAXPATHLEN]; snprintf(src, sizeof(src), "%s/gtags/icons", datadir); snprintf(dist, sizeof(dist), "%s/icons", distpath); copydirectory(src, dist); } gpath_close(); /* * Print statistics information. */ print_statistics(statistics); clean(); return 0; }
int main (int argc, char **argv) { pam_handle_t *pamh = NULL; const char *auth; char **env; int status; int flags; int res; int i; if (isatty (0)) errx (2, "this command is not meant to be run from the console"); if (argc != 3) errx (2, "invalid arguments to cockpit-session"); save_environment (); /* When setuid root, make sure our group is also root */ if (geteuid () == 0) { /* Never trust the environment when running setuid() */ if (getuid() != 0) { if (clearenv () != 0) err (1, "couldn't clear environment"); } /* set a minimal environment */ setenv ("PATH", "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", 1); if (setgid (0) != 0 || setuid (0) != 0) err (1, "couldn't switch permissions correctly"); } /* We should never leak our auth fd to other processes */ flags = fcntl (AUTH_FD, F_GETFD); if (flags < 0 || fcntl (AUTH_FD, F_SETFD, flags | FD_CLOEXEC)) err (1, "couldn't set auth fd flags"); auth = argv[1]; rhost = argv[2]; signal (SIGALRM, SIG_DFL); signal (SIGQUIT, SIG_DFL); signal (SIGTSTP, SIG_IGN); signal (SIGHUP, SIG_IGN); signal (SIGPIPE, SIG_IGN); /* Switch namespaces if we've been requested to do so */ maybe_nsenter (); if (strcmp (auth, "basic") == 0) pamh = perform_basic (); else if (strcmp (auth, "negotiate") == 0) pamh = perform_gssapi (); else errx (2, "unrecognized authentication method: %s", auth); for (i = 0; env_saved[i] != NULL; i++) pam_putenv (pamh, env_saved[i]); env = pam_getenvlist (pamh); if (env == NULL) errx (EX, "get pam environment failed"); if (want_session) { assert (pwd != NULL); if (initgroups (pwd->pw_name, pwd->pw_gid) < 0) err (EX, "%s: can't init groups", pwd->pw_name); signal (SIGTERM, pass_to_child); signal (SIGINT, pass_to_child); signal (SIGQUIT, pass_to_child); utmp_log (1); status = fork_session (env); utmp_log (0); signal (SIGTERM, SIG_DFL); signal (SIGINT, SIG_DFL); signal (SIGQUIT, SIG_DFL); res = pam_setcred (pamh, PAM_DELETE_CRED); if (res != PAM_SUCCESS) err (EX, "%s: couldn't delete creds: %s", pwd->pw_name, pam_strerror (pamh, res)); res = pam_close_session (pamh, 0); if (res != PAM_SUCCESS) err (EX, "%s: couldn't close session: %s", pwd->pw_name, pam_strerror (pamh, res)); } else { status = session (env); } pam_end (pamh, PAM_SUCCESS); if (WIFEXITED(status)) exit (WEXITSTATUS(status)); else if (WIFSIGNALED(status)) raise (WTERMSIG(status)); else exit (127); }