/* * close_files - close and unlock the group databases */ static void close_files (void) { #ifdef SHADOWGRP if (is_shadow_grp) { 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 (1); } 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 */ } sgr_locked = false; } #endif 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 (1); } 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 */ } gr_locked = false; }
/* * close_files - close and unlock the group databases * * This cause any changes in the databases to be committed. * * It will call exit in case of error. */ static void close_files (void) { if (gr_close () == 0) { fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, gr_dbname ()); exit (E_NOPERM); } add_cleanup (log_gpasswd_success_group, NULL); del_cleanup (log_gpasswd_failure_group); cleanup_unlock_group (NULL); del_cleanup (cleanup_unlock_group); #ifdef SHADOWGRP if (is_shadowgrp) { if (sgr_close () == 0) { fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, sgr_dbname ()); exit (E_NOPERM); } del_cleanup (log_gpasswd_failure_gshadow); cleanup_unlock_gshadow (NULL); del_cleanup (cleanup_unlock_gshadow); } #endif /* SHADOWGRP */ log_gpasswd_success_system (NULL); del_cleanup (log_gpasswd_success_group); }
void test::FSTestFixture::TearDown() { if (_initFlags & INIT_SHIPS) { ship_close(); } if (_initFlags & INIT_GRAPHICS) { io::mouse::CursorManager::shutdown(); bm_unload_all(); gr_close(nullptr); } cfile_close(); timer_close(); lcl_close(); os_cleanup(); #ifndef NDEBUG outwnd_close(); #endif // although the comment in cmdline.cpp said this isn't needed, // Valgrind disagrees (quite possibly incorrectly), but this is just cleaner if (Cmdline_mod != NULL) { delete[] Cmdline_mod; Cmdline_mod = NULL; } }
int main() { void *gr; //gr = gr_init("test", "127.0.0.1:6785", 0); //gr = gr_init("test", "192.168.13.101:9001", 0); printf("init\n"); gr = gr_init("test", "/var/run/garner.sock", 0); printf("gr_log1\n"); gr_log(gr, "test\n"); sleep(5); gr_log(gr, "test\n"); printf("gr_log2\n"); gr_close(gr); #if 0 u_int8_t buffer[1024]; int len; memset(buffer, 0, sizeof(buffer)); len = gr_read(gr, buffer, sizeof(buffer)); printf("got %d errno=%s: %s\n", len, strerror(errno), buffer); buffer[0] = '\0'; gr_log(gr, "MAIL FROM: <vinod@rhel5>\r\n"); len = gr_read(gr, buffer, sizeof(buffer)); printf("got %d errno=%s: %s\n", len, strerror(errno), buffer); buffer[0] = '\0'; gr_log(gr, "RCPT To: <vinod@rhel5>\r\n"); len = gr_read(gr, buffer, sizeof(buffer)); printf("got %d errno=%s: %s\n", len, strerror(errno), buffer); buffer[0] = '\0'; gr_log(gr, "DATA\r\n"); len = gr_read(gr, buffer, sizeof(buffer)); printf("got %d errno=%s: %s\n", len, strerror(errno), buffer); buffer[0] = '\0'; gr_log(gr, "Subject: test mail from gr\r\n\r\nThis is test.\r\n.\r\n"); len = gr_read(gr, buffer, sizeof(buffer)); printf("got %d errno=%s: %s\n", len, strerror(errno), buffer); buffer[0] = '\0'; gr_log(gr, "QUIT\r\n"); len = gr_read(gr, buffer, sizeof(buffer)); printf("got %d errno=%s: %s\n", len, strerror(errno), buffer); buffer[0] = '\0'; gr_close(gr); #endif return 0; }
/* * close_files - close all of the files that were opened * * close_files() closes all of the files that were opened for this new * group. This causes any modified entries to be written out. */ static void close_files (void) { /* First, write the changes in the regular group database */ if (gr_close () == 0) { fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, gr_dbname ()); exit (E_GRP_UPDATE); } #ifdef WITH_AUDIT audit_logger (AUDIT_ADD_GROUP, Prog, "adding group to /etc/group", group_name, (unsigned int) group_id, SHADOW_AUDIT_SUCCESS); #endif SYSLOG ((LOG_INFO, "group added to %s: name=%s, GID=%u", gr_dbname (), group_name, (unsigned int) group_id)); del_cleanup (cleanup_report_add_group_group); cleanup_unlock_group (NULL); del_cleanup (cleanup_unlock_group); /* Now, write the changes in the shadow database */ #ifdef SHADOWGRP if (is_shadow_grp) { if (sgr_close () == 0) { fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, sgr_dbname ()); exit (E_GRP_UPDATE); } #ifdef WITH_AUDIT audit_logger (AUDIT_ADD_GROUP, Prog, "adding group to /etc/gshadow", group_name, (unsigned int) group_id, SHADOW_AUDIT_SUCCESS); #endif SYSLOG ((LOG_INFO, "group added to %s: name=%s", sgr_dbname (), group_name)); del_cleanup (cleanup_report_add_group_gshadow); cleanup_unlock_gshadow (NULL); del_cleanup (cleanup_unlock_gshadow); } #endif /* SHADOWGRP */ /* Report success at the system level */ #ifdef WITH_AUDIT audit_logger (AUDIT_ADD_GROUP, Prog, "", group_name, (unsigned int) group_id, SHADOW_AUDIT_SUCCESS); #endif SYSLOG ((LOG_INFO, "new group: name=%s, GID=%u", group_name, (unsigned int) group_id)); del_cleanup (cleanup_report_add_group); }
/********************************************************************* * アナログ入力グラフ表示.(仮) ********************************************************************* */ void cmdAinGraph(char *buf) { gr_init(AIN_SCREEN_W,AIN_SCREEN_H,32,0); draw_AnalogFrame(); do { draw_AnalogInput(); Sleep(32); }while(gr_break()==0); gr_close(); }
/********************************************************************* * 抵抗値 グラフ表示.(仮) ********************************************************************* */ void cmdRegGraph(char *buf) { gr_init(AIN_SCREEN_W,AIN_SCREEN_H,32,0); draw_RegistanceFrame(); do { draw_Registance(); Sleep(32); }while(gr_break()==0); gr_close(); }
void test::FSTestFixture::TearDown() { if (_initFlags & INIT_CFILE) { if (_initFlags & INIT_SHIPS) { ship_close(); } if (_initFlags & INIT_GRAPHICS) { if (_initFlags & INIT_FONTS) { font::close(); } io::mouse::CursorManager::shutdown(); bm_unload_all(); gr_close(); } if (_initFlags & INIT_MOD_TABLE) { // Reset mod settings again so that subsequent tests don't get broken mod_table_reset(); } cfile_close(); } timer_close(); lcl_close(); os_cleanup(); #ifndef NDEBUG outwnd_close(); #endif // although the comment in cmdline.cpp said this isn't needed, // Valgrind disagrees (quite possibly incorrectly), but this is just cleaner if (Cmdline_mod != NULL) { delete[] Cmdline_mod; Cmdline_mod = NULL; } }
/* * close_files - close and unlock the group/gshadow databases * * If changed is not set, the databases are not closed, and no * changes are committed in the databases. The databases are * unlocked anyway. */ static void close_files (bool changed) { /* * All done. If there were no change we can just abandon any * changes to the files. */ if (changed) { if (gr_close () == 0) { fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, grp_file); fail_exit (E_CANT_UPDATE); } #ifdef SHADOWGRP if (is_shadow && (sgr_close () == 0)) { fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, sgr_file); fail_exit (E_CANT_UPDATE); } #endif } /* * Don't be anti-social - unlock the files when you're done. */ #ifdef SHADOWGRP if (sgr_locked) { 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 */ } sgr_locked = false; } #endif if (gr_locked) { 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 */ } gr_locked = false; } }
static void close_files (void) { if (!gr_close ()) { fprintf (stderr, _("%s: cannot rewrite group file\n"), Prog); fail_exit (E_GRP_UPDATE); } gr_unlock (); #ifdef SHADOWGRP if (is_shadow_grp && !sgr_close ()) { fprintf (stderr, _("%s: cannot rewrite shadow group file\n"), Prog); fail_exit (E_GRP_UPDATE); } if (is_shadow_grp) sgr_unlock (); #endif /* SHADOWGRP */ }
static void arch_close(void) { songs_uninit(); gr_close(); if (!GameArg.CtlNoJoystick) joy_close(); mouse_close(); if (!GameArg.SndNoSound) { digi_close(); } key_close(); SDL_Quit(); }
static void close_files(void) { if (!pw_close()) fprintf(stderr, _("%s: cannot rewrite password file\n"), Prog); #ifdef SHADOWPWD if (is_shadow_pwd && !spw_close()) fprintf(stderr, _("%s: cannot rewrite shadow password file\n"), Prog); #endif #ifdef HAVE_TCFS if (!tcfs_close()) fprintf(stderr, _("%s: cannot rewrite TCFS key file\n"), Prog); #endif if (! gr_close ()) fprintf(stderr, _("%s: cannot rewrite group file\n"), Prog); (void) gr_unlock (); #ifdef SHADOWGRP if (is_shadow_grp && !sgr_close()) fprintf(stderr, _("%s: cannot rewrite shadow group file\n"), Prog); if (is_shadow_grp) (void) sgr_unlock(); #endif #ifdef SHADOWPWD if (is_shadow_pwd) (void) spw_unlock(); #endif #ifdef HAVE_TCFS (void) tcfs_unlock(); #endif (void) pw_unlock(); }
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; }
main() { unsigned int t1, t2, fastest; unsigned int timeb1v, timeb2v, timeb4v, timeb1s, timeb2s, timeb4s; unsigned int timew1v, timew2v, timew4v, timew1s, timew2s, timew4s; unsigned int timed1v, timed2v, timed4v, timed1s, timed2s, timed4s; gr_init( 0 ); timer_init( 0, NULL ); TempBuffer1 = (unsigned char *)(((unsigned int)TempBufferX+0xF) & 0xFFFFFFF0); System4 = (unsigned char *)(((unsigned int)TempBuffer2+0xF) & 0xFFFFFFF0); System2 = (unsigned char *)((unsigned int)System4 + 2); System1 = (unsigned char *)((unsigned int)System4 + 1); Video4 = (unsigned char *)0xA0000; Video2 = (unsigned char *)0xA0002; Video1 = (unsigned char *)0xA0001; t1 = timer_get_microseconds(); gr_linear_movsb(TempBuffer1, Video1, 320*200); t2 = timer_get_microseconds(); t1 = timer_get_microseconds(); gr_linear_movsb(TempBuffer1, Video1, 320*200); t2 = timer_get_microseconds(); fastest = t2-t1; if ((t2-t1) < fastest) fastest = t2-t1; timeb1v = t2 - t1; t1 = timer_get_microseconds(); gr_linear_movsb(TempBuffer1, Video2, 320*200); t2 = timer_get_microseconds(); t1 = timer_get_microseconds(); gr_linear_movsb(TempBuffer1, Video2, 320*200); t2 = timer_get_microseconds(); if ((t2-t1) < fastest) fastest = t2-t1; timeb2v = t2 - t1; t1 = timer_get_microseconds(); gr_linear_movsb(TempBuffer1, Video4, 320*200); t2 = timer_get_microseconds(); t1 = timer_get_microseconds(); gr_linear_movsb(TempBuffer1, Video4, 320*200); t2 = timer_get_microseconds(); if ((t2-t1) < fastest) fastest = t2-t1; timeb4v = t2 - t1; t1 = timer_get_microseconds(); gr_linear_movsb(TempBuffer1, System1, 320*200); t2 = timer_get_microseconds(); t1 = timer_get_microseconds(); gr_linear_movsb(TempBuffer1, System1, 320*200); t2 = timer_get_microseconds(); if ((t2-t1) < fastest) fastest = t2-t1; timeb1s = t2 - t1; t1 = timer_get_microseconds(); gr_linear_movsb(TempBuffer1, System2, 320*200); t2 = timer_get_microseconds(); t1 = timer_get_microseconds(); gr_linear_movsb(TempBuffer1, System2, 320*200); t2 = timer_get_microseconds(); if ((t2-t1) < fastest) fastest = t2-t1; timeb2s = t2 - t1; t1 = timer_get_microseconds(); gr_linear_movsb(TempBuffer1, System4, 320*200); t2 = timer_get_microseconds(); t1 = timer_get_microseconds(); gr_linear_movsb(TempBuffer1, System4, 320*200); t2 = timer_get_microseconds(); if ((t2-t1) < fastest) fastest = t2-t1; timeb4s = t2 - t1; t1 = timer_get_microseconds(); gr_linear_movsw(TempBuffer1, Video1, 320*200); t2 = timer_get_microseconds(); t1 = timer_get_microseconds(); gr_linear_movsw(TempBuffer1, Video1, 320*200); t2 = timer_get_microseconds(); if ((t2-t1) < fastest) fastest = t2-t1; timew1v = t2 - t1; t1 = timer_get_microseconds(); gr_linear_movsw(TempBuffer1, Video2, 320*200); t2 = timer_get_microseconds(); t1 = timer_get_microseconds(); gr_linear_movsw(TempBuffer1, Video2, 320*200); t2 = timer_get_microseconds(); if ((t2-t1) < fastest) fastest = t2-t1; timew2v = t2 - t1; t1 = timer_get_microseconds(); gr_linear_movsw(TempBuffer1, Video4, 320*200); t2 = timer_get_microseconds(); t1 = timer_get_microseconds(); gr_linear_movsw(TempBuffer1, Video4, 320*200); t2 = timer_get_microseconds(); if ((t2-t1) < fastest) fastest = t2-t1; timew4v = t2 - t1; t1 = timer_get_microseconds(); gr_linear_movsw(TempBuffer1, System1, 320*200); t2 = timer_get_microseconds(); t1 = timer_get_microseconds(); gr_linear_movsw(TempBuffer1, System1, 320*200); t2 = timer_get_microseconds(); if ((t2-t1) < fastest) fastest = t2-t1; timew1s = t2 - t1; t1 = timer_get_microseconds(); gr_linear_movsw(TempBuffer1, System2, 320*200); t2 = timer_get_microseconds(); t1 = timer_get_microseconds(); gr_linear_movsw(TempBuffer1, System2, 320*200); t2 = timer_get_microseconds(); if ((t2-t1) < fastest) fastest = t2-t1; timew2s = t2 - t1; t1 = timer_get_microseconds(); gr_linear_movsw(TempBuffer1, System4, 320*200); t2 = timer_get_microseconds(); t1 = timer_get_microseconds(); gr_linear_movsw(TempBuffer1, System4, 320*200); t2 = timer_get_microseconds(); if ((t2-t1) < fastest) fastest = t2-t1; timew4s = t2 - t1; t1 = timer_get_microseconds(); gr_linear_movsd(TempBuffer1, Video1, 320*200); t2 = timer_get_microseconds(); t1 = timer_get_microseconds(); gr_linear_movsd(TempBuffer1, Video1, 320*200); t2 = timer_get_microseconds(); if ((t2-t1) < fastest) fastest = t2-t1; timed1v = t2 - t1; t1 = timer_get_microseconds(); gr_linear_movsd(TempBuffer1, Video2, 320*200); t2 = timer_get_microseconds(); t1 = timer_get_microseconds(); gr_linear_movsd(TempBuffer1, Video2, 320*200); t2 = timer_get_microseconds(); if ((t2-t1) < fastest) fastest = t2-t1; timed2v = t2 - t1; t1 = timer_get_microseconds(); gr_linear_movsd(TempBuffer1, Video4, 320*200); t2 = timer_get_microseconds(); t1 = timer_get_microseconds(); gr_linear_movsd(TempBuffer1, Video4, 320*200); t2 = timer_get_microseconds(); if ((t2-t1) < fastest) fastest = t2-t1; timed4v = t2 - t1; t1 = timer_get_microseconds(); gr_linear_movsd(TempBuffer1, System1, 320*200); t2 = timer_get_microseconds(); t1 = timer_get_microseconds(); gr_linear_movsd(TempBuffer1, System1, 320*200); t2 = timer_get_microseconds(); if ((t2-t1) < fastest) fastest = t2-t1; timed1s = t2 - t1; t1 = timer_get_microseconds(); gr_linear_movsd(TempBuffer1, System2, 320*200); t2 = timer_get_microseconds(); t1 = timer_get_microseconds(); gr_linear_movsd(TempBuffer1, System2, 320*200); t2 = timer_get_microseconds(); if ((t2-t1) < fastest) fastest = t2-t1; timed2s = t2 - t1; t1 = timer_get_microseconds(); gr_linear_movsd(TempBuffer1, System4, 320*200); t2 = timer_get_microseconds(); t1 = timer_get_microseconds(); gr_linear_movsd(TempBuffer1, System4, 320*200); t2 = timer_get_microseconds(); if ((t2-t1) < fastest) fastest = t2-t1; timed4s = t2 - t1; timer_close(); gr_close(); printf( "Relative memory move speeds: \n\n" ); printf( " Vid1 Vid2 Vid4 Sys1 Sys2 Sys4\n" ); printf( "REP MOVSB: %#2.2f %#2.2f %#2.2f %#2.2f %#2.2f %#2.2f\n", RelTime(timeb1v),RelTime(timeb2v),RelTime(timeb4v), RelTime(timeb1s),RelTime(timeb2s),RelTime(timeb4s) ); printf( "REP MOVSW: %#2.2f %#2.2f %#2.2f %#2.2f %#2.2f %#2.2f\n", RelTime(timew1v),RelTime(timew2v),RelTime(timew4v), RelTime(timew1s),RelTime(timew2s),RelTime(timew4s) ); printf( "REP MOVSD: %#2.2f %#2.2f %#2.2f %#2.2f %#2.2f %#2.2f\n", RelTime(timed1v),RelTime(timed2v),RelTime(timed4v), RelTime(timed1s),RelTime(timed2s),RelTime(timed4s) ); printf( "\nA 1.00 corresponds to %d microseconds to move 320x200 unsigned chars.\n", fastest ); return; }
static void get_group (struct group *gr) #endif { struct group const*tmpgr = NULL; #ifdef SHADOWGRP struct sgrp const*tmpsg = NULL; #endif if (gr_open (O_RDONLY) == 0) { fprintf (stderr, _("%s: cannot open %s\n"), Prog, gr_dbname ()); SYSLOG ((LOG_WARN, "cannot open %s", gr_dbname ())); exit (E_NOPERM); } tmpgr = gr_locate (group); if (NULL == tmpgr) { fprintf (stderr, _("%s: group '%s' does not exist in %s\n"), Prog, group, gr_dbname ()); exit (E_BAD_ARG); } *gr = *tmpgr; gr->gr_name = xstrdup (tmpgr->gr_name); gr->gr_passwd = xstrdup (tmpgr->gr_passwd); gr->gr_mem = dup_list (tmpgr->gr_mem); if (gr_close () == 0) { fprintf (stderr, _("%s: failure while closing read-only %s\n"), Prog, gr_dbname ()); SYSLOG ((LOG_ERR, "failure while closing read-only %s", gr_dbname ())); exit (E_NOPERM); } #ifdef SHADOWGRP if (is_shadowgrp) { if (sgr_open (O_RDONLY) == 0) { fprintf (stderr, _("%s: cannot open %s\n"), Prog, sgr_dbname ()); SYSLOG ((LOG_WARN, "cannot open %s", sgr_dbname ())); exit (E_NOPERM); } tmpsg = sgr_locate (group); if (NULL != tmpsg) { *sg = *tmpsg; sg->sg_name = xstrdup (tmpsg->sg_name); sg->sg_passwd = xstrdup (tmpsg->sg_passwd); sg->sg_mem = dup_list (tmpsg->sg_mem); sg->sg_adm = dup_list (tmpsg->sg_adm); } else { sg->sg_name = xstrdup (group); sg->sg_passwd = gr->gr_passwd; gr->gr_passwd = SHADOW_PASSWD_STRING; /* XXX warning: const */ sg->sg_mem = dup_list (gr->gr_mem); sg->sg_adm = (char **) xmalloc (sizeof (char *) * 2); #ifdef FIRST_MEMBER_IS_ADMIN if (sg->sg_mem[0]) { sg->sg_adm[0] = xstrdup (sg->sg_mem[0]); sg->sg_adm[1] = NULL; } else #endif { sg->sg_adm[0] = NULL; } } if (sgr_close () == 0) { fprintf (stderr, _("%s: failure while closing read-only %s\n"), Prog, sgr_dbname ()); SYSLOG ((LOG_ERR, "failure while closing read-only %s", sgr_dbname ())); exit (E_NOPERM); } } #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; }
/* Clot la fenetre graphique */ void Clore() { gr_close(&fenetreCourante); }
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; }
/* * close_files - close all of the files that were opened * * close_files() closes all of the files that were opened for this new * group. This causes any modified entries to be written out. */ static void close_files (void) { if (gr_close () == 0) { fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, gr_dbname ()); exit (E_GRP_UPDATE); } #ifdef WITH_AUDIT audit_logger (AUDIT_USER_ACCT, Prog, info_group.audit_msg, group_name, AUDIT_NO_ID, SHADOW_AUDIT_SUCCESS); #endif SYSLOG ((LOG_INFO, "group changed in %s (%s)", gr_dbname (), info_group.action)); del_cleanup (cleanup_report_mod_group); cleanup_unlock_group (NULL); del_cleanup (cleanup_unlock_group); #ifdef SHADOWGRP if ( is_shadow_grp && (pflg || nflg)) { if (sgr_close () == 0) { fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, sgr_dbname ()); exit (E_GRP_UPDATE); } #ifdef WITH_AUDIT audit_logger (AUDIT_USER_ACCT, Prog, info_gshadow.audit_msg, group_name, AUDIT_NO_ID, SHADOW_AUDIT_SUCCESS); #endif SYSLOG ((LOG_INFO, "group changed in %s (%s)", sgr_dbname (), info_gshadow.action)); del_cleanup (cleanup_report_mod_gshadow); cleanup_unlock_gshadow (NULL); del_cleanup (cleanup_unlock_gshadow); } #endif /* SHADOWGRP */ if (gflg) { if (pw_close () == 0) { fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, pw_dbname ()); exit (E_GRP_UPDATE); } #ifdef WITH_AUDIT audit_logger (AUDIT_USER_ACCT, Prog, info_passwd.audit_msg, group_name, AUDIT_NO_ID, SHADOW_AUDIT_SUCCESS); #endif SYSLOG ((LOG_INFO, "group changed in %s (%s)", pw_dbname (), info_passwd.action)); del_cleanup (cleanup_report_mod_passwd); cleanup_unlock_passwd (NULL); del_cleanup (cleanup_unlock_passwd); } #ifdef WITH_AUDIT audit_logger (AUDIT_USER_ACCT, Prog, "modifying group", group_name, AUDIT_NO_ID, SHADOW_AUDIT_SUCCESS); #endif }
main(int argc,char **argv) { int ret; grs_bitmap my_bitmap; ubyte my_palette[256*3]; grs_bitmap *bm_list[100]; int n_bitmaps; char key; #if 0 { int new_len,i; new_len=rle_span(new_span,test_span,sizeof(test_span)); printf("old span (%d): ",sizeof(test_span)); for (i=0;i<sizeof(test_span);i++) printf("%d ",test_span[i]); printf("\nnew span (%d): ",new_len); for (i=0;i<new_len;i++) printf("%d ",new_span[i]); exit(0); } #endif #ifdef ANIM_TEST ret = iff_read_animbrush(argv[1],bm_list,100,&n_bitmaps,&my_palette); #else ret = iff_read_bitmap(argv[1],&my_bitmap,BM_LINEAR,&my_palette); bm_list[0] = &my_bitmap; n_bitmaps = 1; #endif printf("ret = %d\n",ret); printf("error message = <%s>",iff_errormsg(ret)); if (ret == IFF_NO_ERROR) { int i; vga_init(); gr_init(); vga_set_mode(SM_320x200C); for (i=0;i<n_bitmaps;) { if (argc>2) { ret = iff_write_bitmap(argv[2],bm_list[i],&my_palette); printf("ret = %d\n",ret); } //gr_pal_setblock(0,256,&my_palette); gr_palette_load(&my_palette); //gr_pal_fade_in(grd_curscreen->pal); //in case palette is blacked gr_ubitmap(0,0,bm_list[i]); key = getch(); if (key=='-') {if (i) i--;} else i++; } gr_close(); for (i=0;i<n_bitmaps;i++) { free(bm_list[i]->bm_data); #ifdef ANIM_TEST free(bm_list[i]); #endif } } }
/* * close_files - close and unlock the password, group and shadow databases */ static void close_files (void) { if (pw_close () == 0) { fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, pw_dbname ()); SYSLOG ((LOG_ERR, "failure while writing changes to %s", pw_dbname ())); fail_exit (EXIT_FAILURE); } if (pw_unlock () == 0) { fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ()); SYSLOG ((LOG_ERR, "failed to unlock %s", pw_dbname ())); /* continue */ } pw_locked = false; if (is_shadow) { if (spw_close () == 0) { fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, spw_dbname ()); SYSLOG ((LOG_ERR, "failure while writing changes to %s", spw_dbname ())); fail_exit (EXIT_FAILURE); } if (spw_unlock () == 0) { fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, spw_dbname ()); SYSLOG ((LOG_ERR, "failed to unlock %s", spw_dbname ())); /* continue */ } spw_locked = false; } 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 (EXIT_FAILURE); } #ifdef ENABLE_SUBIDS if (is_sub_uid && (sub_uid_close () == 0)) { fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, sub_uid_dbname ()); SYSLOG ((LOG_ERR, "failure while writing changes to %s", sub_uid_dbname ())); fail_exit (EXIT_FAILURE); } if (is_sub_gid && (sub_gid_close () == 0)) { fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, sub_gid_dbname ()); SYSLOG ((LOG_ERR, "failure while writing changes to %s", sub_gid_dbname ())); fail_exit (EXIT_FAILURE); } #endif /* ENABLE_SUBIDS */ 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 */ } gr_locked = false; #ifdef SHADOWGRP if (is_shadow_grp) { 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 (EXIT_FAILURE); } 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 */ } sgr_locked = false; } #endif #ifdef ENABLE_SUBIDS if (is_sub_uid) { if (sub_uid_unlock () == 0) { fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sub_uid_dbname ()); SYSLOG ((LOG_ERR, "failed to unlock %s", sub_uid_dbname ())); /* continue */ } sub_uid_locked = false; } if (is_sub_gid) { if (sub_gid_unlock () == 0) { fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sub_gid_dbname ()); SYSLOG ((LOG_ERR, "failed to unlock %s", sub_gid_dbname ())); /* continue */ } sub_gid_locked = false; } #endif /* ENABLE_SUBIDS */ }
/* * grpck - verify group file integrity */ int main (int argc, char **argv) { int arg; int errors = 0; int deleted = 0; int i; struct commonio_entry *gre, *tgre; struct group *grp; int sort_mode = 0; #ifdef SHADOWGRP struct commonio_entry *sge, *tsge; struct sgrp *sgr; int is_shadow = 0; #endif /* * Get my name so that I can use it to report errors. */ Prog = Basename (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); OPENLOG ("grpck"); /* * Parse the command line arguments */ while ((arg = getopt (argc, argv, "qrs")) != EOF) { switch (arg) { case 'q': /* quiet - ignored for now */ break; case 'r': read_only = 1; break; case 's': sort_mode = 1; break; default: usage (); } } if (sort_mode && read_only) { fprintf (stderr, _("%s: -s and -r are incompatibile\n"), Prog); exit (E_USAGE); } /* * Make certain we have the right number of arguments */ #ifdef SHADOWGRP if (optind != argc && optind + 1 != argc && optind + 2 != argc) #else if (optind != argc && optind + 1 != argc) #endif usage (); /* * If there are two left over filenames, use those as the group and * group password filenames. */ if (optind != argc) { grp_file = argv[optind]; gr_name (grp_file); } #ifdef SHADOWGRP if (optind + 2 == argc) { sgr_file = argv[optind + 1]; sgr_name (sgr_file); is_shadow = 1; } else if (optind == argc) is_shadow = sgr_file_present (); #endif /* * Lock the files if we aren't in "read-only" mode */ if (!read_only) { if (!gr_lock ()) { fprintf (stderr, _("%s: cannot lock file %s\n"), Prog, grp_file); if (optind == argc) SYSLOG ((LOG_WARN, "cannot lock %s", grp_file)); closelog (); exit (E_CANT_LOCK); } #ifdef SHADOWGRP if (is_shadow && !sgr_lock ()) { fprintf (stderr, _("%s: cannot lock file %s\n"), Prog, sgr_file); if (optind == argc) SYSLOG ((LOG_WARN, "cannot lock %s", sgr_file)); closelog (); exit (E_CANT_LOCK); } #endif } /* * Open the files. Use O_RDONLY if we are in read_only mode, * O_RDWR otherwise. */ if (!gr_open (read_only ? O_RDONLY : O_RDWR)) { fprintf (stderr, _("%s: cannot open file %s\n"), Prog, grp_file); if (optind == argc) SYSLOG ((LOG_WARN, "cannot open %s", grp_file)); closelog (); exit (E_CANT_OPEN); } #ifdef SHADOWGRP if (is_shadow && !sgr_open (read_only ? O_RDONLY : O_RDWR)) { fprintf (stderr, _("%s: cannot open file %s\n"), Prog, sgr_file); if (optind == argc) SYSLOG ((LOG_WARN, "cannot open %s", sgr_file)); closelog (); exit (E_CANT_OPEN); } #endif if (sort_mode) { gr_sort (); #ifdef SHADOWGRP if (is_shadow) sgr_sort (); #endif goto write_and_bye; } /* * Loop through the entire group file. */ for (gre = __gr_get_head (); 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 (!gre->eptr) { /* * Tell the user this entire line is bogus and ask * them to delete it. */ printf (_("invalid group file entry\n")); printf (_("delete line `%s'? "), gre->line); errors++; /* * prompt the user to delete the entry or not */ if (!yes_or_no ()) 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)); deleted++; __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 (); 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 (!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. */ printf (_("duplicate group entry\n")); printf (_("delete line `%s'? "), gre->line); errors++; /* * prompt the user to delete the entry or not */ if (yes_or_no ()) goto delete_gr; } /* * Check for invalid group names. --marekm */ if (!check_group_name (grp->gr_name)) { errors++; printf (_("invalid group name `%s'\n"), grp->gr_name); } /* * 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 (grp->gr_mem[0] && !grp->gr_mem[1] && *(grp->gr_mem[0]) == '\0') grp->gr_mem[0] = (char *) 0; /* * Make sure each member exists */ for (i = 0; grp->gr_mem[i]; i++) { if (getpwnam (grp->gr_mem[i])) continue; /* * Can't find this user. Remove them * from the list. */ errors++; printf (_("group %s: no user %s\n"), grp->gr_name, grp->gr_mem[i]); printf (_("delete member `%s'? "), grp->gr_mem[i]); if (!yes_or_no ()) continue; SYSLOG ((LOG_INFO, "delete member `%s' group `%s'", grp->gr_mem[i], grp->gr_name)); deleted++; delete_member (grp->gr_mem, grp->gr_mem[i]); gre->changed = 1; __gr_set_changed (); } } #ifdef SHADOWGRP if (!is_shadow) goto shadow_done; /* * Loop through the entire shadow group file. */ for (sge = __sgr_get_head (); sge; sge = sge->next) { /* * Start with the entries that are completely corrupt. They * have no (struct sgrp) entry because they couldn't be * parsed properly. */ if (!sge->eptr) { /* * Tell the user this entire line is bogus and ask * them to delete it. */ printf (_("invalid shadow group file entry\n")); printf (_("delete line `%s'? "), sge->line); errors++; /* * prompt the user to delete the entry or not */ if (!yes_or_no ()) continue; /* * All shadow 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_sg: SYSLOG ((LOG_INFO, "delete shadow line `%s'", sge->line)); deleted++; __sgr_del_entry (sge); continue; } /* * Shadow group structure is good, start using it. */ sgr = sge->eptr; /* * Make sure this entry has a unique name. */ for (tsge = __sgr_get_head (); tsge; tsge = tsge->next) { const struct sgrp *ent = tsge->eptr; /* * Don't check this entry */ if (tsge == sge) continue; /* * Don't check invalid entries. */ if (!ent) continue; if (strcmp (sgr->sg_name, ent->sg_name) != 0) continue; /* * Tell the user this entry is a duplicate of * another and ask them to delete it. */ printf (_("duplicate shadow group entry\n")); printf (_("delete line `%s'? "), sge->line); errors++; /* * prompt the user to delete the entry or not */ if (yes_or_no ()) goto delete_sg; } /* * Make sure this entry exists in the /etc/group file. */ if (!gr_locate (sgr->sg_name)) { printf (_("no matching group file entry\n")); printf (_("delete line `%s'? "), sge->line); errors++; if (yes_or_no ()) goto delete_sg; } /* * Make sure each administrator exists */ for (i = 0; sgr->sg_adm[i]; i++) { if (getpwnam (sgr->sg_adm[i])) continue; /* * Can't find this user. Remove them * from the list. */ errors++; printf (_ ("shadow group %s: no administrative user %s\n"), sgr->sg_name, sgr->sg_adm[i]); printf (_("delete administrative member `%s'? "), sgr->sg_adm[i]); if (!yes_or_no ()) continue; SYSLOG ((LOG_INFO, "delete admin `%s' from shadow group `%s'", sgr->sg_adm[i], sgr->sg_name)); deleted++; delete_member (sgr->sg_adm, sgr->sg_adm[i]); sge->changed = 1; __sgr_set_changed (); } /* * Make sure each member exists */ for (i = 0; sgr->sg_mem[i]; i++) { if (getpwnam (sgr->sg_mem[i])) continue; /* * Can't find this user. Remove them from the list. */ errors++; printf (_("shadow group %s: no user %s\n"), sgr->sg_name, sgr->sg_mem[i]); printf (_("delete member `%s'? "), sgr->sg_mem[i]); if (!yes_or_no ()) continue; SYSLOG ((LOG_INFO, "delete member `%s' from shadow group `%s'", sgr->sg_mem[i], sgr->sg_name)); deleted++; delete_member (sgr->sg_mem, sgr->sg_mem[i]); sge->changed = 1; __sgr_set_changed (); } } shadow_done: #endif /* SHADOWGRP */ /* * All done. If there were no deletions we can just abandon any * changes to the files. */ if (deleted) { write_and_bye: if (!gr_close ()) { fprintf (stderr, _("%s: cannot update file %s\n"), Prog, grp_file); exit (E_CANT_UPDATE); } #ifdef SHADOWGRP if (is_shadow && !sgr_close ()) { fprintf (stderr, _("%s: cannot update file %s\n"), Prog, sgr_file); exit (E_CANT_UPDATE); } #endif } /* * Don't be anti-social - unlock the files when you're done. */ #ifdef SHADOWGRP if (is_shadow) sgr_unlock (); #endif (void) gr_unlock (); nscd_flush_cache ("group"); /* * Tell the user what we did and exit. */ if (errors) printf (deleted ? _("%s: the files have been updated\n") : _("%s: no changes\n"), Prog); exit (errors ? E_BAD_ENTRY : E_OKAY); }