int vfs_get_user_ntquota_list(files_struct *fsp, SMB_NTQUOTA_LIST **qt_list) { struct passwd *usr; TALLOC_CTX *mem_ctx = NULL; if (!fsp||!fsp->conn||!qt_list) return (-1); *qt_list = NULL; if ((mem_ctx=talloc_init("SMB_USER_QUOTA_LIST"))==NULL) { DEBUG(0,("talloc_init() failed\n")); return (-1); } sys_setpwent(); while ((usr = sys_getpwent()) != NULL) { SMB_NTQUOTA_STRUCT tmp_qt; SMB_NTQUOTA_LIST *tmp_list_ent; DOM_SID sid; ZERO_STRUCT(tmp_qt); if (allready_in_quota_list((*qt_list),usr->pw_uid)) { DEBUG(5,("record for uid[%ld] allready in the list\n",(long)usr->pw_uid)); continue; } uid_to_sid(&sid, usr->pw_uid); if (vfs_get_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &tmp_qt)!=0) { DEBUG(5,("no quota entry for sid[%s] path[%s]\n", sid_string_static(&sid),fsp->conn->connectpath)); continue; } DEBUG(15,("quota entry for id[%s] path[%s]\n", sid_string_static(&sid),fsp->conn->connectpath)); if ((tmp_list_ent=TALLOC_ZERO_P(mem_ctx,SMB_NTQUOTA_LIST))==NULL) { DEBUG(0,("TALLOC_ZERO() failed\n")); *qt_list = NULL; talloc_destroy(mem_ctx); return (-1); } if ((tmp_list_ent->quotas=TALLOC_ZERO_P(mem_ctx,SMB_NTQUOTA_STRUCT))==NULL) { DEBUG(0,("TALLOC_ZERO() failed\n")); *qt_list = NULL; talloc_destroy(mem_ctx); return (-1); } tmp_list_ent->uid = usr->pw_uid; memcpy(tmp_list_ent->quotas,&tmp_qt,sizeof(tmp_qt)); tmp_list_ent->mem_ctx = mem_ctx; DLIST_ADD((*qt_list),tmp_list_ent); } sys_endpwent(); return 0; }
int main (int argc, char **argv) { struct passwd *pw; int found = 0; int num_users, i; /* Test getpwent() without setpwent() */ for (i = 0; i < 100; i++) { pw = sys_getpwent(); /* This is supposed to work */ #if 0 if (pw != NULL) { printf("FAIL: getpwent() with no setpwent()\n"); return 1; } #endif } /* Work out how many user till first domain user */ num_users = 0; sys_setpwent(); while (1) { pw = sys_getpwent(); num_users++; if (pw == NULL) break; if (strchr(pw->pw_name, '/')) { found = 1; break; } } if (!found) { printf("FAIL: could not find any domain users\n"); return 1; } /* Test stopping getpwent in the middle of a set of users */ sys_endpwent(); /* Test setpwent() without any getpwent() calls */ sys_setpwent(); for (i = 0; i < (num_users - 1); i++) { sys_getpwent(); } sys_endpwent(); /* Test lots of setpwent() calls */ sys_setpwent(); for (i = 0; i < (num_users - 1); i++) { sys_getpwent(); } for (i = 0; i < 100; i++) { sys_setpwent(); } /* Test lots of endpwent() calls */ sys_setpwent(); for (i = 0; i < (num_users - 1); i++) { sys_getpwent(); } for (i = 0; i < 100; i++) { sys_endpwent(); } /* Everything's cool */ printf("PASS\n"); return 0; }