/* * win_chgrp: ファイルとディレクトリのプライマリグループを変更する。 * 「win_chgrp NTAccount名 ファイルもしくはディレクトリ名」とする。 * オプションは一つずつ別々に書く。 * -Rで再帰的にディレクトリを下っていく。 * -vで変更に用いたグループ名やパス名を表示。 * -Nの指定もしくはNTAccount名に-を書くことで、実際の変更は行わない。 * -fはエラー無視のつもりだが試していない。 * -Oは操作対象が所有者になる。-Gはグループ。 * ワイルドカードには対応しない。 * ファイル名に-を書くと、標準入力からパス名を取り込む。 */ using System; using System.IO; using System.Security.AccessControl; using System.Security.Principal; class win_chgrp { private static bool recursize = false; private static bool force = false; private static bool verbose = false; private static bool donothing = false;  private static bool chown = false; public static void Main(string[] argv) { int i; int index; for(index=0;index < argv.Length;index++){ if(argv[index] == "-R"){ recursize = true; } else if(argv[index] == "-f"){ force = true; } else if(argv[index] == "-v"){ verbose = true; } else if(argv[index] == "-N"){ donothing = true; } else if(argv[index] == "-O"){ chown = true; } else if(argv[index] == "-G"){ chown = false; } else { break; } } if(index >= argv.Length) usage(null); if(argv[index] == "-") donothing = true; NTAccount nta = new NTAccount(argv[index]); index++; for(i=index;i "+ir+"):"+path); } if(!donothing){ if(chown) fs.SetOwner(ir); else fs.SetGroup(ir); File.SetAccessControl(path, fs); } } catch(Exception e){ if(!force) throw e; } } if(Directory.Exists(path)){ try{ DirectorySecurity ds = Directory.GetAccessControl(path); if(verbose){ IdentityReference old_ir = ds.GetGroup(typeof(NTAccount)); Console.WriteLine("(d)("+old_ir+" -> "+ir+"):"+path); } if(!donothing){ ds.SetGroup(ir); Directory.SetAccessControl(path, ds); } } catch(Exception e){ if(!force) throw e; } if(recursize){ try{ string[] dirs = Directory.GetDirectories(path); for(i=0;i