void just_print_files(char **files, char *flags, char *folder) { struct stat *f_t; int i; if (!files || !files[0] || !ft_strlen(files[0])) return ; i = 0; while (files[i]) { if (ft_strchr(flags, 'G')) { if (!(f_t = get_file_stat(files[i], f_t, folder))) return ; if (!print_name_by_extension(files[i])) if (!print_name_by_permissions(get_permissions(f_t), files[i])) ft_putstr(files[i]); free(f_t); } else ft_putstr(files[i]); ft_putstr("\n"); i++; } }
static fssh_status_t command_chmod(int argc, const char* const* argv) { bool recursive = false; // parse parameters int argi = 1; for (argi = 1; argi < argc; argi++) { const char *arg = argv[argi]; if (arg[0] != '-') break; if (arg[1] == '\0') { fprintf(stderr, "Error: Invalid option \"-\"\n"); return FSSH_B_BAD_VALUE; } for (int i = 1; arg[i]; i++) { switch (arg[i]) { case 'R': recursive = true; fprintf(stderr, "Sorry, recursive mode not supported " "yet.\n"); return FSSH_B_BAD_VALUE; default: fprintf(stderr, "Error: Unknown option \"-%c\"\n", arg[i]); return FSSH_B_BAD_VALUE; } } } // get mode fssh_mode_t permissions; if (argi + 1 >= argc || !get_permissions(argv[argi++], permissions)) { printf("Usage: %s [ -R ] <octal mode> <file>...\n", argv[0]); return FSSH_B_BAD_VALUE; } fssh_struct_stat st; st.fssh_st_mode = permissions; // chmod loop for (; argi < argc; argi++) { const char *file = argv[argi]; if (strlen(file) == 0) { fprintf(stderr, "Error: An empty path is not a valid argument!\n"); return FSSH_B_BAD_VALUE; } fssh_status_t error = _kern_write_stat(-1, file, false, &st, sizeof(st), FSSH_B_STAT_MODE); if (error != FSSH_B_OK) { fprintf(stderr, "Error: Failed to change mode of \"%s\"!\n", file); return error; } } return FSSH_B_OK; }
void AditionalFileDialog::dialog_accepted() { a_file = ui->le_file->text(); QMap<PisiSPBase::AFileAttr,QString> attr; attr.insert(PisiSPBase::TARGET, ui->le_target->text()); attr.insert(PisiSPBase::PERMISSION, get_permissions()); attr.insert(PisiSPBase::OWNER, ui->le_owner->text()); attr.insert(PisiSPBase::GROUP, ui->le_group->text()); this->attr = attr; }
int perm::execute_access( const char * filename ) { if ( !volume_has_acls(filename) ) { return 1; } ACCESS_MASK rights = NULL; int p = get_permissions( filename, rights ); if ( p < 0 ) return -1; return ( rights & FILE_GENERIC_EXECUTE ) == FILE_GENERIC_EXECUTE; }
int qcopy_acl (const char *src_name, int source_desc, const char *dst_name, int dest_desc, mode_t mode) { struct permission_context ctx; int ret; ret = get_permissions (src_name, source_desc, mode, &ctx); if (ret != 0) return -2; ret = set_permissions (&ctx, dst_name, dest_desc); free_permission_context (&ctx); return ret; }
int perm::write_access( const char * filename ) { if ( !volume_has_acls(filename) ) { return 1; } ACCESS_MASK rights = NULL; int p = get_permissions( filename, rights ); if ( p < 0 ) return -1; /* Just some harmless debugging output printf("Rights mask: 0x%08x\n", rights); printf("FILE_GENERIC_WRITE mask: 0x%08x\n", FILE_GENERIC_WRITE); printf("GENERIC_WRITE mask: 0x%08x\n", GENERIC_WRITE); rights = ( rights & FILE_GENERIC_WRITE ); printf("Logical AND result mask: 0x%08x\n", rights); bool test = ( rights == FILE_GENERIC_WRITE ); */ return (rights & FILE_GENERIC_WRITE) == FILE_GENERIC_WRITE; }
/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ mafdcmd() $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/ int main(int argc, char *argv[]) { int errors = 0, i, position, user_offset; char fake_user[MAX_FULL_USER_ID_LENGTH], *perm_buffer, *ptr, user[MAX_FULL_USER_ID_LENGTH], work_dir[MAX_PATH_LENGTH]; CHECK_FOR_VERSION(argc, argv); if ((argc > 1) && (argv[1][0] == '-') && (argv[1][1] == 'v') && (argv[1][2] == '\0')) { (void)fprintf(stdout, "%s\n", PACKAGE_VERSION); exit(SUCCESS); } if (get_mon_path(&argc, argv, work_dir) < 0) { exit(INCORRECT); } p_work_dir = work_dir; if (get_arg(&argc, argv, "-p", user, MAX_PROFILE_NAME_LENGTH) == INCORRECT) { user_offset = 0; } else { user_offset = strlen(user); } #ifdef WITH_SETUID_PROGS set_afd_euid(work_dir); #endif if (argc < 2) { usage(argv[0]); exit(INCORRECT); } check_fake_user(&argc, argv, MON_CONFIG_FILE, fake_user); eval_input(argc, argv); get_user(user, fake_user, user_offset); /* * Ensure that the user may use this program. */ switch (get_permissions(&perm_buffer, fake_user)) { case NO_ACCESS : /* Cannot access afd.users file. */ { char afd_user_file[MAX_PATH_LENGTH]; (void)strcpy(afd_user_file, p_work_dir); (void)strcat(afd_user_file, ETC_DIR); (void)strcat(afd_user_file, AFD_USER_FILE); (void)fprintf(stderr, "Failed to access `%s', unable to determine users permissions.\n", afd_user_file); } exit(INCORRECT); case NONE : (void)fprintf(stderr, "%s\n", PERMISSION_DENIED_STR); exit(INCORRECT); case SUCCESS : /* Lets evaluate the permissions and see what */ /* the user may do. */ { int permission = NO; if ((perm_buffer[0] == 'a') && (perm_buffer[1] == 'l') && (perm_buffer[2] == 'l') && ((perm_buffer[3] == '\0') || (perm_buffer[3] == ' ') || (perm_buffer[3] == '\t'))) { permission = YES; } else { if (lposi(perm_buffer, MAFD_CMD_PERM, MAFD_CMD_PERM_LENGTH) != NULL) { permission = YES; /* * Check if the user may do everything * he has requested. If not remove it * from the option list. */ if ((options & ENABLE_AFD_OPTION) || (options & DISABLE_AFD_OPTION)) { if (lposi(perm_buffer, DISABLE_AFD_PERM, DISABLE_AFD_PERM_LENGTH) == NULL) { if (options & ENABLE_AFD_OPTION) { options ^= ENABLE_AFD_OPTION; } if (options & DISABLE_AFD_OPTION) { options ^= DISABLE_AFD_OPTION; } if (options & TOGGLE_AFD_OPTION) { options ^= TOGGLE_AFD_OPTION; } (void)fprintf(stderr, "User %s not permitted to enable/disable a AFD.\n", user); } } if (options & RETRY_OPTION) { if (lposi(perm_buffer, RETRY_PERM, RETRY_PERM_LENGTH) == NULL) { options ^= RETRY_OPTION; (void)fprintf(stderr, "User %s not permitted to retry.\n", user); } } if (options & SWITCH_AFD_OPTION) { if (lposi(perm_buffer, SWITCH_HOST_PERM, SWITCH_HOST_PERM_LENGTH) == NULL) { options ^= SWITCH_AFD_OPTION; (void)fprintf(stderr, "User %s not permitted to retry.\n", user); } } } } free(perm_buffer); if (permission != YES) { (void)fprintf(stderr, "%s\n", PERMISSION_DENIED_STR); exit(INCORRECT); } } break; case INCORRECT: /* Hmm. Something did go wrong. Since we want to */ /* be able to disable permission checking let */ /* the user have all permissions. */ break; default : (void)fprintf(stderr, "Impossible!! Remove the programmer!\n"); exit(INCORRECT); } if (msa_attach() < 0) { (void)fprintf(stderr, "ERROR : Failed to attach to MSA. (%s %d)\n", __FILE__, __LINE__); exit(INCORRECT); } for (i = 0; i < no_of_afd_names; i++) { position = -1; ptr = afds[i]; while ((*ptr != '\0') && (isdigit((int)(*ptr)))) { ptr++; } if ((*ptr == '\0') && (ptr != afds[i])) { position = atoi(afds[i]); if ((position < 0) || (position > (no_of_afds - 1))) { (void)fprintf(stderr, "WARNING : Position %d out of range. Ignoring. (%s %d)\n", position, __FILE__, __LINE__); errors++; continue; } } if (position < 0) { if ((position = get_afd_position(msa, afds[i], no_of_afds)) < 0) { (void)fprintf(stderr, "WARNING : Could not find AFD %s in MSA. (%s %d)\n", afds[i], __FILE__, __LINE__); errors++; continue; } } /* * ENABLE AFD */ if (options & ENABLE_AFD_OPTION) { if (msa[position].connect_status == DISABLED) { int fd; #ifdef WITHOUT_FIFO_RW_SUPPORT int readfd; #endif char mon_cmd_fifo[MAX_PATH_LENGTH]; (void)sprintf(mon_cmd_fifo, "%s%s%s", p_work_dir, FIFO_DIR, MON_CMD_FIFO); #ifdef WITHOUT_FIFO_RW_SUPPORT if (open_fifo_rw(mon_cmd_fifo, &readfd, &fd) == -1) #else if ((fd = open(mon_cmd_fifo, O_RDWR)) == -1) #endif { system_log(ERROR_SIGN, __FILE__, __LINE__, "Failed to open() %s : %s", mon_cmd_fifo, strerror(errno)); errors++; } else { char cmd[1 + SIZEOF_INT]; cmd[0] = ENABLE_MON; (void)memcpy(&cmd[1], &position, SIZEOF_INT); if (write(fd, cmd, (1 + SIZEOF_INT)) != (1 + SIZEOF_INT)) { system_log(ERROR_SIGN, __FILE__, __LINE__, "Failed to write() to %s : %s", mon_cmd_fifo, strerror(errno)); errors++; } else { system_log(DEBUG_SIGN, NULL, 0, "%-*s: ENABLED (%s) [mafdcmd].", MAX_AFD_NAME_LENGTH, msa[position].afd_alias, user); } #ifdef WITHOUT_FIFO_RW_SUPPORT if (close(readfd) == -1) { system_log(DEBUG_SIGN, __FILE__, __LINE__, "Failed to close() FIFO %s : %s", mon_cmd_fifo, strerror(errno)); } #endif if (close(fd) == -1) { system_log(DEBUG_SIGN, __FILE__, __LINE__, "Failed to close() FIFO %s : %s", mon_cmd_fifo, strerror(errno)); } } } else { (void)fprintf(stderr, "INFO : AFD %s is already enabled.\n", msa[position].afd_alias); } } /* * DISABLE AFD */ if (options & DISABLE_AFD_OPTION) { if (msa[position].connect_status == DISABLED) { (void)fprintf(stderr, "INFO : AFD %s is already disabled.\n", msa[position].afd_alias); } else { int fd; #ifdef WITHOUT_FIFO_RW_SUPPORT int readfd; #endif char mon_cmd_fifo[MAX_PATH_LENGTH]; (void)sprintf(mon_cmd_fifo, "%s%s%s", p_work_dir, FIFO_DIR, MON_CMD_FIFO); #ifdef WITHOUT_FIFO_RW_SUPPORT if (open_fifo_rw(mon_cmd_fifo, &readfd, &fd) == -1) #else if ((fd = open(mon_cmd_fifo, O_RDWR)) == -1) #endif { system_log(ERROR_SIGN, __FILE__, __LINE__, "Failed to open() %s : %s", mon_cmd_fifo, strerror(errno)); errors++; } else { char cmd[1 + SIZEOF_INT]; cmd[0] = DISABLE_MON; (void)memcpy(&cmd[1], &position, SIZEOF_INT); if (write(fd, cmd, (1 + SIZEOF_INT)) != (1 + SIZEOF_INT)) { system_log(ERROR_SIGN, __FILE__, __LINE__, "Failed to write() to %s : %s", mon_cmd_fifo, strerror(errno)); errors++; } else { system_log(DEBUG_SIGN, NULL, 0, "%-*s: DISABLED (%s) [mafdcmd].", MAX_AFD_NAME_LENGTH, msa[position].afd_alias, user); } #ifdef WITHOUT_FIFO_RW_SUPPORT if (close(readfd) == -1) { system_log(DEBUG_SIGN, __FILE__, __LINE__, "Failed to close() FIFO %s : %s", mon_cmd_fifo, strerror(errno)); } #endif if (close(fd) == -1) { system_log(DEBUG_SIGN, __FILE__, __LINE__, "Failed to close() FIFO %s : %s", mon_cmd_fifo, strerror(errno)); } } } } /* * ENABLE or DISABLE a AFD. */ if (options & TOGGLE_AFD_OPTION) { int fd; #ifdef WITHOUT_FIFO_RW_SUPPORT int readfd; #endif char mon_cmd_fifo[MAX_PATH_LENGTH]; (void)sprintf(mon_cmd_fifo, "%s%s%s", p_work_dir, FIFO_DIR, MON_CMD_FIFO); #ifdef WITHOUT_FIFO_RW_SUPPORT if (open_fifo_rw(mon_cmd_fifo, &readfd, &fd) == -1) #else if ((fd = open(mon_cmd_fifo, O_RDWR)) == -1) #endif { system_log(ERROR_SIGN, __FILE__, __LINE__, "Failed to open() %s : %s", mon_cmd_fifo, strerror(errno)); errors++; } else { char cmd[1 + SIZEOF_INT]; if (msa[position].connect_status == DISABLED) { cmd[0] = ENABLE_MON; } else /* DISABLE AFD */ { cmd[0] = DISABLE_MON; } (void)memcpy(&cmd[1], &position, SIZEOF_INT); if (write(fd, cmd, (1 + SIZEOF_INT)) != (1 + SIZEOF_INT)) { system_log(ERROR_SIGN, __FILE__, __LINE__, "Failed to write() to %s : %s", mon_cmd_fifo, strerror(errno)); errors++; } else { system_log(DEBUG_SIGN, NULL, 0, "%-*s: %s (%s) [mafdcmd].", MAX_AFD_NAME_LENGTH, msa[position].afd_alias, (cmd[0] == DISABLE_MON) ? "DISABLE" : "ENABLE", user); } #ifdef WITHOUT_FIFO_RW_SUPPORT if (close(readfd) == -1) { system_log(DEBUG_SIGN, __FILE__, __LINE__, "Failed to close() FIFO %s : %s", mon_cmd_fifo, strerror(errno)); } #endif if (close(fd) == -1) { system_log(DEBUG_SIGN, __FILE__, __LINE__, "Failed to close() FIFO %s : %s", mon_cmd_fifo, strerror(errno)); } } } if (options & RETRY_OPTION) { int fd; #ifdef WITHOUT_FIFO_RW_SUPPORT int readfd; #endif char retry_fifo[MAX_PATH_LENGTH]; (void)sprintf(retry_fifo, "%s%s%s%d", p_work_dir, FIFO_DIR, RETRY_MON_FIFO, position); #ifdef WITHOUT_FIFO_RW_SUPPORT if (open_fifo_rw(retry_fifo, &readfd, &fd) == -1) #else if ((fd = open(retry_fifo, O_RDWR)) == -1) #endif { (void)fprintf(stderr, "WARNING : Failed to open() %s : %s (%s %d)\n", retry_fifo, strerror(errno), __FILE__, __LINE__); errors++; } else { if (write(fd, &position, sizeof(int)) != sizeof(int)) { (void)fprintf(stderr, "WARNING : Failed to write() to %s : %s (%s %d)\n", retry_fifo, strerror(errno), __FILE__, __LINE__); errors++; } #ifdef WITHOUT_FIFO_RW_SUPPORT if (close(readfd) == -1) { system_log(DEBUG_SIGN, __FILE__, __LINE__, "Failed to close() FIFO %s : %s" RETRY_FD_FIFO, strerror(errno)); } #endif if (close(fd) == -1) { system_log(DEBUG_SIGN, __FILE__, __LINE__, "Failed to close() FIFO %s : %s" RETRY_FD_FIFO, strerror(errno)); } } } /* * Switch AFD */ if (options & SWITCH_AFD_OPTION) { if (msa[position].afd_switching == NO_SWITCHING) { (void)fprintf(stderr, "INFO : AFD %s cannot be switched.\n", msa[position].afd_alias); errors++; } else { if (msa[position].afd_toggle == (HOST_ONE - 1)) { msa[position].afd_toggle = (HOST_TWO - 1); } else { msa[position].afd_toggle = (HOST_ONE - 1); } system_log(DEBUG_SIGN, NULL, 0, "%-*s: SWITCHED (%s) [mafdcmd].", MAX_AFD_NAME_LENGTH, msa[position].afd_alias, user); } } } /* for (i = 0; i < no_of_afd_names; i++) */ (void)msa_detach(); exit(errors); }
// main int main(int argc, char** argv) { BApplication app("application/x-vnd.antares-netfs_server_prefs"); // parse first argument int argi = 1; const char* arg = next_arg(argc, argv, argi); if (strcmp(arg, "-h") == 0 || strcmp(arg, "--help") == 0) print_usage_and_exit(false); if (strcmp(arg, "launch") == 0) { // launch no_more_args(argc, argi); launch_server(); } else if (strcmp(arg, "terminate") == 0) { // terminate no_more_args(argc, argi); terminate_server(); } else if (strcmp(arg, "save") == 0) { // save no_more_args(argc, argi); save_server_setttings(); } else if (strcmp(arg, "l") == 0 || strcmp(arg, "list") == 0) { // list no_more_args(argc, argi); list(); } else if (strcmp(arg, "add") == 0) { // add arg = next_arg(argc, argv, argi); if (strcmp(arg, "share") == 0) { // share const char* name = next_arg(argc, argv, argi); const char* path = next_arg(argc, argv, argi); no_more_args(argc, argi); add_share(name, path); } else if (strcmp(arg, "user") == 0) { // user const char* name = next_arg(argc, argv, argi); const char* password = next_arg(argc, argv, argi, true); no_more_args(argc, argi); add_user(name, password); } else print_usage_and_exit(true); } else if (strcmp(arg, "remove") == 0) { // remove arg = next_arg(argc, argv, argi); if (strcmp(arg, "share") == 0) { // share const char* name = next_arg(argc, argv, argi); no_more_args(argc, argi); remove_share(name); } else if (strcmp(arg, "user") == 0) { // user const char* name = next_arg(argc, argv, argi); no_more_args(argc, argi); remove_user(name); } else print_usage_and_exit(true); } else if (strcmp(arg, "permissions") == 0) { // permissions const char* user = next_arg(argc, argv, argi); const char* share = next_arg(argc, argv, argi); uint32 permissions = 0; while (argi < argc) { uint32 perms = 0; arg = next_arg(argc, argv, argi); if (!get_permissions(arg, &perms)) print_usage_and_exit(true); permissions |= perms; } set_user_permissions(user, share, permissions); } else { print_usage_and_exit(true); } return 0; }
/*++++++++++++++++++++++++++++ init_mon_info() ++++++++++++++++++++++++++*/ static void init_mon_info(int *argc, char *argv[]) { int i, user_offset; char fake_user[MAX_FULL_USER_ID_LENGTH], *perm_buffer, profile[MAX_PROFILE_NAME_LENGTH + 1]; if ((get_arg(argc, argv, "-?", NULL, 0) == SUCCESS) || (get_arg(argc, argv, "-help", NULL, 0) == SUCCESS) || (get_arg(argc, argv, "--help", NULL, 0) == SUCCESS)) { usage(argv[0]); exit(SUCCESS); } if (get_arg(argc, argv, "-f", font_name, 40) == INCORRECT) { (void)strcpy(font_name, "fixed"); } if (get_arg(argc, argv, "-a", afd_name, MAX_AFDNAME_LENGTH + 1) == INCORRECT) { usage(argv[0]); exit(INCORRECT); } if (get_arg(argc, argv, "-p", profile, MAX_PROFILE_NAME_LENGTH) == INCORRECT) { user_offset = 0; profile[0] = '\0'; } else { (void)strcpy(user, profile); user_offset = strlen(profile); } if (get_mon_path(argc, argv, p_work_dir) < 0) { (void)fprintf(stderr, "Failed to get working directory of AFD_MON. (%s %d)\n", __FILE__, __LINE__); exit(INCORRECT); } /* Now lets see if user may use this program. */ check_fake_user(argc, argv, MON_CONFIG_FILE, fake_user); switch (get_permissions(&perm_buffer, fake_user)) { case NO_ACCESS : /* Cannot access afd.users file. */ { char afd_user_file[MAX_PATH_LENGTH]; (void)strcpy(afd_user_file, p_work_dir); (void)strcat(afd_user_file, ETC_DIR); (void)strcat(afd_user_file, AFD_USER_FILE); (void)fprintf(stderr, "Failed to access `%s', unable to determine users permissions.\n", afd_user_file); } exit(INCORRECT); case NONE : (void)fprintf(stderr, "%s\n", PERMISSION_DENIED_STR); exit(INCORRECT); case SUCCESS : /* Lets evaluate the permissions and see what */ /* the user may do. */ eval_permissions(perm_buffer); free(perm_buffer); break; case INCORRECT : /* Hmm. Something did go wrong. Since we want to */ /* be able to disable permission checking let */ /* the user have all permissions. */ editable = NO; break; default : (void)fprintf(stderr, "Impossible!! Remove the programmer!\n"); exit(INCORRECT); } get_user(user, fake_user, user_offset); /* Attach to the MSA. */ if ((i = msa_attach_passive()) < 0) { if (i == INCORRECT_VERSION) { (void)fprintf(stderr, "This program is not able to attach to the MSA due to incorrect version. (%s %d)\n", __FILE__, __LINE__); } else { (void)fprintf(stderr, "Failed to attach to MSA. (%s %d)\n", __FILE__, __LINE__); } exit(INCORRECT); } for (i = 0; i < no_of_afds; i++) { if (strcmp(msa[i].afd_alias, afd_name) == 0) { afd_position = i; break; } } if (afd_position < 0) { (void)fprintf(stderr, "WARNING : Could not find AFD %s in MSA. (%s %d)\n", afd_name, __FILE__, __LINE__); exit(INCORRECT); } /* Initialize values in MSA structure. */ (void)strcpy(prev.real_hostname[0], msa[afd_position].hostname[0]); (void)strcpy(prev.real_hostname[1], msa[afd_position].hostname[1]); (void)strcpy(prev.r_work_dir, msa[afd_position].r_work_dir); (void)strcpy(prev.afd_version, msa[afd_position].afd_version); prev.port[0] = msa[afd_position].port[0]; prev.port[1] = msa[afd_position].port[1]; prev.afd_toggle = msa[afd_position].afd_toggle; prev.poll_interval = msa[afd_position].poll_interval; prev.max_connections = msa[afd_position].max_connections; prev.no_of_hosts = msa[afd_position].no_of_hosts; prev.last_data_time = msa[afd_position].last_data_time; prev.top_not = msa[afd_position].top_no_of_transfers[0]; prev.top_tr = msa[afd_position].top_tr[0]; prev.top_fr = msa[afd_position].top_fr[0]; if (atexit(mon_info_exit) != 0) { (void)xrec(WARN_DIALOG, "Failed to set exit handler for %s : %s", MON_INFO, strerror(errno)); } check_window_ids(MON_INFO); return; }
// // get_permissions: 1 = yes, 0 = no, -1 = unknown/error // int perm::get_permissions( const char *file_name, ACCESS_MASK &AccessRights ) { DWORD retVal; PACL pacl; PSECURITY_DESCRIPTOR pSD; DWORD pSD_length = 0; DWORD pSD_length_needed = 0; BOOL acl_present = FALSE; BOOL acl_defaulted = FALSE; // Do the call first to find out how much space is needed. pSD = NULL; GetFileSecurity( file_name, // address of string for file name DACL_SECURITY_INFORMATION, // requested information pSD, // address of security descriptor pSD_length, // size of security descriptor buffer &pSD_length_needed // address of required size of buffer ); if( pSD_length_needed <= 0 ) { // Find out how much space is needed, if <=0 then error if ( (GetLastError() == ERROR_FILE_NOT_FOUND) || (GetLastError() == ERROR_PATH_NOT_FOUND) ) { // Here we have the tricky part of walking up the directory path // Typically it works like this: If the filename exists, great, we'll // get the permissions on that. If the filename does not exist, then // we pop the filename part off the file_name and look at the // directory. If that directory should be (for some odd reason) non- // existant, then we just pop that off, until either we find something // thats will give us a permissions bitmask, or we run out of places // to look (which shouldn't happen since c:\ should always give us // SOMETHING... int i = strlen( file_name ) - 1; while ( i >= 0 && ( file_name[i] != '\\' && file_name[i] != '/' ) ) { i--; } if ( i < 0 ) { // We've nowhere else to look, and this is bad. return -1; // Its not a no, its an unknown } char *new_file_name = new char[i+1]; strncpy(new_file_name, file_name, i); new_file_name[i]= '\0'; // Now that we've chopped off more of the filename, call get_permissions // again... retVal = get_permissions( new_file_name, AccessRights ); delete[] new_file_name; // ... and return what it returns. (after deleting the string that was // allocated. return retVal; } dprintf(D_ALWAYS, "perm::GetFileSecurity failed (err=%d)\n", GetLastError()); return -1; } pSD_length = pSD_length_needed + 2; // Add 2 for safety. pSD_length_needed = 0; pSD = new BYTE[pSD_length]; // Okay, now that we've found something, and know how large of an SD we need, // call the thing for real and lets get ON WITH IT ALREADY... if( !GetFileSecurity( file_name, // address of string for file name DACL_SECURITY_INFORMATION, // requested information pSD, // address of security descriptor pSD_length, // size of security descriptor buffer &pSD_length_needed // address of required size of buffer ) ) { dprintf(D_ALWAYS, "perm::GetFileSecurity(%s) failed (err=%d)\n", file_name, GetLastError()); delete[] pSD; return -1; } // Now, get the ACL from the security descriptor if( !GetSecurityDescriptorDacl( pSD, // address of security descriptor &acl_present, // address of flag for presence of disc. ACL &pacl, // address of pointer to ACL &acl_defaulted // address of flag for default disc. ACL ) ) { dprintf(D_ALWAYS, "perm::GetSecurityDescriptorDacl failed (file=%s err=%d)\n", file_name, GetLastError()); delete[] pSD; return -1; } // This is the workaround for the broken API GetEffectiveRightsFromAcl(). // It should be guaranteed to work on all versions of NT and 2000 but be aware // that nested global group permissions are not supported. // C. Stolley - June 2001 ACL_SIZE_INFORMATION acl_info; // Structure contains the following members: // DWORD AceCount; // DWORD AclBytesInUse; // DWORD AclBytesFree; // first get the number of ACEs in the ACL if (! GetAclInformation( pacl, // acl to get info from &acl_info, // buffer to receive info sizeof(acl_info), // size in bytes of buffer AclSizeInformation // class of info to retrieve ) ) { dprintf(D_ALWAYS, "Perm::GetAclInformation failed with error %d\n", GetLastError() ); return -1; } ACCESS_MASK allow = 0x0; ACCESS_MASK deny = 0x0; unsigned int aceCount = acl_info.AceCount; int result; // now look at each ACE in the ACL and see if it contains the user we're looking for for (unsigned int i=0; i < aceCount; i++) { LPVOID current_ace; if (! GetAce( pacl, // pointer to ACL i, // index of ACE we want ¤t_ace // pointer to ACE ) ) { dprintf(D_ALWAYS, "Perm::GetAce() failed! Error code %d\n", GetLastError() ); return -1; } dprintf(D_FULLDEBUG, "Calling Perm::userInAce() for %s\\%s\n", (Domain_name) ? Domain_name : "NULL", (Account_name) ? Account_name : "NULL" ); result = userInAce ( current_ace, Account_name, Domain_name ); if (result == 1) { switch ( ( (PACE_HEADER) current_ace)->AceType ) { case ACCESS_ALLOWED_ACE_TYPE: case ACCESS_ALLOWED_OBJECT_ACE_TYPE: allow |= ( (ACCESS_ALLOWED_ACE*) current_ace)->Mask; break; case ACCESS_DENIED_ACE_TYPE: case ACCESS_DENIED_OBJECT_ACE_TYPE: deny |= ( (ACCESS_DENIED_ACE*) current_ace)->Mask; break; } } } AccessRights = allow; AccessRights &= ~deny; // and now if we've made this far everything's happy so return true return 1; }
/*+++++++++++++++++++++++++++ init_afd_load() +++++++++++++++++++++++++++*/ static void init_afd_load(int *argc, char *argv[], char *font_name, char *window_title) { register int i; char fake_user[MAX_FULL_USER_ID_LENGTH], *perm_buffer, hostname[MAX_AFD_NAME_LENGTH]; if ((get_arg(argc, argv, "-?", NULL, 0) == SUCCESS) || (get_arg(argc, argv, "-help", NULL, 0) == SUCCESS) || (get_arg(argc, argv, "--help", NULL, 0) == SUCCESS)) { usage(argv[0]); exit(SUCCESS); } if (get_afd_path(argc, argv, p_work_dir) < 0) { (void)fprintf(stderr, "Failed to get working directory of AFD. (%s %d)\n", __FILE__, __LINE__); exit(INCORRECT); } /* Now lets see if user may use this program. */ check_fake_user(argc, argv, AFD_CONFIG_FILE, fake_user); switch (get_permissions(&perm_buffer, fake_user)) { case NO_ACCESS : /* Cannot access afd.users file. */ { char afd_user_file[MAX_PATH_LENGTH]; (void)strcpy(afd_user_file, p_work_dir); (void)strcat(afd_user_file, ETC_DIR); (void)strcat(afd_user_file, AFD_USER_FILE); (void)fprintf(stderr, "Failed to access `%s', unable to determine users permissions.\n", afd_user_file); } exit(INCORRECT); case NONE : (void)fprintf(stderr, "%s\n", PERMISSION_DENIED_STR); exit(INCORRECT); case SUCCESS : /* The user may use this program. */ free(perm_buffer); break; case INCORRECT : /* Hmm. Something did go wrong. Since we want to */ /* be able to disable permission checking let */ /* the user have all permissions. */ break; default : (void)fprintf(stderr, "Impossible!! Remove the programmer!\n"); exit(INCORRECT); } /* Attach to FSA to get values for chart. */ if ((i = fsa_attach_passive(NO, AFD_LOAD)) < 0) { if (i == INCORRECT_VERSION) { (void)fprintf(stderr, "This program is not able to attach to the FSA due to incorrect version.\n"); } else { (void)fprintf(stderr, "Failed to attach to FSA.\n"); } exit(INCORRECT); } if (get_arg(argc, argv, SHOW_FILE_LOAD, NULL, 0) == SUCCESS) { chart_type = FILE_CHART; for (i = 0; i < no_of_hosts; i++) { prev_value += (double)fsa[i].file_counter_done; } } else if (get_arg(argc, argv, SHOW_KBYTE_LOAD, NULL, 0) == SUCCESS) { chart_type = KBYTE_CHART; for (i = 0; i < no_of_hosts; i++) { prev_value += (double)fsa[i].bytes_send; } prev_value /= 1024; } else if (get_arg(argc, argv, SHOW_CONNECTION_LOAD, NULL, 0) == SUCCESS) { chart_type = CONNECTION_CHART; for (i = 0; i < no_of_hosts; i++) { prev_value += (double)fsa[i].connections; } } else if (get_arg(argc, argv, SHOW_TRANSFER_LOAD, NULL, 0) == SUCCESS) { /* Attach to the AFD Status Area. */ if (attach_afd_status(NULL, WAIT_AFD_STATUS_ATTACH) < 0) { (void)fprintf(stderr, "Failed to map to AFD status area. (%s %d)\n", __FILE__, __LINE__); exit(INCORRECT); } chart_type = TRANSFER_CHART; prev_value = p_afd_status->no_of_transfers; } else { (void)fsa_detach(NO); usage(argv[0]); exit(INCORRECT); } if (get_arg(argc, argv, "-f", font_name, 256) == INCORRECT) { (void)strcpy(font_name, "fixed"); } /* Prepare title of this window. */ (void)strcpy(window_title, "AFD Load "); if (get_afd_name(hostname) == INCORRECT) { if (gethostname(hostname, MAX_AFD_NAME_LENGTH) == 0) { hostname[0] = toupper((int)hostname[0]); (void)strcat(window_title, hostname); } } else { (void)strcat(window_title, hostname); } return; }
/* allows remapping even if memory is mapped in...this is useful, as it * remembers where the video mem *was* mapped, unmaps from that, and then * remaps it to where the text page number says it should be */ void get_video_ram(int waitflag) { char *graph_mem; char *sbase; size_t ssize; char *textbuf = NULL, *vgabuf = NULL; debug_vid("get_video_ram STARTED\n"); if (config.vga) { ssize = GRAPH_SIZE; sbase = (char *) GRAPH_BASE; } else { ssize = TEXT_SIZE; sbase = PAGE_ADDR(READ_BYTE(BIOS_CURRENT_SCREEN_PAGE)); } #if 0 if (waitflag == WAIT) { config.console_video = 0; debug_vid("VID: get_video_ram WAITING\n"); /* XXX - wait until our console is current (mixed signal functions) */ do { if (!wait_vc_active ()) break; debug_vid("Keeps waiting...And\n"); } while (errno == EINTR); } #endif if (config.vga) { debug("config.vga\n"); if (READ_BYTE(BIOS_VIDEO_MODE) == 3 && READ_BYTE(BIOS_CURRENT_SCREEN_PAGE) < 8) { textbuf = malloc(TEXT_SIZE * 8); if (!textbuf) leaveemu(ERR_MEM); memcpy(textbuf, PAGE_ADDR(0), TEXT_SIZE * 8); } if (SCR_STATE.mapped) { vgabuf = (char *)malloc(GRAPH_SIZE); if (!vgabuf) leaveemu(ERR_MEM); memcpy(vgabuf, (caddr_t) GRAPH_BASE, GRAPH_SIZE); if (memmap(graph_mem = (void *)GRAPH_BASE, GRAPH_SIZE, PG_U | PG_W | PG_P, (void *)GRAPH_BASE) != 0) { error("memmap failed for 0x%08x\n", GRAPH_BASE); leaveemu(ERR_PT); } memcpy((caddr_t) GRAPH_BASE, vgabuf, GRAPH_SIZE); } } else { textbuf = (char *)malloc(TEXT_SIZE); if (!textbuf) leaveemu(ERR_MEM); memcpy(textbuf, SCR_STATE.virt_address, TEXT_SIZE); if (SCR_STATE.mapped) { if (memmap(graph_mem = SCR_STATE.virt_address, TEXT_SIZE, PG_U | PG_W | PG_P, SCR_STATE.virt_address) != 0) { error("memmap failed for 0x%08x\n", (u_int)SCR_STATE.virt_address); leaveemu(ERR_PT); } memcpy(SCR_STATE.virt_address, textbuf, TEXT_SIZE); } } SCR_STATE.mapped = 0; if (config.vga) { if (READ_BYTE(BIOS_VIDEO_MODE) == 3) { if (dosemu_regs->mem && textbuf) memcpy(dosemu_regs->mem, textbuf, dosemu_regs->save_mem_size[0]); /* else error("ERROR: no dosemu_regs->mem!\n"); */ } debug("mapping GRAPH_BASE\n"); if (memmap(graph_mem = (void *) GRAPH_BASE, GRAPH_SIZE, PG_U | PG_W | PG_P, (void *) GRAPH_BASE) != 0) { error("memmap failed for 0x%08x\n", GRAPH_BASE); leaveemu(ERR_PT); } /* the code below is done by the video save/restore code */ get_permissions(); } else { /* this is used for page switching */ if (PAGE_ADDR(READ_BYTE(BIOS_CURRENT_SCREEN_PAGE)) != SCR_STATE.virt_address) memcpy(textbuf, PAGE_ADDR(READ_BYTE(BIOS_CURRENT_SCREEN_PAGE)), TEXT_SIZE); debug("mapping PAGE_ADDR\n"); if (memmap(graph_mem = PAGE_ADDR(READ_BYTE(BIOS_CURRENT_SCREEN_PAGE)), TEXT_SIZE, PG_U | PG_W | PG_P, (void*)phys_text_base) != 0) { error("memmap failed for 0x%08x\n", GRAPH_BASE); leaveemu(ERR_PT); } #if 0 /* Map CGA, etc text memory to HGA memory. Useful for debugging systems with HGA or MDA cards. */ graph_mem = (char *) mmap((caddr_t) 0xb8000, TEXT_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, mem_fd, phys_text_base); if ((long) graph_mem < 0) { error("ERROR: mmap error in get_video_ram (text): %x, errno %d\n", (Bit32u) graph_mem, errno); return; } else #endif debug_vid("CONSOLE VIDEO address: %p %p %p\n", (void *) graph_mem, (void *) phys_text_base, (void *) PAGE_ADDR(READ_BYTE(BIOS_CURRENT_SCREEN_PAGE))); get_permissions(); /* copy contents of page onto video RAM */ memcpy((caddr_t) PAGE_ADDR(READ_BYTE(BIOS_CURRENT_SCREEN_PAGE)), textbuf, TEXT_SIZE); } if (vgabuf) free(vgabuf); if (textbuf) free(textbuf); SCR_STATE.pageno = READ_BYTE(BIOS_CURRENT_SCREEN_PAGE); SCR_STATE.virt_address = PAGE_ADDR(READ_BYTE(BIOS_CURRENT_SCREEN_PAGE)); SCR_STATE.phys_address = graph_mem; SCR_STATE.mapped = 1; }
/*++++++++++++++++++++++++++++ init_view_dc() +++++++++++++++++++++++++++*/ static void init_view_dc(int *argc, char *argv[]) { int empty_lines, length, line_length; char cmd[MAX_PATH_LENGTH], *data_buffer, fake_user[MAX_FULL_USER_ID_LENGTH], *perm_buffer, *p_retr_send_sep; if ((get_arg(argc, argv, "-?", NULL, 0) == SUCCESS) || (get_arg(argc, argv, "-help", NULL, 0) == SUCCESS) || (get_arg(argc, argv, "--help", NULL, 0) == SUCCESS)) { usage(argv[0]); exit(SUCCESS); } if (get_afd_path(argc, argv, p_work_dir) < 0) { (void)fprintf(stderr, "Failed to get working directory of AFD. (%s %d)\n", __FILE__, __LINE__); exit(INCORRECT); } if (get_arg(argc, argv, "-f", font_name, 40) == INCORRECT) { (void)strcpy(font_name, "fixed"); } if (get_arg(argc, argv, "-h", host_alias, MAX_HOSTNAME_LENGTH + 1) == INCORRECT) { if (get_arg(argc, argv, "-d", dir_alias, MAX_DIR_ALIAS_LENGTH + 1) == INCORRECT) { usage(argv[0]); exit(INCORRECT); } host_alias[0] = '\0'; } else { dir_alias[0] = '\0'; } /* Now lets see if user may use this program. */ check_fake_user(argc, argv, AFD_CONFIG_FILE, fake_user); switch (get_permissions(&perm_buffer, fake_user)) { case NO_ACCESS : /* Cannot access afd.users file. */ { char afd_user_file[MAX_PATH_LENGTH]; (void)strcpy(afd_user_file, p_work_dir); (void)strcat(afd_user_file, ETC_DIR); (void)strcat(afd_user_file, AFD_USER_FILE); (void)fprintf(stderr, "Failed to access `%s', unable to determine users permissions.\n", afd_user_file); } exit(INCORRECT); case NONE : (void)fprintf(stderr, "%s\n", PERMISSION_DENIED_STR); exit(INCORRECT); case SUCCESS : /* Lets evaluate the permissions and see what */ /* the user may do. */ if ((perm_buffer[0] == 'a') && (perm_buffer[1] == 'l') && (perm_buffer[2] == 'l') && ((perm_buffer[3] == '\0') || (perm_buffer[3] == ' ') || (perm_buffer[3] == '\t'))) { free(perm_buffer); break; } else if (posi(perm_buffer, VIEW_DIR_CONFIG_PERM) == NULL) { (void)fprintf(stderr, "%s\n", PERMISSION_DENIED_STR); exit(INCORRECT); } free(perm_buffer); break; case INCORRECT: /* Hmm. Something did go wrong. Since we want to */ /* be able to disable permission checking let */ /* the user have all permissions. */ break; default : (void)fprintf(stderr, "Impossible!! Remove the programmer!\n"); exit(INCORRECT); } /* * Run get_dc_data program to get the data. */ length = sprintf(cmd, "%s %s %s", GET_DC_DATA, WORK_DIR_ID, p_work_dir); if (fake_user[0] != '\0') { length += sprintf(&cmd[length], " -u %s", fake_user); } if (host_alias[0] != '\0') { length += sprintf(&cmd[length], " -h \"%s\"", host_alias); } else if (dir_alias[0] != '\0') { length += sprintf(&cmd[length], " -d \"%s\"", dir_alias); } data_buffer = NULL; if ((exec_cmd(cmd, &data_buffer, -1, NULL, 0, #ifdef HAVE_SETPRIORITY NO_PRIORITY, #endif "", 0L, NO, NO) != 0) || (data_buffer == NULL)) { (void)fprintf(stderr, "Failed to execute command: %s\n", cmd); (void)fprintf(stderr, "See SYSTEM_LOG for more information.\n"); exit(INCORRECT); } length = 0; empty_lines = 0; max_x = 0; max_y = 0; while (data_buffer[length] != '\0') { line_length = 0; while ((data_buffer[length] != '\n') && (data_buffer[length] != '\0')) { length++; line_length++; } if (data_buffer[length] == '\n') { max_y++; length++; if (line_length > max_x) { max_x = line_length; } line_length = 0; if (data_buffer[length] == '\n') { length++; empty_lines++; max_y++; } } } if (length > 0) { int new_lines_removed = 0; while (data_buffer[length - 1] == '\n') { new_lines_removed++; length--; } empty_lines = empty_lines - (new_lines_removed / 2); data_buffer[length] = '\0'; length++; } if ((length > 0) && (host_alias[0] != '\0')) { if (posi(data_buffer, DIR_IDENTIFIER) != NULL) { if ((p_retr_send_sep = posi(data_buffer, VIEW_DC_DIR_IDENTIFIER)) == NULL) { (void)strcpy(dir_alias, host_alias); host_alias[0] = '\0'; } else { p_retr_send_sep -= (VIEW_DC_DIR_IDENTIFIER_LENGTH + 1); } } else { p_retr_send_sep = NULL; } } /* * For host alias, lets insert separator lines for empty * lines. This makes it more readable. */ if (host_alias[0] != '\0') { if (length == 0) { view_buffer = data_buffer; max_x = sprintf(view_buffer, "\n No data found for host %s!\n\n", host_alias); max_y = 3; } else { size_t new_size; char *wptr; new_size = length + 1 + (empty_lines * (max_x + 1)); if ((view_buffer = malloc(new_size)) == NULL) { #if SIZEOF_SIZE_T == 4 (void)fprintf(stderr, "Failed to malloc() %d bytes : %s", #else (void)fprintf(stderr, "Failed to malloc() %lld bytes : %s", #endif (pri_size_t)new_size, strerror(errno)); exit(INCORRECT); } if (p_retr_send_sep == NULL) { length = 0; wptr = view_buffer; } else { length = p_retr_send_sep - data_buffer; (void)memcpy(view_buffer, data_buffer, length); wptr = &view_buffer[length]; (void)memset(wptr, '=', max_x); wptr += max_x; *wptr = '\n'; wptr++; } while (data_buffer[length] != '\0') { while ((data_buffer[length] != '\n') && (data_buffer[length] != '\0')) { *wptr = data_buffer[length]; length++; wptr++; } if (data_buffer[length] == '\n') { *wptr = '\n'; length++; wptr++; if (data_buffer[length] == '\n') { (void)memset(wptr, '-', max_x); wptr += max_x; *wptr = '\n'; length++; wptr++; } } } *wptr = '\0'; free(data_buffer); max_y--; } p_title = host_alias; }
int main (int argc, char **argv) { int status = 0; char *nextarg; char *tmp; char *section = 0; #ifdef __CYGWIN__ extern int optind; #endif #if 0 { /* There are no known cases of buffer overflow caused by excessively long environment variables. In case you find one, the simplistic way to fix is to enable this stopgap. */ char *s; #define CHECK(p,l) s=getenv(p); if(s && strlen(s)>(l)) { fprintf(stderr, "ERROR: Environment variable %s too long!\n", p); exit(1); } CHECK("LANG", 32); CHECK("LANGUAGE", 128); CHECK("LC_MESSAGES", 128); CHECK("MANPAGER", 128); CHECK("MANPL", 128); CHECK("MANROFFSEQ", 128); CHECK("MANSECT", 128); CHECK("MAN_HP_DIREXT", 128); CHECK("PAGER", 128); CHECK("SYSTEM", 64); CHECK("BROWSER", 64); CHECK("HTMLPAGER", 64); /* COLUMNS, LC_ALL, LC_CTYPE, MANPATH, MANWIDTH, MAN_IRIX_CATNAMES, MAN_ICONV_PATH, MAN_ICONV_OPT, MAN_ICONV_INPUT_CHARSET, MAN_ICONV_OUTPUT_CHARSET, NLSPATH, PATH */ } #endif #ifndef __FreeBSD__ /* Slaven Rezif: FreeBSD-2.2-SNAP does not recognize LC_MESSAGES. */ setlocale(LC_CTYPE, ""); /* used anywhere? maybe only isdigit()? */ setlocale(LC_MESSAGES, ""); #endif /* No doubt we'll need some generic language code here later. For the moment only Japanese support. */ setlang(); /* Handle /usr/man/man1.Z/name.1 nonsense from HP */ dohp = getenv("MAN_HP_DIREXT"); /* .Z */ /* Handle ls.z (instead of ls.1.z) cat page naming from IRIX */ if (getenv("MAN_IRIX_CATNAMES")) do_irix = 1; /* Handle lack of ':' in NTFS file names */ #if defined(_WIN32) || defined(__CYGWIN__) do_win32 = 1; #endif progname = mkprogname (argv[0]); get_permissions (); get_line_length(); /* * read command line options and man.conf */ man_getopt (argc, argv); /* * manpath or man --path or man -w will only print the manpath */ if (!strcmp (progname, "manpath") || (optind == argc && print_where)) { init_manpath(); prmanpath(); exit(0); } if (optind == argc) gripe(NO_NAME_NO_SECTION); section_list = get_section_list (); while (optind < argc) { nextarg = argv[optind++]; /* is_section correctly accepts 3Xt as section, but also 9wm, so we should not believe is_section() for the last arg. */ tmp = is_section (nextarg); if (tmp && optind < argc) { section = tmp; if (debug) gripe (SECTION, section); continue; } if (global_apropos) status = !do_global_apropos (nextarg, section); else if (apropos) status = !do_apropos (nextarg); else if (whatis) status = !do_whatis (nextarg); else { status = man (nextarg, section); if (status == 0) { if (section) gripe (NO_SUCH_ENTRY_IN_SECTION, nextarg, section); else gripe (NO_SUCH_ENTRY, nextarg); } } } return status ? EXIT_SUCCESS : EXIT_FAILURE; }