// ----------------------------------------------------------------------------- // Returns char width. // If show_robot_flag set, then show a frame of the spinning robot. int show_char_delay(char the_char, int delay, int robot_num, int cursor_flag) { int w, h, aw; char message[2]; fix start_time; int i; start_time = timer_get_fixed_seconds(); message[0] = the_char; message[1] = 0; gr_get_string_size(message, &w, &h, &aw ); Assert((Current_color >= 0) && (Current_color < MAX_BRIEFING_COLORS)); // Draw cursor if there is some delay and caller says to draw cursor //added/changed on 9/13/98 by adb to fix messy code and add gr_update if (delay) { if (cursor_flag && delay) { gr_set_fontcolor(Briefing_foreground_colors[Current_color], -1); gr_printf(Briefing_text_x+1, Briefing_text_y, "_" ); } for (i=0; i<2; i++) { if (robot_num != -1) show_spinning_robot_frame(robot_num); show_bitmap_frame(); gr_update(); while (timer_get_fixed_seconds() < start_time + delay/2) ; start_time = timer_get_fixed_seconds(); } // Erase cursor if (cursor_flag) { gr_set_fontcolor(Erase_color, -1); gr_printf(Briefing_text_x+1, Briefing_text_y, "_" ); } } //end additions/changed - adb // Draw the character gr_set_fontcolor(Briefing_background_colors[Current_color], -1); gr_printf(Briefing_text_x, Briefing_text_y, message ); gr_set_fontcolor(Briefing_foreground_colors[Current_color], -1); gr_printf(Briefing_text_x+1, Briefing_text_y, message ); // if (the_char != ' ') // if (!digi_is_sound_playing(231)) // digi_play_sample( 231, F1_0 ); return w; }
int delgrent(struct group * grp) { char group[MAXLOGNAME]; strlcpy(group, grp->gr_name, MAXLOGNAME); return gr_update(NULL, group); }
/* * grp_update - add new group file entries * * grp_update() writes the new records to the group files. */ static void grp_update (void) { struct group grp; #ifdef SHADOWGRP struct sgrp sgrp; #endif /* SHADOWGRP */ /* * To add the group, we need to update /etc/group. * Make sure failures will be reported. */ add_cleanup (cleanup_report_add_group_group, group_name); #ifdef SHADOWGRP if (is_shadow_grp) { /* We also need to update /etc/gshadow */ add_cleanup (cleanup_report_add_group_gshadow, group_name); } #endif /* * Create the initial entries for this new group. */ new_grent (&grp); #ifdef SHADOWGRP new_sgent (&sgrp); if (is_shadow_grp && pflg) { grp.gr_passwd = SHADOW_PASSWD_STRING; /* XXX warning: const */ } #endif /* SHADOWGRP */ /* * Write out the new group file entry. */ if (gr_update (&grp) == 0) { fprintf (stderr, _("%s: failed to prepare the new %s entry '%s'\n"), Prog, gr_dbname (), grp.gr_name); exit (E_GRP_UPDATE); } #ifdef SHADOWGRP /* * Write out the new shadow group entries as well. */ if (is_shadow_grp && (sgr_update (&sgrp) == 0)) { fprintf (stderr, _("%s: failed to prepare the new %s entry '%s'\n"), Prog, sgr_dbname (), sgrp.sg_name); exit (E_GRP_UPDATE); } #endif /* SHADOWGRP */ }
int gr_palette_fade_out (ubyte *pal, int nsteps, int allow_keys) { int i, j, k; ubyte c; fix fade_palette[768]; fix fade_palette_delta[768]; ggi_color fade_colors[256]; if (gr_palette_faded_out) return 0; if (pal==NULL) pal=gr_current_pal; for (i=0; i<768; i++) { gr_current_pal[i] = pal[i]; fade_palette[i] = i2f(pal[i]); fade_palette_delta[i] = fade_palette[i] / nsteps; } for (j=0; j<nsteps; j++) { for (i = 0; i < 768; i++) { fade_palette[i] -= fade_palette_delta[i]; if (fade_palette[i] > i2f(pal[i] + gr_palette_gamma)) fade_palette[i] = i2f(pal[i] + gr_palette_gamma); } for (i = 0, k = 0; k < 256; k++) { c = f2i(fade_palette[i++]); if (c > 63) c = 63; fade_colors[k].r = c * 0x3ff; c = f2i(fade_palette[i++]); if (c > 63) c = 63; fade_colors[k].g = c * 0x3ff; c = f2i(fade_palette[i++]); if (c > 63) c = 63; fade_colors[k].b = c * 0x3ff; } ggiSetPalette (screenvis, 0, 256, fade_colors); gr_update(); } gr_palette_faded_out = 1; return 0; }
int show_title_screen( char * filename, int allow_keys ) { fix timer; int pcx_error; grs_bitmap title_bm; gr_init_bitmap_data (&title_bm); if ((pcx_error=pcx_read_bitmap( filename, &title_bm, BM_LINEAR, New_pal ))!=PCX_ERROR_NONE) { printf( "File '%s', PCX load error: %s (%i)\n (No big deal, just no title screen.)\n",filename, pcx_errormsg(pcx_error), pcx_error); mprintf((0, "File '%s', PCX load error: %s (%i)\n (No big deal, just no title screen.)\n",filename, pcx_errormsg(pcx_error), pcx_error)); Int3(); gr_free_bitmap_data (&title_bm); return 0; } // vfx_set_palette_sub( New_pal ); #ifdef OGL gr_palette_load(New_pal); #else gr_palette_clear(); #endif gr_set_current_canvas( NULL ); show_fullscr(&title_bm); //added on 9/13/98 by adb to make update-needing arch's work gr_update(); //end addition - adb gr_free_bitmap_data (&title_bm); if (allow_keys > 2 || gr_palette_fade_in( New_pal, 32, allow_keys ) || allow_keys > 1) { return 1; } gr_palette_load( New_pal ); timer = timer_get_fixed_seconds() + i2f(3); while (1) { if ( local_key_inkey() && allow_keys ) break; if ( timer_get_fixed_seconds() > timer ) break; } if (gr_palette_fade_out( New_pal, 32, allow_keys )) return 1; return 0; }
static void update_group (struct group *gr) #endif { if (gr_update (gr) == 0) { fprintf (stderr, _("%s: failed to prepare the new %s entry '%s'\n"), Prog, gr_dbname (), gr->gr_name); exit (1); } #ifdef SHADOWGRP if (is_shadowgrp && (sgr_update (sg) == 0)) { fprintf (stderr, _("%s: failed to prepare the new %s entry '%s'\n"), Prog, sgr_dbname (), sg->sg_name); exit (1); } #endif /* SHADOWGRP */ }
int chggrent(char const * login, struct group * grp) { return gr_update(grp, login); }
void draw_automap() { int i; int color; object * objp; vms_vector viewer_position; g3s_point sphere_point; #ifndef AUTOMAP_DIRECT_RENDER #ifndef AUTOMAP_NO_PAGING current_page ^= 1; gr_set_current_canvas(&DrawingPages[current_page]); #else gr_set_current_canvas(&DrawingPages[0]); #endif #endif gr_clear_canvas(0); g3_start_frame(); render_start_frame(); vm_vec_scale_add(&viewer_position,&view_target,&ViewMatrix.fvec,-ViewDist ); g3_set_view_matrix(&viewer_position,&ViewMatrix,Automap_zoom); draw_all_edges(); // Draw player... #ifdef NETWORK if (Game_mode & GM_TEAM) color = get_team(Player_num); else #endif color = Player_num; // Note link to above if! gr_setcolor(gr_getcolor(player_rgb[color].r,player_rgb[color].g,player_rgb[color].b)); draw_player(&Objects[Players[Player_num].objnum]); // Draw player(s)... #ifdef NETWORK if ( (Game_mode & (GM_TEAM | GM_MULTI_COOP)) || (Netgame.game_flags & NETGAME_FLAG_SHOW_MAP) ) { for (i=0; i<N_players; i++) { if ( (i != Player_num) && ((Game_mode & GM_MULTI_COOP) || (get_team(Player_num) == get_team(i)) || (Netgame.game_flags & NETGAME_FLAG_SHOW_MAP)) ) { if ( Objects[Players[i].objnum].type == OBJ_PLAYER ) { if (Game_mode & GM_TEAM) color = get_team(i); else color = i; gr_setcolor(gr_getcolor(player_rgb[color].r,player_rgb[color].g,player_rgb[color].b)); draw_player(&Objects[Players[i].objnum]); } } } } #endif objp = &Objects[0]; for (i=0;i<=Highest_object_index;i++,objp++) { switch( objp->type ) { case OBJ_HOSTAGE: gr_setcolor(BM_XRGB(0,31,0)); g3_rotate_point(&sphere_point,&objp->pos); g3_draw_sphere(&sphere_point,objp->size); break; case OBJ_POWERUP: if ( Automap_visited[objp->segnum] ) { if ( (objp->id==POW_KEY_RED) || (objp->id==POW_KEY_BLUE) || (objp->id==POW_KEY_GOLD) ) { switch (objp->id) { case POW_KEY_RED: gr_setcolor(gr_getcolor(63, 5, 5)); break; case POW_KEY_BLUE: gr_setcolor(gr_getcolor(5, 5, 63)); break; case POW_KEY_GOLD: gr_setcolor(gr_getcolor(63, 63, 10)); break; } g3_rotate_point(&sphere_point,&objp->pos); g3_draw_sphere(&sphere_point,objp->size*4); } } break; } } g3_end_frame(); // gr_bitmapm(5,5,&name_canv->cv_bitmap); gr_set_curfont(GAME_FONT); gr_set_fontcolor(BM_XRGB(0,31,0),-1); gr_uprintf(5,5,name_level); #ifdef OGL ogl_swap_buffers(); #else #ifndef AUTOMAP_DIRECT_RENDER #ifndef AUTOMAP_NO_PAGING gr_show_canvas( &Pages[current_page] ); #else gr_bm_ubitblt( DrawingPages[0].cv_bitmap.bm_w, DrawingPages[0].cv_bitmap.bm_h, DrawingPages[0].cv_bitmap.bm_x, DrawingPages[0].cv_bitmap.bm_y, 0, 0, &DrawingPages[0].cv_bitmap, &Pages[0].cv_bitmap ); // int_gr_update(); gr_update(); #endif #else gr_update(); #endif #endif }
int main (int argc, char **argv) { char buf[BUFSIZ]; char *name; char *newpwd; char *cp; #ifdef SHADOWGRP const struct sgrp *sg; struct sgrp newsg; #endif const struct group *gr; struct group newgr; int errors = 0; int line = 0; Prog = Basename (argv[0]); (void) setlocale (LC_ALL, ""); (void) bindtextdomain (PACKAGE, LOCALEDIR); (void) textdomain (PACKAGE); process_root_flag ("-R", argc, argv); process_flags (argc, argv); OPENLOG ("chgpasswd"); check_perms (); #ifdef SHADOWGRP is_shadow_grp = sgr_file_present (); #endif open_files (); /* * Read each line, separating the group name from the password. The * group entry for each group will be looked up in the appropriate * file (gshadow or group) and the password changed. */ while (fgets (buf, (int) sizeof buf, stdin) != (char *) 0) { line++; cp = strrchr (buf, '\n'); if (NULL != cp) { *cp = '\0'; } else { fprintf (stderr, _("%s: line %d: line too long\n"), Prog, line); errors++; continue; } /* * The group's name is the first field. It is separated from * the password with a ":" character which is replaced with a * NUL to give the new password. The new password will then * be encrypted in the normal fashion with a new salt * generated, unless the '-e' is given, in which case it is * assumed to already be encrypted. */ name = buf; cp = strchr (name, ':'); if (NULL != cp) { *cp = '\0'; cp++; } else { fprintf (stderr, _("%s: line %d: missing new password\n"), Prog, line); errors++; continue; } newpwd = cp; if ( (!eflg) && ( (NULL == crypt_method) || (0 != strcmp (crypt_method, "NONE")))) { void *arg = NULL; const char *salt; if (md5flg) { crypt_method = "MD5"; } #ifdef USE_SHA_CRYPT if (sflg) { arg = &sha_rounds; } #endif salt = crypt_make_salt (crypt_method, arg); cp = pw_encrypt (newpwd, salt); if (NULL == cp) { fprintf (stderr, _("%s: failed to crypt password with salt '%s': %s\n"), Prog, salt, strerror (errno)); fail_exit (1); } } /* * Get the group file entry for this group. The group must * already exist. */ gr = gr_locate (name); if (NULL == gr) { fprintf (stderr, _("%s: line %d: group '%s' does not exist\n"), Prog, line, name); errors++; continue; } #ifdef SHADOWGRP if (is_shadow_grp) { /* The gshadow entry should be updated if the * group entry has a password set to 'x'. * But on the other hand, if there is already both * a group and a gshadow password, it's preferable * to update both. */ sg = sgr_locate (name); if ( (NULL == sg) && (strcmp (gr->gr_passwd, SHADOW_PASSWD_STRING) == 0)) { static char *empty = NULL; /* If the password is set to 'x' in * group, but there are no entries in * gshadow, create one. */ newsg.sg_name = name; /* newsg.sg_passwd = NULL; will be set later */ newsg.sg_adm = ∅ newsg.sg_mem = dup_list (gr->gr_mem); sg = &newsg; } } else { sg = NULL; } #endif /* * The freshly encrypted new password is merged into the * group's entry. */ #ifdef SHADOWGRP if (NULL != sg) { newsg = *sg; newsg.sg_passwd = cp; } if ( (NULL == sg) || (strcmp (gr->gr_passwd, SHADOW_PASSWD_STRING) != 0)) #endif { newgr = *gr; newgr.gr_passwd = cp; } /* * The updated group file entry is then put back and will * be written to the group file later, after all the * other entries have been updated as well. */ #ifdef SHADOWGRP if (NULL != sg) { if (sgr_update (&newsg) == 0) { fprintf (stderr, _("%s: line %d: failed to prepare the new %s entry '%s'\n"), Prog, line, sgr_dbname (), newsg.sg_name); errors++; continue; } } if ( (NULL == sg) || (strcmp (gr->gr_passwd, SHADOW_PASSWD_STRING) != 0)) #endif { if (gr_update (&newgr) == 0) { fprintf (stderr, _("%s: line %d: failed to prepare the new %s entry '%s'\n"), Prog, line, gr_dbname (), newgr.gr_name); errors++; continue; } } } /* * Any detected errors will cause the entire set of changes to be * aborted. Unlocking the group file will cause all of the * changes to be ignored. Otherwise the file is closed, causing the * changes to be written out all at once, and then unlocked * afterwards. */ if (0 != errors) { fprintf (stderr, _("%s: error detected, changes ignored\n"), Prog); fail_exit (1); } close_files (); nscd_flush_cache ("group"); return (0); }
/* * check_grp_file - check the content of the group file */ static void check_grp_file (int *errors, bool *changed) { struct commonio_entry *gre, *tgre; struct group *grp; #ifdef SHADOWGRP struct sgrp *sgr; #endif /* * Loop through the entire group file. */ for (gre = __gr_get_head (); NULL != gre; gre = gre->next) { /* * Skip all NIS entries. */ if ((gre->line[0] == '+') || (gre->line[0] == '-')) { continue; } /* * Start with the entries that are completely corrupt. They * have no (struct group) entry because they couldn't be * parsed properly. */ if (NULL == gre->eptr) { /* * Tell the user this entire line is bogus and ask * them to delete it. */ (void) puts (_("invalid group file entry")); printf (_("delete line '%s'? "), gre->line); *errors += 1; /* * prompt the user to delete the entry or not */ if (!yes_or_no (read_only)) { continue; } /* * All group file deletions wind up here. This code * removes the current entry from the linked list. * When done, it skips back to the top of the loop * to try out the next list element. */ delete_gr: SYSLOG ((LOG_INFO, "delete group line '%s'", gre->line)); *changed = true; __gr_del_entry (gre); continue; } /* * Group structure is good, start using it. */ grp = gre->eptr; /* * Make sure this entry has a unique name. */ for (tgre = __gr_get_head (); NULL != tgre; tgre = tgre->next) { const struct group *ent = tgre->eptr; /* * Don't check this entry */ if (tgre == gre) { continue; } /* * Don't check invalid entries. */ if (NULL == ent) { continue; } if (strcmp (grp->gr_name, ent->gr_name) != 0) { continue; } /* * Tell the user this entry is a duplicate of * another and ask them to delete it. */ (void) puts (_("duplicate group entry")); printf (_("delete line '%s'? "), gre->line); *errors += 1; /* * prompt the user to delete the entry or not */ if (yes_or_no (read_only)) { goto delete_gr; } } /* * Check for invalid group names. --marekm */ if (!is_valid_group_name (grp->gr_name)) { *errors += 1; printf (_("invalid group name '%s'\n"), grp->gr_name); } /* * Check for invalid group ID. */ if (grp->gr_gid == (gid_t)-1) { printf (_("invalid group ID '%lu'\n"), (long unsigned int)grp->gr_gid); *errors += 1; } /* * Workaround for a NYS libc 5.3.12 bug on RedHat 4.2 - * groups with no members are returned as groups with one * member "", causing grpck to fail. --marekm */ if ( (NULL != grp->gr_mem[0]) && (NULL == grp->gr_mem[1]) && ('\0' == grp->gr_mem[0][0])) { grp->gr_mem[0] = NULL; } if (check_members (grp->gr_name, grp->gr_mem, _("group %s: no user %s\n"), _("delete member '%s'? "), "delete member '%s' from group '%s'", errors) == 1) { *changed = true; gre->changed = true; __gr_set_changed (); } #ifdef SHADOWGRP /* * Make sure this entry exists in the /etc/gshadow file. */ if (is_shadow) { sgr = (struct sgrp *) sgr_locate (grp->gr_name); if (sgr == NULL) { printf (_("no matching group file entry in %s\n"), sgr_file); printf (_("add group '%s' in %s? "), grp->gr_name, sgr_file); *errors += 1; if (yes_or_no (read_only)) { struct sgrp sg; struct group gr; static char *empty = NULL; sg.sg_name = grp->gr_name; sg.sg_passwd = grp->gr_passwd; sg.sg_adm = ∅ sg.sg_mem = grp->gr_mem; SYSLOG ((LOG_INFO, "add group '%s' to '%s'", grp->gr_name, sgr_file)); *changed = true; if (sgr_update (&sg) == 0) { fprintf (stderr, _("%s: failed to prepare the new %s entry '%s'\n"), Prog, sgr_dbname (), sg.sg_name); fail_exit (E_CANT_UPDATE); } /* remove password from /etc/group */ gr = *grp; gr.gr_passwd = SHADOW_PASSWD_STRING; /* XXX warning: const */ if (gr_update (&gr) == 0) { fprintf (stderr, _("%s: failed to prepare the new %s entry '%s'\n"), Prog, gr_dbname (), gr.gr_name); fail_exit (E_CANT_UPDATE); } } } else { /** * Verify that all the members defined in /etc/group are also * present in /etc/gshadow. */ compare_members_lists (grp->gr_name, grp->gr_mem, sgr->sg_mem, grp_file, sgr_file); /* The group entry has a gshadow counterpart. * Make sure no passwords are in group. */ if (strcmp (grp->gr_passwd, SHADOW_PASSWD_STRING) != 0) { printf (_("group %s has an entry in %s, but its password field in %s is not set to 'x'\n"), grp->gr_name, sgr_file, grp_file); *errors += 1; } } } #endif } }
/* * add_group - create a new group or add a user to an existing group */ static int add_group (const char *name, const char *gid, gid_t *ngid, uid_t uid) { const struct group *grp; struct group grent; char *members[1]; #ifdef SHADOWGRP const struct sgrp *sg; #endif /* * Start by seeing if the named group already exists. This will be * very easy to deal with if it does. */ grp = getgrnam (gid); if (NULL == grp) { grp = gr_locate (gid); } if (NULL != grp) { /* The user will use this ID for her primary group */ *ngid = grp->gr_gid; /* Don't check gshadow */ return 0; } if (isdigit (gid[0])) { /* * The GID is a number, which means either this is a brand * new group, or an existing group. */ if (get_gid (gid, &grent.gr_gid) == 0) { fprintf (stderr, _("%s: invalid group ID '%s'\n"), Prog, gid); return -1; } /* Look in both the system database (getgrgid) and in the * internal database (gr_locate_gid), which may contain * uncommitted changes */ if ( (getgrgid ((gid_t) grent.gr_gid) != NULL) || (gr_locate_gid ((gid_t) grent.gr_gid) != NULL)) { /* The user will use this ID for her * primary group */ *ngid = (gid_t) grent.gr_gid; return 0; } /* Do not create groups with GID == (gid_t)-1 */ if (grent.gr_gid == (gid_t)-1) { fprintf (stderr, _("%s: invalid group ID '%s'\n"), Prog, gid); return -1; } } else { /* The gid parameter can be "" or a name which is not * already the name of an existing group. * In both cases, figure out what group ID can be used. */ if (find_new_gid(rflg, &grent.gr_gid, &uid) < 0) { return -1; } } /* * Now I have all of the fields required to create the new group. */ if (('\0' != gid[0]) && (!isdigit (gid[0]))) { grent.gr_name = xstrdup (gid); } else { grent.gr_name = xstrdup (name); /* FIXME: check if the group exists */ } /* Check if this is a valid group name */ if (!is_valid_group_name (grent.gr_name)) { fprintf (stderr, _("%s: invalid group name '%s'\n"), Prog, grent.gr_name); if (grent.gr_name) free (grent.gr_name); return -1; } grent.gr_passwd = "*"; /* XXX warning: const */ members[0] = NULL; grent.gr_mem = members; *ngid = grent.gr_gid; #ifdef SHADOWGRP if (is_shadow_grp) { sg = sgr_locate (grent.gr_name); if (NULL != sg) { fprintf (stderr, _("%s: group '%s' is a shadow group, but does not exist in /etc/group\n"), Prog, grent.gr_name); return -1; } } #endif #ifdef SHADOWGRP if (is_shadow_grp) { struct sgrp sgrent; char *admins[1]; sgrent.sg_name = grent.gr_name; sgrent.sg_passwd = "*"; /* XXX warning: const */ grent.gr_passwd = "x"; /* XXX warning: const */ admins[0] = NULL; sgrent.sg_adm = admins; sgrent.sg_mem = members; if (sgr_update (&sgrent) == 0) { return -1; } } #endif if (gr_update (&grent) == 0) { return -1; } return 0; }
static int update_group (void) { int is_member; int was_member; int changed; const struct group *grp; struct group *ngrp; /* * Lock and open the group file. This will load all of the group * entries. */ if (!gr_lock ()) { fprintf (stderr, _("%s: error locking group file\n"), Prog); SYSLOG ((LOG_ERR, "error locking group file")); return -1; } if (!gr_open (O_RDWR)) { fprintf (stderr, _("%s: error opening group file\n"), Prog); SYSLOG ((LOG_ERR, "error opening group file")); gr_unlock (); return -1; } changed = 0; /* * Scan through the entire group file looking for the groups that * the user is a member of. */ while ((grp = gr_next ())) { /* * See if the user specified this group as one of their * concurrent groups. */ was_member = is_on_list (grp->gr_mem, user_name); is_member = Gflg && is_on_list (user_groups, grp->gr_name); if (!was_member && !is_member) continue; ngrp = __gr_dup (grp); if (!ngrp) { fprintf (stderr, _("%s: out of memory in update_group\n"), Prog); gr_unlock (); return -1; } if (was_member && (!Gflg || is_member)) { if (lflg) { ngrp->gr_mem = del_list (ngrp->gr_mem, user_name); ngrp->gr_mem = add_list (ngrp->gr_mem, user_newname); changed = 1; SYSLOG ((LOG_INFO, "change `%s' to `%s' in group `%s'", user_name, user_newname, ngrp->gr_name)); } } else if (was_member && Gflg && !is_member) { ngrp->gr_mem = del_list (ngrp->gr_mem, user_name); changed = 1; SYSLOG ((LOG_INFO, "delete `%s' from group `%s'", user_name, ngrp->gr_name)); } else if (!was_member && Gflg && is_member) { ngrp->gr_mem = add_list (ngrp->gr_mem, lflg ? user_newname : user_name); changed = 1; SYSLOG ((LOG_INFO, "add `%s' to group `%s'", lflg ? user_newname : user_name, ngrp->gr_name)); } if (!changed) continue; changed = 0; if (!gr_update (ngrp)) { fprintf (stderr, _("%s: error adding new group entry\n"), Prog); SYSLOG ((LOG_ERR, "error adding group entry")); gr_unlock (); return -1; } #ifdef NDBM /* * Update the DBM group file with the new entry as well. */ if (!gr_dbm_update (ngrp)) { fprintf (stderr, _("%s: cannot add new dbm group entry\n"), Prog); SYSLOG ((LOG_ERR, "error adding dbm group entry")); gr_unlock (); return -1; } #endif /* NDBM */ } #ifdef NDBM endgrent (); #endif /* NDBM */ if (!gr_close ()) { fprintf (stderr, _("%s: cannot rewrite group file\n"), Prog); gr_unlock (); return -1; } gr_unlock (); return 0; }
/* * grp_update - update group file entries * * grp_update() updates the new records in the memory databases. */ static void grp_update (void) { struct group grp; const struct group *ogrp; #ifdef SHADOWGRP struct sgrp sgrp; const struct sgrp *osgrp = NULL; #endif /* SHADOWGRP */ /* * Get the current settings for this group. */ ogrp = gr_locate (group_name); if (!ogrp) { fprintf (stderr, _("%s: group '%s' does not exist in %s\n"), Prog, group_name, gr_dbname ()); exit (E_GRP_UPDATE); } grp = *ogrp; new_grent (&grp); #ifdef SHADOWGRP if ( is_shadow_grp && (pflg || nflg)) { osgrp = sgr_locate (group_name); if (NULL != osgrp) { sgrp = *osgrp; new_sgent (&sgrp); if (pflg) { grp.gr_passwd = SHADOW_PASSWD_STRING; } } } #endif /* SHADOWGRP */ if (gflg) { update_primary_groups (ogrp->gr_gid, group_newid); } /* * Write out the new group file entry. */ if (gr_update (&grp) == 0) { fprintf (stderr, _("%s: failed to prepare the new %s entry '%s'\n"), Prog, gr_dbname (), grp.gr_name); exit (E_GRP_UPDATE); } if (nflg && (gr_remove (group_name) == 0)) { fprintf (stderr, _("%s: cannot remove entry '%s' from %s\n"), Prog, grp.gr_name, gr_dbname ()); exit (E_GRP_UPDATE); } #ifdef SHADOWGRP /* * Make sure there was a shadow entry to begin with. */ if ( (NULL != osgrp) && (pflg || nflg)) { /* * Write out the new shadow group entries as well. */ if (sgr_update (&sgrp) == 0) { fprintf (stderr, _("%s: failed to prepare the new %s entry '%s'\n"), Prog, sgr_dbname (), sgrp.sg_name); exit (E_GRP_UPDATE); } if (nflg && (sgr_remove (group_name) == 0)) { fprintf (stderr, _("%s: cannot remove entry '%s' from %s\n"), Prog, group_name, sgr_dbname ()); exit (E_GRP_UPDATE); } } #endif /* SHADOWGRP */ }
int delgrent(struct group * grp) { return (gr_update(NULL, grp->gr_name)); }
/* * update_groups - delete user from secondary group set * * update_groups() takes the user name that was given and searches * the group files for membership in any group. * * we also check to see if they have any groups they own (the same * name is their user name) and delete them too (only if USERGROUPS_ENAB * is enabled). */ static void update_groups (void) { const struct group *grp; struct group *ngrp; struct passwd *pwd; #ifdef SHADOWGRP bool deleted_user_group = false; const struct sgrp *sgrp; struct sgrp *nsgrp; #endif /* SHADOWGRP */ /* * Scan through the entire group file looking for the groups that * the user is a member of. */ for (gr_rewind (), grp = gr_next (); NULL != grp; grp = gr_next ()) { /* * See if the user specified this group as one of their * concurrent groups. */ if (!is_on_list (grp->gr_mem, user_name)) { continue; } /* * Delete the username from the list of group members and * update the group entry to reflect the change. */ ngrp = __gr_dup (grp); if (NULL == ngrp) { fprintf (stderr, _("%s: Out of memory. Cannot update %s.\n"), Prog, gr_dbname ()); exit (13); /* XXX */ } ngrp->gr_mem = del_list (ngrp->gr_mem, user_name); if (gr_update (ngrp) == 0) { fprintf (stderr, _("%s: failed to prepare the new %s entry '%s'\n"), Prog, gr_dbname (), ngrp->gr_name); exit (E_GRP_UPDATE); } /* * Update the DBM group file with the new entry as well. */ #ifdef WITH_AUDIT audit_logger (AUDIT_DEL_USER, Prog, "deleting user from group", user_name, (unsigned int) user_id, SHADOW_AUDIT_SUCCESS); #endif SYSLOG ((LOG_INFO, "delete '%s' from group '%s'\n", user_name, ngrp->gr_name)); } /* * we've removed their name from all the groups above, so * now if they have a group with the same name as their * user name, with no members, we delete it. * FIXME: below, the check for grp->gr_mem[0] is not sufficient. * We should retrieve the group with gr_locate and check * that gr_mem is empty. */ grp = xgetgrnam (user_name); if ( (NULL != grp) && getdef_bool ("USERGROUPS_ENAB") && ( (NULL == grp->gr_mem[0]) || ( (NULL == grp->gr_mem[1]) && (strcmp (grp->gr_mem[0], user_name) == 0)))) { pwd = NULL; if (!fflg) { /* * Scan the passwd file to check if this group is still * used as a primary group. */ setpwent (); while ((pwd = getpwent ()) != NULL) { if (strcmp (pwd->pw_name, user_name) == 0) { continue; } if (pwd->pw_gid == grp->gr_gid) { fprintf (stderr, _("%s: group %s is the primary group of another user and is not removed.\n"), Prog, grp->gr_name); break; } } endpwent (); } if (NULL == pwd) { /* * We can remove this group, it is not the primary * group of any remaining user. */ if (gr_remove (grp->gr_name) == 0) { fprintf (stderr, _("%s: cannot remove entry '%s' from %s\n"), Prog, grp->gr_name, gr_dbname ()); fail_exit (E_GRP_UPDATE); } #ifdef SHADOWGRP deleted_user_group = true; #endif #ifdef WITH_AUDIT audit_logger (AUDIT_DEL_GROUP, Prog, "deleting group", grp->gr_name, AUDIT_NO_ID, SHADOW_AUDIT_SUCCESS); #endif SYSLOG ((LOG_INFO, "removed group '%s' owned by '%s'\n", grp->gr_name, user_name)); } } #ifdef SHADOWGRP if (!is_shadow_grp) { return; } /* * Scan through the entire shadow group file looking for the groups * that the user is a member of. Both the administrative list and * the ordinary membership list is checked. */ for (sgr_rewind (), sgrp = sgr_next (); NULL != sgrp; sgrp = sgr_next ()) { bool was_member, was_admin; /* * See if the user specified this group as one of their * concurrent groups. */ was_member = is_on_list (sgrp->sg_mem, user_name); was_admin = is_on_list (sgrp->sg_adm, user_name); if (!was_member && !was_admin) { continue; } nsgrp = __sgr_dup (sgrp); if (NULL == nsgrp) { fprintf (stderr, _("%s: Out of memory. Cannot update %s.\n"), Prog, sgr_dbname ()); exit (13); /* XXX */ } if (was_member) { nsgrp->sg_mem = del_list (nsgrp->sg_mem, user_name); } if (was_admin) { nsgrp->sg_adm = del_list (nsgrp->sg_adm, user_name); } if (sgr_update (nsgrp) == 0) { fprintf (stderr, _("%s: failed to prepare the new %s entry '%s'\n"), Prog, sgr_dbname (), nsgrp->sg_name); exit (E_GRP_UPDATE); } #ifdef WITH_AUDIT audit_logger (AUDIT_DEL_USER, Prog, "deleting user from shadow group", user_name, (unsigned int) user_id, SHADOW_AUDIT_SUCCESS); #endif SYSLOG ((LOG_INFO, "delete '%s' from shadow group '%s'\n", user_name, nsgrp->sg_name)); } if ( deleted_user_group && (sgr_locate (user_name) != NULL)) { if (sgr_remove (user_name) == 0) { fprintf (stderr, _("%s: cannot remove entry '%s' from %s\n"), Prog, user_name, sgr_dbname ()); fail_exit (E_GRP_UPDATE); } } #endif /* SHADOWGRP */ }
int addgrent(struct group * grp) { return gr_update(grp, NULL); }
/* * grp_update - update group file entries * * grp_update() updates the new records in the memory databases. */ static void grp_update (void) { struct group grp; const struct group *ogrp; #ifdef SHADOWGRP struct sgrp sgrp; const struct sgrp *osgrp = NULL; #endif /* SHADOWGRP */ /* * Get the current settings for this group. */ ogrp = gr_locate (group_name); if (NULL == ogrp) { fprintf (stderr, _("%s: group '%s' does not exist in %s\n"), Prog, group_name, gr_dbname ()); exit (E_GRP_UPDATE); } grp = *ogrp; new_grent (&grp); #ifdef SHADOWGRP if ( is_shadow_grp && (pflg || nflg)) { osgrp = sgr_locate (group_name); if (NULL != osgrp) { sgrp = *osgrp; new_sgent (&sgrp); } else if ( pflg && (strcmp (grp.gr_passwd, SHADOW_PASSWD_STRING) == 0)) { static char *empty = NULL; /* If there is a gshadow file with no entries for * the group, but the group file indicates a * shadowed password, we force the creation of a * gshadow entry when a new password is requested. */ memset (&sgrp, 0, sizeof sgrp); sgrp.sg_name = xstrdup (grp.gr_name); sgrp.sg_passwd = xstrdup (grp.gr_passwd); sgrp.sg_adm = ∅ sgrp.sg_mem = dup_list (grp.gr_mem); new_sgent (&sgrp); osgrp = &sgrp; /* entry needs to be committed */ } } #endif /* SHADOWGRP */ if (gflg) { update_primary_groups (ogrp->gr_gid, group_newid); } /* * Write out the new group file entry. */ if (gr_update (&grp) == 0) { fprintf (stderr, _("%s: failed to prepare the new %s entry '%s'\n"), Prog, gr_dbname (), grp.gr_name); exit (E_GRP_UPDATE); } if (nflg && (gr_remove (group_name) == 0)) { fprintf (stderr, _("%s: cannot remove entry '%s' from %s\n"), Prog, grp.gr_name, gr_dbname ()); exit (E_GRP_UPDATE); } #ifdef SHADOWGRP /* * Make sure there was a shadow entry to begin with. */ if (NULL != osgrp) { /* * Write out the new shadow group entries as well. */ if (sgr_update (&sgrp) == 0) { fprintf (stderr, _("%s: failed to prepare the new %s entry '%s'\n"), Prog, sgr_dbname (), sgrp.sg_name); exit (E_GRP_UPDATE); } if (nflg && (sgr_remove (group_name) == 0)) { fprintf (stderr, _("%s: cannot remove entry '%s' from %s\n"), Prog, group_name, sgr_dbname ()); exit (E_GRP_UPDATE); } } #endif /* SHADOWGRP */ }
/* * update_groups - delete user from secondary group set * * update_groups() takes the user name that was given and searches * the group files for membership in any group. * * we also check to see if they have any groups they own (the same * name is their user name) and delete them too (only if USERGROUPS_ENAB * is enabled). */ static void update_groups (void) { const struct group *grp; struct group *ngrp; #ifdef SHADOWGRP const struct sgrp *sgrp; struct sgrp *nsgrp; #endif /* SHADOWGRP */ /* * Scan through the entire group file looking for the groups that * the user is a member of. */ for (gr_rewind (), grp = gr_next (); NULL != grp; grp = gr_next ()) { /* * See if the user specified this group as one of their * concurrent groups. */ if (!is_on_list (grp->gr_mem, user_name)) { continue; } /* * Delete the username from the list of group members and * update the group entry to reflect the change. */ ngrp = __gr_dup (grp); if (NULL == ngrp) { fprintf (stderr, _("%s: Out of memory. Cannot update %s.\n"), Prog, gr_dbname ()); exit (13); /* XXX */ } ngrp->gr_mem = del_list (ngrp->gr_mem, user_name); if (gr_update (ngrp) == 0) { fprintf (stderr, _("%s: failed to prepare the new %s entry '%s'\n"), Prog, gr_dbname (), ngrp->gr_name); exit (E_GRP_UPDATE); } /* * Update the DBM group file with the new entry as well. */ #ifdef WITH_AUDIT audit_logger (AUDIT_DEL_USER, Prog, "deleting user from group", user_name, (unsigned int) user_id, SHADOW_AUDIT_SUCCESS); #endif /* WITH_AUDIT */ SYSLOG ((LOG_INFO, "delete '%s' from group '%s'\n", user_name, ngrp->gr_name)); } if (getdef_bool ("USERGROUPS_ENAB")) { remove_usergroup (); } #ifdef SHADOWGRP if (!is_shadow_grp) { return; } /* * Scan through the entire shadow group file looking for the groups * that the user is a member of. Both the administrative list and * the ordinary membership list is checked. */ for (sgr_rewind (), sgrp = sgr_next (); NULL != sgrp; sgrp = sgr_next ()) { bool was_member, was_admin; /* * See if the user specified this group as one of their * concurrent groups. */ was_member = is_on_list (sgrp->sg_mem, user_name); was_admin = is_on_list (sgrp->sg_adm, user_name); if (!was_member && !was_admin) { continue; } nsgrp = __sgr_dup (sgrp); if (NULL == nsgrp) { fprintf (stderr, _("%s: Out of memory. Cannot update %s.\n"), Prog, sgr_dbname ()); exit (13); /* XXX */ } if (was_member) { nsgrp->sg_mem = del_list (nsgrp->sg_mem, user_name); } if (was_admin) { nsgrp->sg_adm = del_list (nsgrp->sg_adm, user_name); } if (sgr_update (nsgrp) == 0) { fprintf (stderr, _("%s: failed to prepare the new %s entry '%s'\n"), Prog, sgr_dbname (), nsgrp->sg_name); exit (E_GRP_UPDATE); } #ifdef WITH_AUDIT audit_logger (AUDIT_DEL_USER, Prog, "deleting user from shadow group", user_name, (unsigned int) user_id, SHADOW_AUDIT_SUCCESS); #endif /* WITH_AUDIT */ SYSLOG ((LOG_INFO, "delete '%s' from shadow group '%s'\n", user_name, nsgrp->sg_name)); } #endif /* SHADOWGRP */ }
int main (int argc, char **argv) { const struct group *gr; struct group grent; const struct sgrp *sg; struct sgrp sgent; Prog = Basename (argv[0]); (void) setlocale (LC_ALL, ""); (void) bindtextdomain (PACKAGE, LOCALEDIR); (void) textdomain (PACKAGE); process_root_flag ("-R", argc, argv); OPENLOG ("grpconv"); process_flags (argc, argv); if (gr_lock () == 0) { fprintf (stderr, _("%s: cannot lock %s; try again later.\n"), Prog, gr_dbname ()); fail_exit (5); } gr_locked = true; if (gr_open (O_CREAT | O_RDWR) == 0) { fprintf (stderr, _("%s: cannot open %s\n"), Prog, gr_dbname ()); fail_exit (1); } if (sgr_lock () == 0) { fprintf (stderr, _("%s: cannot lock %s; try again later.\n"), Prog, sgr_dbname ()); fail_exit (5); } sgr_locked = true; if (sgr_open (O_CREAT | O_RDWR) == 0) { fprintf (stderr, _("%s: cannot open %s\n"), Prog, sgr_dbname ()); fail_exit (1); } /* * Remove /etc/gshadow entries for groups not in /etc/group. */ (void) sgr_rewind (); while ((sg = sgr_next ()) != NULL) { if (gr_locate (sg->sg_name) != NULL) { continue; } if (sgr_remove (sg->sg_name) == 0) { /* * This shouldn't happen (the entry exists) but... */ fprintf (stderr, _("%s: cannot remove entry '%s' from %s\n"), Prog, sg->sg_name, sgr_dbname ()); fail_exit (3); } } /* * Update shadow group passwords if non-shadow password is not "x". * Add any missing shadow group entries. */ (void) gr_rewind (); while ((gr = gr_next ()) != NULL) { sg = sgr_locate (gr->gr_name); if (NULL != sg) { /* update existing shadow group entry */ sgent = *sg; if (strcmp (gr->gr_passwd, SHADOW_PASSWD_STRING) != 0) sgent.sg_passwd = gr->gr_passwd; } else { static char *empty = 0; /* add new shadow group entry */ memset (&sgent, 0, sizeof sgent); sgent.sg_name = gr->gr_name; sgent.sg_passwd = gr->gr_passwd; sgent.sg_adm = ∅ } /* * XXX - sg_mem is redundant, it is currently always a copy * of gr_mem. Very few programs actually use sg_mem, and all * of them are in the shadow suite. Maybe this field could * be used for something else? Any suggestions? */ sgent.sg_mem = gr->gr_mem; if (sgr_update (&sgent) == 0) { fprintf (stderr, _("%s: failed to prepare the new %s entry '%s'\n"), Prog, sgr_dbname (), sgent.sg_name); fail_exit (3); } /* remove password from /etc/group */ grent = *gr; grent.gr_passwd = SHADOW_PASSWD_STRING; /* XXX warning: const */ if (gr_update (&grent) == 0) { fprintf (stderr, _("%s: failed to prepare the new %s entry '%s'\n"), Prog, gr_dbname (), grent.gr_name); fail_exit (3); } } if (sgr_close () == 0) { fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, sgr_dbname ()); SYSLOG ((LOG_ERR, "failure while writing changes to %s", sgr_dbname ())); fail_exit (3); } if (gr_close () == 0) { fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, gr_dbname ()); SYSLOG ((LOG_ERR, "failure while writing changes to %s", gr_dbname ())); fail_exit (3); } if (sgr_unlock () == 0) { fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname ()); SYSLOG ((LOG_ERR, "failed to unlock %s", sgr_dbname ())); /* continue */ } if (gr_unlock () == 0) { fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ()); SYSLOG ((LOG_ERR, "failed to unlock %s", gr_dbname ())); /* continue */ } nscd_flush_cache ("group"); return 0; }
// ----------------------------------------------------------------------------- // Return true if message got aborted by user (pressed ESC), else return false. int show_briefing_message(int screen_num, char *message) { int prev_ch=-1; int ch, done=0; briefing_screen *bsp = &Briefing_screens[screen_num]; int delay_count = KEY_DELAY_DEFAULT; int key_check; int robot_num=-1; int rval=0; int tab_stop=0; int flashing_cursor=0; int new_page=0; int text_ulx = rescale_x(bsp->text_ulx); int text_uly = rescale_y(bsp->text_uly); Bitmap_name[0] = 0; Current_color = 0; // mprintf((0, "Going to print message [%s] at x=%i, y=%i\n", message, x, y)); gr_set_curfont( GAME_FONT ); init_char_pos(text_ulx, text_uly); while (!done) { ch = *message++; if (ch == '$') { ch = *message++; if (ch == 'C') { Current_color = get_message_num(&message)-1; Assert((Current_color >= 0) && (Current_color < MAX_BRIEFING_COLORS)); prev_ch = 10; } else if (ch == 'F') { // toggle flashing cursor flashing_cursor = !flashing_cursor; prev_ch = 10; while (*message++ != 10) ; } else if (ch == 'T') { tab_stop = get_message_num(&message); prev_ch = 10; // read to eoln } else if (ch == 'R') { if (Robot_canv != NULL) {free(Robot_canv); Robot_canv=NULL;} init_spinning_robot(); robot_num = get_message_num(&message); prev_ch = 10; // read to eoln } else if (ch == 'N') { //--grs_bitmap *bitmap_ptr; if (Robot_canv != NULL) {free(Robot_canv); Robot_canv=NULL;} get_message_name(&message, Bitmap_name); strcat(Bitmap_name, "#0"); Animating_bitmap_type = 0; prev_ch = 10; } else if (ch == 'O') { if (Robot_canv != NULL) {free(Robot_canv); Robot_canv=NULL;} get_message_name(&message, Bitmap_name); strcat(Bitmap_name, "#0"); Animating_bitmap_type = 1; prev_ch = 10; } else if (ch == 'B') { char bitmap_name[32]; grs_bitmap guy_bitmap; ubyte temp_palette[768]; int iff_error; if (Robot_canv != NULL) {free(Robot_canv); Robot_canv=NULL;} get_message_name(&message, bitmap_name); strcat(bitmap_name, ".bbm"); gr_init_bitmap_data (&guy_bitmap); iff_error = iff_read_bitmap(bitmap_name, &guy_bitmap, BM_LINEAR, temp_palette); Assert(iff_error == IFF_NO_ERROR); show_briefing_bitmap(&guy_bitmap); gr_free_bitmap_data (&guy_bitmap); prev_ch = 10; // } else if (ch == 'B') { // if (Robot_canv != NULL) // {free(Robot_canv); Robot_canv=NULL;} // // bitmap_num = get_message_num(&message); // if (bitmap_num != -1) // show_briefing_bitmap(Textures[bitmap_num]); // prev_ch = 10; // read to eoln } else if (ch == 'S') { int keypress; fix start_time; fix time_out_value; start_time = timer_get_fixed_seconds(); start_time = timer_get_approx_seconds(); time_out_value = start_time + i2f(60*5); // Wait 1 minute... //added on 9/13/98 by adb to make arch's requiring updates work gr_update(); //end changes by adb while ( (keypress = local_key_inkey()) == 0 ) { // Wait for a key if ( timer_get_approx_seconds() > time_out_value ) { keypress = 0; break; // Time out after 1 minute.. } while (timer_get_fixed_seconds() < start_time + KEY_DELAY_DEFAULT/2) ; flash_cursor(flashing_cursor); show_spinning_robot_frame(robot_num); show_bitmap_frame(); //added on 9/13/98 by adb to make arch's requiring updates work gr_update(); //end changes by adb start_time += KEY_DELAY_DEFAULT/2; } #ifndef NDEBUG if (keypress == KEY_BACKSP) Int3(); #endif if (keypress == KEY_ESC) rval = 1; flashing_cursor = 0; done = 1; } else if (ch == 'P') { // New page. new_page = 1; while (*message != 10) { message++; // drop carriage return after special escape sequence } message++; prev_ch = 10; //Begin D1X addition } else if (ch == '$' || ch == ';') { // Print a $/; prev_ch = ch; Briefing_text_x += show_char_delay((char) ch, delay_count, robot_num, flashing_cursor); //End D1X addition } } else if (ch == '\t') { // Tab if (Briefing_text_x - text_ulx < tab_stop) Briefing_text_x = text_ulx + tab_stop; } else if ((ch == ';') && (prev_ch == 10)) { while (*message++ != 10) ; prev_ch = 10; } else if (ch == '\\') { prev_ch = ch; } else if (ch == 10) { if (prev_ch != '\\') { prev_ch = ch; Briefing_text_y += GAME_FONT->ft_h+GAME_FONT->ft_h*3/5; Briefing_text_x = text_ulx; if (Briefing_text_y > text_uly + rescale_y(bsp->text_height)) { load_briefing_screen(screen_num); Briefing_text_x = text_ulx; Briefing_text_y = text_uly; } } else { if (ch == 13) Int3(); prev_ch = ch; } } else { prev_ch = ch; Briefing_text_x += show_char_delay((char) ch, delay_count, robot_num, flashing_cursor); } //added/changed on 9/13/98 by adb to speed up briefings after pressing a key with SDL // Check for Esc -> abort. if(delay_count) key_check=local_key_inkey(); else key_check=0; //end change - adb if ( key_check == KEY_ESC ) { rval = 1; done = 1; } if ( key_check == KEY_ALTED+KEY_F2 ) title_save_game(); if ((key_check == KEY_SPACEBAR) || (key_check == KEY_ENTER)) delay_count = 0; if (Briefing_text_x > text_ulx + rescale_x(bsp->text_width)) { Briefing_text_x = text_ulx; Briefing_text_y += GAME_FONT->ft_h+GAME_FONT->ft_h*3/5; } if ((new_page) || (Briefing_text_y > text_uly + rescale_y(bsp->text_height))) { fix start_time = 0; fix time_out_value = 0; int keypress; new_page = 0; start_time = timer_get_approx_seconds(); time_out_value = start_time + i2f(60*5); // Wait 1 minute... //added on 9/13/98 by adb to make arch's requiring updates work gr_update(); //end changes by adb while ( (keypress = local_key_inkey()) == 0 ) { // Wait for a key if ( timer_get_approx_seconds() > time_out_value ) { keypress = 0; break; // Time out after 1 minute.. } while (timer_get_approx_seconds() < start_time + KEY_DELAY_DEFAULT/2) ; flash_cursor(flashing_cursor); show_spinning_robot_frame(robot_num); show_bitmap_frame(); //added on 9/13/98 by adb to make arch's requiring updates work gr_update(); //end changes by adb start_time += KEY_DELAY_DEFAULT/2; } robot_num = -1; #ifndef NDEBUG if (keypress == KEY_BACKSP) Int3(); #endif if (keypress == KEY_ESC) { rval = 1; done = 1; } load_briefing_screen(screen_num); Briefing_text_x = text_ulx; Briefing_text_y = text_uly; delay_count = KEY_DELAY_DEFAULT; } } if (Robot_canv != NULL) {free(Robot_canv); Robot_canv=NULL;} return rval; }
static void grp_update (void) { struct group grp; #ifdef SHADOWGRP struct sgrp sgrp; #endif /* SHADOWGRP */ /* * Create the initial entries for this new group. */ new_grent (&grp); #ifdef SHADOWGRP new_sgent (&sgrp); #endif /* SHADOWGRP */ /* * Write out the new group file entry. */ if (!gr_update (&grp)) { fprintf (stderr, _("%s: error adding new group entry\n"), Prog); fail_exit (E_GRP_UPDATE); } #ifdef NDBM /* * Update the DBM group file with the new entry as well. */ if (gr_dbm_present () && !gr_dbm_update (&grp)) { fprintf (stderr, _("%s: cannot add new dbm group entry\n"), Prog); fail_exit (E_GRP_UPDATE); } endgrent (); #endif /* NDBM */ #ifdef SHADOWGRP /* * Write out the new shadow group entries as well. */ if (is_shadow_grp && !sgr_update (&sgrp)) { fprintf (stderr, _("%s: error adding new group entry\n"), Prog); fail_exit (E_GRP_UPDATE); } #ifdef NDBM /* * Update the DBM group file with the new entry as well. */ if (is_shadow_grp && sg_dbm_present () && !sg_dbm_update (&sgrp)) { fprintf (stderr, _("%s: cannot add new dbm group entry\n"), Prog); fail_exit (E_GRP_UPDATE); } endsgent (); #endif /* NDBM */ #endif /* SHADOWGRP */ SYSLOG ((LOG_INFO, "new group: name=%s, gid=%u", group_name, (unsigned int)group_id)); }
static void update_groups(void) { const struct group *grp; struct group *ngrp; #ifdef SHADOWGRP const struct sgrp *sgrp; struct sgrp *nsgrp; #endif /* SHADOWGRP */ /* * Scan through the entire group file looking for the groups that * the user is a member of. */ for (gr_rewind (), grp = gr_next ();grp;grp = gr_next ()) { /* * See if the user specified this group as one of their * concurrent groups. */ if (!is_on_list(grp->gr_mem, user_name)) continue; /* * Delete the username from the list of group members and * update the group entry to reflect the change. */ ngrp = __gr_dup(grp); if (!ngrp) { exit(13); /* XXX */ } ngrp->gr_mem = del_list (ngrp->gr_mem, user_name); if (!gr_update(ngrp)) fprintf(stderr, _("%s: error updating group entry\n"), Prog); /* * Update the DBM group file with the new entry as well. */ #ifdef NDBM if (!gr_dbm_update(ngrp)) fprintf(stderr, _("%s: cannot update dbm group entry\n"), Prog); #endif /* NDBM */ SYSLOG((LOG_INFO, "delete `%s' from group `%s'\n", user_name, ngrp->gr_name)); } #ifdef NDBM endgrent (); #endif /* NDBM */ #ifdef SHADOWGRP if (!is_shadow_grp) return; /* * Scan through the entire shadow group file looking for the groups * that the user is a member of. Both the administrative list and * the ordinary membership list is checked. */ for (sgr_rewind (), sgrp = sgr_next ();sgrp;sgrp = sgr_next ()) { int was_member, was_admin; /* * See if the user specified this group as one of their * concurrent groups. */ was_member = is_on_list(sgrp->sg_mem, user_name); was_admin = is_on_list(sgrp->sg_adm, user_name); if (!was_member && !was_admin) continue; nsgrp = __sgr_dup(sgrp); if (!nsgrp) { exit(13); /* XXX */ } if (was_member) nsgrp->sg_mem = del_list (nsgrp->sg_mem, user_name); if (was_admin) nsgrp->sg_adm = del_list (nsgrp->sg_adm, user_name); if (!sgr_update(nsgrp)) fprintf(stderr, _("%s: error updating group entry\n"), Prog); #ifdef NDBM /* * Update the DBM group file with the new entry as well. */ if (!sg_dbm_update(nsgrp)) fprintf(stderr, _("%s: cannot update dbm group entry\n"), Prog); #endif /* NDBM */ SYSLOG((LOG_INFO, "delete `%s' from shadow group `%s'\n", user_name, nsgrp->sg_name)); } #ifdef NDBM endsgent (); #endif /* NDBM */ #endif /* SHADOWGRP */ }
int main (int argc, char **argv) { const struct group *gr; struct group grent; const struct sgrp *sg; Prog = Basename (argv[0]); (void) setlocale (LC_ALL, ""); (void) bindtextdomain (PACKAGE, LOCALEDIR); (void) textdomain (PACKAGE); process_root_flag ("-R", argc, argv); OPENLOG ("grpunconv"); process_flags (argc, argv); if (sgr_file_present () == 0) { exit (0); /* no /etc/gshadow, nothing to do */ } if (gr_lock () == 0) { fprintf (stderr, _("%s: cannot lock %s; try again later.\n"), Prog, gr_dbname ()); fail_exit (5); } gr_locked = true; if (gr_open (O_RDWR) == 0) { fprintf (stderr, _("%s: cannot open %s\n"), Prog, gr_dbname ()); fail_exit (1); } if (sgr_lock () == 0) { fprintf (stderr, _("%s: cannot lock %s; try again later.\n"), Prog, sgr_dbname ()); fail_exit (5); } sgr_locked = true; if (sgr_open (O_RDONLY) == 0) { fprintf (stderr, _("%s: cannot open %s\n"), Prog, sgr_dbname ()); fail_exit (1); } /* * Update group passwords if non-shadow password is "x". */ (void) gr_rewind (); while ((gr = gr_next ()) != NULL) { sg = sgr_locate (gr->gr_name); if ( (NULL != sg) && (strcmp (gr->gr_passwd, SHADOW_PASSWD_STRING) == 0)) { /* add password to /etc/group */ grent = *gr; grent.gr_passwd = sg->sg_passwd; if (gr_update (&grent) == 0) { fprintf (stderr, _("%s: failed to prepare the new %s entry '%s'\n"), Prog, gr_dbname (), grent.gr_name); fail_exit (3); } } } (void) sgr_close (); /* was only open O_RDONLY */ if (gr_close () == 0) { fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, gr_dbname ()); SYSLOG ((LOG_ERR, "failure while writing changes to %s", gr_dbname ())); fail_exit (3); } if (unlink (SGROUP_FILE) != 0) { fprintf (stderr, _("%s: cannot delete %s\n"), Prog, SGROUP_FILE); SYSLOG ((LOG_ERR, "cannot delete %s", SGROUP_FILE)); fail_exit (3); } if (gr_unlock () == 0) { fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ()); SYSLOG ((LOG_ERR, "failed to unlock %s", gr_dbname ())); /* continue */ } if (sgr_unlock () == 0) { fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname ()); SYSLOG ((LOG_ERR, "failed to unlock %s", sgr_dbname ())); /* continue */ } nscd_flush_cache ("group"); return 0; }
void ui_mega_process() { int mx, my; unsigned char k; #ifdef __LINUX__ gr_update(); #endif switch( Record ) { case 0: mouse_get_delta( &mx, &my ); Mouse.new_dx = mx; Mouse.new_dy = my; Mouse.new_buttons = mouse_get_btns(); last_keypress = key_inkey(); if ( Mouse.new_buttons || last_keypress || Mouse.new_dx || Mouse.new_dy ) { last_event = TICKER; } break; case 1: if (ui_event_counter==0 ) { EventBuffer[ui_event_counter].frame = 0; EventBuffer[ui_event_counter].type = 7; EventBuffer[ui_event_counter].data = ui_number_of_events; ui_event_counter++; } if (ui_event_counter==1 && (RecordFlags & UI_RECORD_MOUSE) ) { Mouse.new_buttons = 0; EventBuffer[ui_event_counter].frame = FrameCount; EventBuffer[ui_event_counter].type = 6; EventBuffer[ui_event_counter].data = ((Mouse.y & 0xFFFF) << 16) | (Mouse.x & 0xFFFF); ui_event_counter++; } mouse_get_delta( &mx, &my ); MouseDX = mx; MouseDY = my; MouseButtons = mouse_get_btns(); Mouse.new_dx = MouseDX; Mouse.new_dy = MouseDY; if ((MouseDX != 0 || MouseDY != 0) && (RecordFlags & UI_RECORD_MOUSE) ) { if (ui_event_counter < ui_number_of_events-1 ) { EventBuffer[ui_event_counter].frame = FrameCount; EventBuffer[ui_event_counter].type = 1; EventBuffer[ui_event_counter].data = ((MouseDY & 0xFFFF) << 16) | (MouseDX & 0xFFFF); ui_event_counter++; //mprintf( 0, "EVENT:%d, Mouse moved %d,%d\n", ui_event_counter, MouseDX, MouseDY ); } else { Record = 0; } } if ( (MouseButtons != Mouse.new_buttons) && (RecordFlags & UI_RECORD_MOUSE) ) { Mouse.new_buttons = MouseButtons; if (ui_event_counter < ui_number_of_events-1 ) { EventBuffer[ui_event_counter].frame = FrameCount; EventBuffer[ui_event_counter].type = 2; EventBuffer[ui_event_counter].data = MouseButtons; ui_event_counter++; //mprintf( 0, "EVENT:%d, Mouse buttons changed %d\n", ui_event_counter, MouseButtons ); } else { Record = 0; } } if ( keyd_last_pressed && (RecordFlags & UI_RECORD_KEYS) ) { _disable(); k = keyd_last_pressed; keyd_last_pressed= 0; _enable(); if (ui_event_counter < ui_number_of_events-1 ) { EventBuffer[ui_event_counter].frame = FrameCount; EventBuffer[ui_event_counter].type = 3; EventBuffer[ui_event_counter].data = k; ui_event_counter++; //mprintf( 0, "EVENT:%d, Key %d pressed\n", ui_event_counter, k ); } else { Record = 0; } } if ( keyd_last_released && (RecordFlags & UI_RECORD_KEYS) ) { _disable(); k = keyd_last_released; keyd_last_released= 0; _enable(); if (ui_event_counter < ui_number_of_events-1 ) { EventBuffer[ui_event_counter].frame = FrameCount; EventBuffer[ui_event_counter].type = 4; EventBuffer[ui_event_counter].data = k; ui_event_counter++; //mprintf( 0, "EVENT:%d, Key %d released\n", ui_event_counter, k ); } else { Record = 0; } } last_keypress = key_inkey(); if (last_keypress == KEY_F12 ) { ui_number_of_events = ui_event_counter; last_keypress = 0; Record = 0; break; } if ((last_keypress != 0) && (RecordFlags & UI_RECORD_KEYS) ) { if (ui_event_counter < ui_number_of_events-1 ) { EventBuffer[ui_event_counter].frame = FrameCount; EventBuffer[ui_event_counter].type = 5; EventBuffer[ui_event_counter].data = last_keypress; ui_event_counter++; //mprintf( 0, "EVENT:%d, Keypressed %d\n", ui_event_counter, last_keypress ); } else { Record = 0; } } FrameCount++; break; case 2: case 3: Mouse.new_dx = 0; Mouse.new_dy = 0; Mouse.new_buttons = 0; last_keypress = 0; if ( keyd_last_pressed ) { _disable(); k = keyd_last_pressed; keyd_last_pressed = 0; _disable(); SavedState[k] = 1; } if ( keyd_last_released ) { _disable(); k = keyd_last_released; keyd_last_released = 0; _disable(); SavedState[k] = 0; } if (key_inkey() == KEY_F12 ) { //mprintf( 0, "Playing stopped.\n" ); restore_state(); Record = 0; break; } if (EventBuffer==NULL) { restore_state(); Record = 0; break; } while( (ui_event_counter < ui_number_of_events) && (EventBuffer[ui_event_counter].frame <= FrameCount) ) { switch ( EventBuffer[ui_event_counter].type ) { case 1: // Mouse moved Mouse.new_dx = EventBuffer[ui_event_counter].data & 0xFFFF; Mouse.new_dy = (EventBuffer[ui_event_counter].data >> 16) & 0xFFFF; break; case 2: // Mouse buttons changed Mouse.new_buttons = EventBuffer[ui_event_counter].data; break; case 3: // Key moved down keyd_pressed[ EventBuffer[ui_event_counter].data ] = 1; break; case 4: // Key moved up keyd_pressed[ EventBuffer[ui_event_counter].data ] = 0; break; case 5: // Key pressed last_keypress = EventBuffer[ui_event_counter].data; break; case 6: // Initial Mouse X position Mouse.x = EventBuffer[ui_event_counter].data & 0xFFFF; Mouse.y = (EventBuffer[ui_event_counter].data >> 16) & 0xFFFF; break; case 7: break; } ui_event_counter++; if (ui_event_counter >= ui_number_of_events ) { Record = 0; restore_state(); //( 0, "Done playing %d events.\n", ui_number_of_events ); } } switch (Record) { case 2: { int next_frame; if ( ui_event_counter < ui_number_of_events ) { next_frame = EventBuffer[ui_event_counter].frame; if ( (FrameCount+PlaybackSpeed) < next_frame ) FrameCount = next_frame - PlaybackSpeed; else FrameCount++; } else { FrameCount++; } } break; case 3: if ( ui_event_counter < ui_number_of_events ) FrameCount = EventBuffer[ui_event_counter].frame; else FrameCount++; break; default: FrameCount++; } } ui_mouse_process(); }