/*********************************************************************** * LaunchINFSectionExW (ADVPACK.@) * * Installs an INF section with BACKUP/ROLLBACK capabilities. * * PARAMS * hWnd [I] Handle to parent window, NULL for desktop. * hInst [I] Instance of the process. * cmdline [I] Contains parameters in the order INF,section,CAB,flags,reboot. * show [I] How the window should be shown. * * RETURNS * Success: ADV_SUCCESS. * Failure: ADV_FAILURE. * * NOTES * INF - Filename of the INF to launch. * section - INF section to install. * flags - see advpub.h. * reboot - smart reboot behavior * 'A' Always reboot. * 'I' Reboot if needed (default). * 'N' No reboot. * * BUGS * Doesn't handle the reboot flag. */ HRESULT WINAPI LaunchINFSectionExW(HWND hWnd, HINSTANCE hInst, LPWSTR cmdline, INT show) { LPWSTR cmdline_copy, cmdline_ptr; LPWSTR flags, ptr; CABINFOW cabinfo; HRESULT hr; TRACE("(%p, %p, %s, %d)\n", hWnd, hInst, debugstr_w(cmdline), show); if (!cmdline) return ADV_FAILURE; cmdline_copy = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(cmdline) + 1) * sizeof(WCHAR)); cmdline_ptr = cmdline_copy; lstrcpyW(cmdline_copy, cmdline); cabinfo.pszInf = get_parameter(&cmdline_ptr, ',', TRUE); cabinfo.pszSection = get_parameter(&cmdline_ptr, ',', TRUE); cabinfo.pszCab = get_parameter(&cmdline_ptr, ',', TRUE); *cabinfo.szSrcPath = '\0'; flags = get_parameter(&cmdline_ptr, ',', TRUE); if (flags) cabinfo.dwFlags = atolW(flags); if (!is_full_path(cabinfo.pszCab) && !is_full_path(cabinfo.pszInf)) { HeapFree(GetProcessHeap(), 0, cmdline_copy); return E_INVALIDARG; } /* get the source path from the cab filename */ if (cabinfo.pszCab && *cabinfo.pszCab) { if (!is_full_path(cabinfo.pszCab)) lstrcpyW(cabinfo.szSrcPath, cabinfo.pszInf); else lstrcpyW(cabinfo.szSrcPath, cabinfo.pszCab); ptr = strrchrW(cabinfo.szSrcPath, '\\'); *(++ptr) = '\0'; } hr = ExecuteCabW(hWnd, &cabinfo, NULL); HeapFree(GetProcessHeap(), 0, cmdline_copy); return SUCCEEDED(hr) ? ADV_SUCCESS : ADV_FAILURE; }
/** @fn int parse_at_list(char *list, int use_count, int abs_path) * @brief parse a comma-separated list of name[@host] items * * @param[in] list * @param[out] use_count if true, make sure no host is repeated * in the list, and host is defaulted only * once * @param[out] abs_path if true, make sure the item appears to * begin with an absolute path name * * @return int * @retval 1 parsing failure * @retval 0 success * @par MT-Safe: no * @par Side Effects: * exits with return code 1 on memory allocation failure */ int parse_at_list(char *list, int use_count, int abs_path) { char *b, *c, *s, *list_dup; int rc = 0; char user[MAXPATHLEN+1]; char host[PBS_MAXSERVERNAME]; struct hostlist *ph, *nh, *hostlist = NULL; if ((list == NULL) || (*list == '\0')) return 1; #ifdef WIN32 back2forward_slash(list); /* "\" translate to "/" for path */ #endif if ((list_dup = strdup(list)) == NULL) { fprintf(stderr, "Out of memory.\n"); return 1; } for (c = list_dup; *c != '\0'; rc = 0) { rc = 1; /* Drop leading white space */ while (isspace(*c)) c++; /* If requested, is this an absolute path */ if (abs_path && !is_full_path(c)) break; /* Find the next comma */ for (s = c; *c && *c != ','; c++) ; /* Drop any trailing blanks */ for (b = c - 1; (b >= list_dup) && isspace(*b); b--) *b = '\0'; /* Make sure the list does not end with a comma */ if (*c == ',') { *c++ = '\0'; if (*c == '\0') break; } /* Parse the individual list item */ if (parse_at_item(s, user, host)) break; /* The user part must be given */ if (*user == '\0') break; /* If requested, make sure the host name is not repeated */ if (use_count) { ph = hostlist; while (ph) { if (strcmp(ph->host, host) == 0) goto duplicate; ph = ph->next; } nh = (struct hostlist *) malloc(sizeof(struct hostlist)); if (nh == NULL) { fprintf(stderr, "Out of memory\n"); return 1; } nh->next = hostlist; strcpy(nh->host, host); hostlist = nh; } } duplicate: /* Release memory for hostlist and argument list */ ph = hostlist; while (ph) { nh = ph->next; free(ph); ph = nh; } free(list_dup); return rc; }
static UINT search_directory( MSIPACKAGE *package, MSISIGNATURE *sig, const WCHAR *path, int depth, WCHAR **appValue ) { UINT rc; DWORD attr; LPWSTR val = NULL; TRACE("%p, %p, %s, %d, %p\n", package, sig, debugstr_w(path), depth, appValue); if (is_full_path( path )) { if (sig->File) rc = recurse_search_directory( package, &val, sig, path, depth ); else { /* Recursively searching a directory makes no sense when the * directory to search is the thing you're trying to find. */ rc = check_directory( package, path, &val ); } } else { WCHAR pathWithDrive[MAX_PATH] = { 'C',':','\\',0 }; DWORD drives = GetLogicalDrives(); int i; rc = ERROR_SUCCESS; for (i = 0; rc == ERROR_SUCCESS && !val && i < 26; i++) { if (!(drives & (1 << i))) continue; pathWithDrive[0] = 'A' + i; if (GetDriveTypeW(pathWithDrive) != DRIVE_FIXED) continue; lstrcpynW(pathWithDrive + 3, path, ARRAY_SIZE(pathWithDrive) - 3); if (sig->File) rc = recurse_search_directory( package, &val, sig, pathWithDrive, depth ); else rc = check_directory( package, pathWithDrive, &val ); } } attr = msi_get_file_attributes( package, val ); if (attr != INVALID_FILE_ATTRIBUTES && (attr & FILE_ATTRIBUTE_DIRECTORY) && val && val[lstrlenW(val) - 1] != '\\') { val = msi_realloc(val, (lstrlenW(val) + 2) * sizeof(WCHAR)); if (!val) rc = ERROR_OUTOFMEMORY; else PathAddBackslashW(val); } *appValue = val; TRACE("returning %d\n", rc); return rc; }
void read_cfg(const char* file) { memset(&conf,0,sizeof(conf)); FILE *fp; fp=fopen(file,"r"); if(!fp) { fprintf(stderr,"Can not read config file : %s\n",file); exit(EXIT_FAILURE); } char *line=NULL; size_t len=0; char port[6]; char uid[10]; char size[10]; memset(port,0,6); memset(uid,0,10); memset(size,0,10); while(getline(&line,&len,fp)!=-1) { get_cfg_str(line,conf.hostname, "hostname=",256); get_cfg_str(line,conf.tagname, "tagname=",64); get_cfg_str(line,conf.mountpoint, "mountpoint=",1024); get_cfg_val(line,&conf.allow_other, "allow_other=on"); get_cfg_val(line,&conf.default_permissions, "default_permissions=on"); get_cfg_val(line,&conf.nonempty, "nonempty=on"); get_cfg_str(line,conf.db_host, "db_host=",256); get_cfg_str(line,port, "db_port=",6); get_cfg_str(line,conf.db_database, "db_database=",64); get_cfg_str(line,conf.db_username, "db_username="******"db_password="******"db_table=",64); get_cfg_str(line,conf.db_dump_table, "db_dump_table=",64); get_cfg_str(line,conf.db_error_table, "db_error_table=",64); get_cfg_val(line,&conf.enable_error_messages, "enable_error_messages=on"); get_cfg_val(line,&conf.enable_write_dump, "enable_write_dump=on"); get_cfg_str(line,uid, "write_dump_effective_uid=",10); get_cfg_str(line,size, "write_dump_size_less_than=",10); get_cfg_str(line,conf.dump_cmd, "write_dump_cmd=",1024); get_cfg_val(line,&conf.syscall_getattr, "syscall_getattr=on"); get_cfg_val(line,&conf.syscall_access, "syscall_access=on"); get_cfg_val(line,&conf.syscall_readlink, "syscall_readlink=on"); get_cfg_val(line,&conf.syscall_readdir, "syscall_readdir=on"); get_cfg_val(line,&conf.syscall_mknod, "syscall_mknod=on"); get_cfg_val(line,&conf.syscall_mkdir, "syscall_mkdir=on"); get_cfg_val(line,&conf.syscall_unlink, "syscall_unlink=on"); get_cfg_val(line,&conf.syscall_rmdir, "syscall_rmdir=on"); get_cfg_val(line,&conf.syscall_symlink, "syscall_symlink=on"); get_cfg_val(line,&conf.syscall_rename, "syscall_rename=on"); get_cfg_val(line,&conf.syscall_link, "syscall_link=on"); get_cfg_val(line,&conf.syscall_chmod, "syscall_chmod=on"); get_cfg_val(line,&conf.syscall_chown, "syscall_chown=on"); get_cfg_val(line,&conf.syscall_truncate, "syscall_truncate=on"); #ifdef HAVE_UTIMENSAT get_cfg_val(line,&conf.syscall_utimens, "syscall_utimens=on"); #endif get_cfg_val(line,&conf.syscall_open, "syscall_open=on"); get_cfg_val(line,&conf.syscall_read, "syscall_read=on"); get_cfg_val(line,&conf.syscall_write, "syscall_write=on"); get_cfg_val(line,&conf.syscall_statfs, "syscall_statfs=on"); #ifdef HAVE_POSIX_FALLOCATE get_cfg_val(line,&conf.syscall_fallocate, "syscall_fallocate=on"); #endif #ifdef HAVE_SETXATTR get_cfg_val(line,&conf.syscall_setxattr, "syscall_setxattr=on"); get_cfg_val(line,&conf.syscall_getxattr, "syscall_getxattr=on"); get_cfg_val(line,&conf.syscall_listxattr, "syscall_listxattr=on"); get_cfg_val(line,&conf.syscall_removexattr, "syscall_removexattr=on"); #endif get_cfg_val(line,&conf.log_username, "log_username=on"); get_cfg_val(line,&conf.log_groupname, "log_groupname=on"); get_cfg_val(line,&conf.log_tty, "log_tty=on"); get_cfg_val(line,&conf.log_login_time, "log_login_time=on"); get_cfg_val(line,&conf.log_remote_host, "log_remote_host=on"); get_cfg_val(line,&conf.log_cmd, "log_cmd=on"); get_cfg_val(line,&conf.log_args, "log_args=on"); get_cfg_val(line,&conf.log_ppid, "log_ppid=on"); get_cfg_val(line,&conf.log_ppid_cmd, "log_ppid_cmd=on"); } fclose(fp); free(line); if(!is_str(conf.hostname)) { if(gethostname(conf.hostname,256)==-1) memset(conf.hostname,0,256); } if(sscanf(port,"%i",&conf.db_port)==0) { fprintf(stderr,"You must provide a port number.\n"); exit(EXIT_FAILURE); } if(conf.enable_write_dump) { if(is_str(uid)) { if(sscanf(uid,"%i",&conf.dump_uid)==0) { fprintf(stderr,"User id must be an integer value.\n"); exit(EXIT_FAILURE); } } if(is_str(size)) { if(sscanf(size,"%i",&conf.dump_size)==0) { fprintf(stderr,"Size limit must be an integer value.\n"); exit(EXIT_FAILURE); } } } if(!is_full_path(conf.mountpoint)) { fprintf(stderr,"Use full path for mountpoint.\n"); fprintf(stderr,"Mountpoint '%s' is not valid.\n",conf.mountpoint); exit(EXIT_FAILURE); } }