int shm_init() { shm_utmp = (struct UTMPFILE *) get_old_shm(UTMP_SHMKEY, sizeof (struct UTMPFILE)); if (shm_utmp == NULL) return -1; uindexshm = (struct UINDEX *) get_old_shm(UINDEX_SHMKEY, sizeof (struct UINDEX)); if (uindexshm == NULL) return -1; shm_bcache = (struct BCACHE *) get_old_shm(BCACHE_SHMKEY, sizeof (struct BCACHE)); if (shm_bcache == NULL) return -1; shm_ucache = (struct UCACHE *) get_old_shm(UCACHE_SHMKEY, sizeof (struct UCACHE)); if (shm_ucache == NULL) return -1; return 0; }
int initbbsinfo(struct bbsinfo *bbsinfo) { bzero(bbsinfo, sizeof (*bbsinfo)); binfo = bbsinfo; if (chdir(MY_BBS_HOME) == -1) goto ERROR; bbsinfo->bcacheshm = get_old_shm(getBBSKey(BCACHE_SHM), sizeof (struct BCACHE)); if (bbsinfo->bcacheshm == NULL) goto ERROR; bbsinfo->bcache = bbsinfo->bcacheshm->bcache; bbsinfo->ucachehashshm = get_old_shm(getBBSKey(UCACHE_HASH_SHM), sizeof (struct UCACHEHASH)); if (bbsinfo->ucachehashshm == NULL) goto ERROR; bbsinfo->utmpshm = get_old_shm(getBBSKey(UTMP_SHM), sizeof (struct UTMPFILE)); if (bbsinfo->utmpshm == NULL) goto ERROR; bbsinfo->uindexshm = get_old_shm(getBBSKey(UINDEX_SHM), sizeof (struct UINDEX)); if (bbsinfo->uindexshm == NULL) goto ERROR; bbsinfo->wwwcache = get_old_shm(getBBSKey(WWWCACHE_SHM), sizeof (struct WWWCACHE)); if (bbsinfo->wwwcache == NULL) goto ERROR; if (mmapfile(".PASSWDS", &passwd_mf) < 0) goto ERROR; passwdptr = (struct userec *) passwd_mf.ptr; return 0; ERROR: mmapfile(NULL, &passwd_mf); if (bbsinfo->bcacheshm) shmdt(bbsinfo->bcacheshm); if (bbsinfo->ucachehashshm) shmdt(bbsinfo->ucachehashshm); if (bbsinfo->utmpshm) shmdt(bbsinfo->utmpshm); if (bbsinfo->uindexshm) shmdt(bbsinfo->uindexshm); if (bbsinfo->wwwcache) shmdt(bbsinfo->wwwcache); return -1; }
int main(int argc, char *argv[]) { int i; struct user_info *uin; if (argc != 4) { return -1; } shm_utmp = (struct UTMPFILE *) get_old_shm(UTMP_SHMKEY, sizeof (struct UTMPFILE)); if (shm_utmp == NULL) { printf("test\n"); return -2; } i = myatoi(argv[1]); if (i < 0 || i > USHM_SIZE) { printf("test\n"); return -3; } uin = &(shm_utmp->uinfo[i]); if (uin->active && !strcmp(uin->sessionid, argv[2]) && !strcmp(uin->from, argv[3])) { printf("%s\n", uin->userid); return 0; } printf("test\n"); return -4; }