Exemplo n.º 1
0
        private ACinShadow GetOneAC(string shadowLine)
        {
            //string Ac_name
            //string Ac_pwd
            //DateTime Ac_pwdLastChange
            //int Ac_atleastDays
            //int Ac_mustChangeDays
            //int Ac_warningDays
            //int Ac_excuseDays
            //DateTime Ac_disableDate
            //string Reserved

            ACinShadow ac = new ACinShadow();

            string[] ac_9 = shadowLine.Split(':');
            ac.Ac_name          = ac_9[0];
            ac.Ac_pwd           = ac_9[1];
            ac.Ac_pwdLastChange = Common.GetTime(ac_9[2]);
            if (ac_9[3] != null)
            {
                ac.Ac_atleastDays = int.Parse(ac_9[3]);
            }
            if (ac_9[4] != null)
            {
                ac.Ac_mustChangeDays = int.Parse(ac_9[4]);
            }
            if (ac_9[5] != null)
            {
                ac.Ac_warningDays = int.Parse(ac_9[5]);
            }
            if (ac_9[6] != null)
            {
                ac.Ac_excuseDays = int.Parse(ac_9[6]);
            }
            if (ac_9[7] != null)
            {
                ac.Ac_disableDate = Common.GetTime(ac_9[7]);
            }
            if (ac_9[8] != null)
            {
                ac.Reserved = ac_9[8];
            }

            return(ac);
        }
Exemplo n.º 2
0
        public OsAccountInfo OsUsers(string ipDir)
        {
            OsAccountInfo osusers = new OsAccountInfo();
            //string Ipaddress;
            //string Ostype;
            //bool LoginFile;
            //bool PamFile;
            //bool AcMatching;
            //List<ACinShadow> Acs;


            List <ACinShadow> acList = new List <ACinShadow>();

            //第一个属性Ipaddress
            osusers.Ipaddress = ipDir.Split('\\').Last();
            //第二个属性从excel文件中读取类型与版本号进行判断,excel单元格位置5D(4,3)
            string ostype = Common.ReadExcelCell(ipDir, 4, 3);

            if (ostype.ToLower().Contains("win"))
            {
                osusers.Ostype = "Windows";
            }
            else if (ostype.ToLower().Contains("lin"))
            {
                osusers.Ostype = "Linux";
            }
            else if (ostype.ToLower().Contains("unix"))
            {
                osusers.Ostype = "Unix";
            }
            else if (ostype.ToLower().Contains("hp"))
            {
                osusers.Ostype = "AIX";
            }
            else
            {
                osusers.Ostype = "Unkown";
            }
            //第三\四个属性,判断是否提供"login.defs","system-auth"文件
            if (File.Exists(ipDir + "\\login.defs"))
            {
                osusers.LoginFile = true;
            }
            if (File.Exists(ipDir + "\\system-auth"))
            {
                osusers.PamFile = true;
            }

            //检查第五个属性,需要判断"passwd"和"shadow"两个文件中的行数是否一致

            if (File.Exists(ipDir + "passwd") && File.Exists(ipDir + "shadow"))
            {
                List <string> readPasswd = Common.ReadTxtContent(ipDir + "passwd");
                List <string> readShadow = Common.ReadTxtContent(ipDir + "shadow");
                if (readPasswd.Count == readShadow.Count)
                {
                    osusers.AcMatching = true;

                    //获取第六个属性,截取"shadow"文件中所有有效的用户名
                    List <string> txtSplit = new List <string>();
                    foreach (string txt in readShadow)
                    {
                        ACinShadow acinfo = new ACinShadow();
                        if (txt.Contains(":$"))
                        {
                            acList.Add(GetOneAC(txt));
                        }
                    }
                    osusers.Acs = acList;
                }
            }
            return(osusers);
        }