TONT 35213 为什么 CreateProcess 函数会做自动修正?

原文链接:https://devblogs.microsoft.com/oldnewthing/20050623-03/?p=35213

Programs that weren’t designed to handle long file names would make mistakes like taking the path to the executable and writing it into the registry, unaware that the path might contain a space that needs quoting. (Spaces—while technically legal—were extremely rare in SFN paths.) The CreateProcess function had to decide whether to “autocorrect” these invalid paths or to let those programs simply stop working.

在设计阶段没有考虑处理长文件名的应用程序,在实际运行时处理诸如获取可执行文件路径、并将其写入注册表时可能出现一些纰漏,因为其意识不到路径中可能包含空格,需要用(英文)引号包裹起来。(虽然在短文件名体系下的路径中包含空格是合法的,但这种情况极为罕见)。CreateProcess 函数不得不做出一些(额外的)努力,来判定是为这些无效路径做一些『自动修正』,还是放任其停止工作算了。

This is the battle between pragmatism and purity.

这是一场有关实用主义与纯粹主义的论战。

Purity says, “Let them suffer for their mistake. We’re not going to sully our beautiful architecture to accomodate such stupidity.” Of course, such an attitude comes with a cost: People aren’t going to use your “pure” system if it can’t run the programs that they require.

纯粹主义者说,『让那些程序去承担自己犯下的错误吧,我们不应该为了适应这种愚蠢的做法而玷污我们华丽的架构。』当然了,这种态度的代价就是:当人们无法运行所需的程序时,是不会去选用你那所谓『纯粹』的系统的。

Put another way, it doesn’t matter how great your 1.0 version is if you don’t survive long enough to make a 2.0.

换个角度来说,要是你活不到出2.0版本的时候的话,不管你的1.0版有多伟大都没什么意义。

Your choice is between “being pure and unpopular” or “being pragmatic and popular”. Look at all the wonderful technologies that died for lack of popularity despite technical superiority. Sony Betamax. Mattel Intellivision. (And, in the United States: The metric system.)

你需要在『纯粹但无人问津』和『活跃且广为接受』做出选择。回顾一下那些虽然技术上优越、但由于缺乏流行度最终悻悻而终的技术吧。Sony Betamax,Mattel Intellivison都是例子。(在美国,还有公制系统也一样。)

Electric cars are another example. As great as electric cars are, they never reached any significant market success. Only after conceding to popularity and “sullying” their “purity” by adding a gasoline hybrid engine did they finally gain acceptance.

电动汽车是另一个例子(译注:本文撰写时2005年)。虽然电动汽车这个概念很先进,但却从来没有取得任何商业上的成功,只有在面向大众时做出退让、通过增加油电混动引擎而『玷污』了其『纯粹性』之后,才最终被人们所接受。

I see this happening over and over again. A product team that, hypothetically, makes automated diagramming software, says, “I can’t believe we’re losing to Z. Sure, Z’s diagrams may be fast and snazzy, but ours gets <subtle detail> right, and when you go to <extreme case> their diagrams come out a little distorted, and they’re faster only because they don’t try to prevent X and Y from overlapping each other in <scenario Q>. We’re doing all those things; that’s why we’re slower, but that’s also why we’re better. Those people over at Z just don’t ‘get it’.”

我已经看到类似的事情发生了一次又一次:假设有某个研发了一款自动图表软件的产品团队声称:『简直难以置信我们会输给Z公司。是啊,Z的图表软件的确是快了一点、时髦了一点,但我们的产品在(某个细枝末节)上做了正确的事,而且在(某个极端条件下)时,Z公司的软件生成的图表会有点扭曲,何况他们的软件之所以快,是因为他们没有再(场景Q)下避免X和Y重叠。我们把这一切都考虑到了,所以我们的软件会慢了一点,但这也是我们的软件更优的原因。那些吹捧Z公司软件的人根本不懂“这些”。』

Guess what. People are voting with their wallets, and right now their wallets are saying that Z is better in spite of all those “horrible flaws”. Whatever part of “it” they don’t get, it’s certainly not the “make lots of people so happy that they send you money” part.

你猜怎么着,人们是用钱包来投票的,而当下他们的钱包正在呐喊『Z公司的软件更好』而无视了那些“可怕的缺点”。不管这些人不懂的“那些”是什么,肯定不是“让很多人用得开心所以送钱给你”这部分。

TONT 35253 日期/时间控制面板不是当日历用的

原文链接:https://devblogs.microsoft.com/oldnewthing/20050621-04/?p=35253

Although many people use the Date/Time control panel to flip through a calendar, that’s not what it is for. In fact, if you use it that way, you can create all sorts of havoc!

尽管有很多人都用『日期/时间设置』控制面板来翻看日历,但这并不是其设计初衷。实际上,如果那样操作的话,还会造成各种大破坏呢!

In its original incarnation in Windows 95, the Date/Time control panel changed your date and time. If you clicked through the calendar to see next month, you actually changed your system clock to next month. If you changed your mind and clicked “Cancel”, the Date/Time control panel undid its changes and restored the date to the original date.

在 Windows 95 的『日期/时间设置』控制面板里,其是用来修改系统的日期和时间设置的。如果在里面的日历上点击查看下个月的话,实际上已经立刻将系统日期修改为下个月了,此时如果你改变主意点击『取消』按钮的话,『日期/时间设置』控制面板会撤销你的设置,并将系统事件调回修改之前的值。

In other words, here’s what happened, step by step:

换句话说,以下是在你操作期间会一步一步发生的事情:

  • On April 1, you open the Date/Time control panel.
    4月1日,你打开了『日期/时间设置』控制面板。
  • You change the month to May. The Date/Time control panel changes your system date to May 1. If you are running an appointment calendar program, all appointments from the month of April will fire. (For example, your April 15th alarm to remind you to file your income taxes.) You are annoyed by all these alerts and you cancel them.
    你(为了查看日历而)将月份改到了5月,而『日期/时间设置』控制面板也将系统日期改到了5月1日。如果你的系统上安装了日程提醒软件,所有4月份的安排此时都会被激活。(例如,你设置了4月15日提醒自己报税。)你被这些提醒吵到了,于是将它们全部取消掉了。
  • You decide you didn’t want to change the month to May after all and click Cancel.
    你决定实际上并不是要将系统日期修改为5月,于是点击了『取消』。
  • The Date/Time control panel changes the date back to April 1.
    『日期/时间设置』控制面板将日期改回了4月1日。
  • On April 15th, your income tax alarm fails to fire because you cancelled it, remember?
    在4月15日,报税的提醒并没有被激活,因为你之前将它取消掉了,还记得吗?

In other words, the Date/Time control panel was not designed for letting you flip through a calendar. It was designed for changing the system date and time.

换句话说,『日期/时间设置』控制面板的设计并不是让你用来翻日历的,而是用来修改系统的日期和时间的。

Unaware of its design, people have been using the Date/Time control panel as if it were a calendar, not realizing that it was doing all sorts of scary things behind the scenes. It’s like using a cash register as an adding machine. Sure, it does a great job of adding numbers together, but you’re also messing up the accounting back at the main office!

然而,在没有意识到这个设计的前提下,人们一直把『日期/时间设置』控制面板当日历来用,而并没有意识到背后正在发生的、各种可怕的事情。这就像用收款机当加法计算器一样。没错,它的确能把将数字加到一起这件事做得很好,但公司的会计可就要炸锅了。

For Windows 2000, in reluctant recognition of the way people had been mis-using the Date/Time control panel, it was rewritten so that it doesn’t change the system time until you hit the Apply button.

直到 Windows 2000 以后,意识到人们对『日期/时间设置』控制面板的误用,虽然很不情愿,但开发人员还是对其进行了重新编写,使其变成只有在点击『应用』按钮后,新的日期、时间设置才会生效了。

Aaron Margosis shows you how to grant a user permission to change the system date and time without having to make them a full administrator.

Aaron Margosis 在他的文章中介绍了如何获得用户授权来修改系统的日期和时间,而不必将用户提升为具有完全权限的系统管理员

(译注:我怎么感觉用户的直觉好像没什么问题,反倒是微软原本的设计过于超前啊……)

TONT 35393 为什么控制面板里的程序和属性页不会出现在任务栏上?

原文链接:https://devblogs.microsoft.com/oldnewthing/20050608-36/?p=35393

Control panel programs and property sheets don’t show up in the taskbar. Why not?

控制面板中的程序,以及各种属性页(译注:如文件属性、文件夹属性等)不会在任务栏中显示,为什么呢?

As I recall, the explanation was that control panel programs and property sheets aren’t applications. They are auxiliary helper windows that assist you with a task, but they aren’t a program in their own right. Therefore, they don’t get a taskbar button.

根据我的记忆,这是由于控制面板里的程序和属性页并不是应用程序。它们是用来协助你完成一项任务的辅助窗口,但其自身并非独立的程序,因此它们就不会有任务栏按钮。

I’ve always been kind of suspicious of that explanation, but there it is, make of it what you will. (I don’t mind the behavior—putting them in the taskbar just creates clutter—but the explanation I found kind of wanting.)

我对这种解释也心存疑虑,不过话就放在这儿,你可以按自己的想法理解。(我对这样的设计并不在乎——将这些内容在任务栏上再开一个按钮显得很累赘——但还是觉得这样的解释有一定的必要性存在。)

(译注:Windows 10 的相关设计已经做出了大幅改变,这里看看就好)

TONT 35653 微软的企业网络:比『地狱』还要恐怖1.7倍

原文链接:https://devblogs.microsoft.com/oldnewthing/20050512-48/?p=35653

Today I’m going to tell a story from 1996. Why? Because I can.

这回我要讲一个1996年的故事。为什么呢?因为我想这么做。

One of the tests performed by Windows Hardware Quality Labs (WHQL) was the NCT packet stress test which had the nickname “Hell”. The purpose of the test was to flood a network card with an insane number of packets, in order to see how it handled extreme conditions. It uncovered packet-dropping bugs, timing problems, all sorts of great stuff. Network card vendors used it to determine what size internal hardware buffers should be in order to cover “all reasonable network traffic scenarios”.

Windows硬件设备质量实验室(WHQL)日常进行的其中一项测试是NCT数据包压力测试(译注:没有找到NCT具体指什么,哪位朋友了解请赐教),而这项测试被冠了个昵称叫『地狱』(Hell)。这项测试的目的是让一块网卡去处理数量多到疯狂的数据包,以验证其在极限条件下的表现,而这项测试可以揭露出这块网卡的掉包bug、时序问题等各种各样的毛病。网卡供应商通过这项测试的结果来判定他们的产品硬件缓冲区的大小,以便应对『所有合乎常理的网络流量场景』。

It so happened that at the time this test had currency (1996 era), the traffic on the Microsoft corporate network was approximately 1.7 times worse than the NCT packet stress test. A card could pass the Hell test with flying colors, yet drop 90% of its packets when installed on a computer at Microsoft because the card simply couldn’t keep up with the traffic.

巧合的是,当年这项测试还具备价值时(1996年那时候),运行在微软的企业网络上的流量实际上大约是NCT数据包压力测试的1.7倍之多。某块网卡可能能在『Hell』测试中获得漂亮的分数,但将其安装在微软内部的机器上的时候仍然会有90%的丢包率,仅仅是因为这块网卡实在承受不住那么大的流量。

The open secret among network card vendors was, “If you want your card to work with Windows, submit one card to WHQL and send another to a developer on the Windows team.”

网卡供应商之间的一个公开的秘密是:『如果你想让自己的产品能在 Windows 上运行,那就在向 WHQL 提交样品的同时也给 Windows 开发组的工程师也送一块。』

(This rule applied to hardware other than network cards. I was “gifted” a sound card from a major manufacturer and installed it on my main machine. It wasn’t long before I found and fixed a crashing bug in their driver.)

(这条规矩在网卡之外的硬件上也适用。我就曾经被『赠予』了一块某大厂的声卡,于是就将其装在了我的机器上。没过多久,我就发现并修复了这块声卡的驱动里一个会导致崩溃的bug。)

TONT 35713 当人们要将安全漏洞作为功能的时候:窃取密码

原文链接:https://devblogs.microsoft.com/oldnewthing/20050504-52/?p=35713

Sometimes people ask for features that are such blatant security holes I don’t know what they were thinking.

有些时候,有些人提出的功能需求完全就是安全漏洞,真不知道这些人脑子里都在想什么。

Is there a way to get the current user’s password? I have a program that does some stuff, then reboots the system, and I want to have the current user’s password so I can log that user back in when I’m done, then my program can resume its operation.

有没有办法获取当前用户的密码呢?我的程序会进行一些操作,然后重新启动系统,这时候我希望能获得用户的密码,这样重启完成后就能替用户进行登录,然后我的程序就能继续执行剩下的操作了。

(Sometimes they don’t bother explaining why they need the user’s password; they just ask for it.)

(有时候这些人连为什么需要用户的密码都懒得解释,就只是要而已。)

Imagine the fantastic security hole if this were possible. Anybody could write a program that steals your password without even having to trick you into typing it. They would just call the imaginary GetPasswordOfCurrentUser function and bingo! they have your password.

想象一下如果这件事成为可能的话,会产生一个多么美妙的安全漏洞。任何人都可以写一段程序来窃取你的密码,甚至不需要欺骗你把密码输进去,只需要调用那个虚构的 GetPasswordOfCurrentUser 方法就好了,一转眼,他们就拥有了你的密码。

For another angle on credential-stealing, read Larry Osterman‘s discussion of why delegation doesn’t work over the network.

或者也可以换个角度来观察凭据窃取这个问题,可以读一读  Larry Osterman 关于为什么代理认证在(内部)网络上行不通的文章。

Even if you didn’t want the password itself but merely some sort of “cookie” that could be used to log the user on later, you still have a security hole. Let’s call this imaginary function GetPasswordCookieOfCurrentUser; it returns a “cookie” that can be used to log the user on instead of using their password.

即便你不是想要密码本身,只是想要个某种形式的『Cookie』用于稍后替用户登录,这样操作同样也是一个安全漏洞。姑且将这个想象中的方法叫做 GetPasswordCookieOfCurrentUser,调用之会返回一个『Cookie』可以在稍后用于替用户登录,而不是直接返回用户的密码。

This is just a thinly-disguised GetPasswordOfCurrentUser because that “cookie” is equivalent to a password. Log on with the cookie and you are now that person.

这不过是前述的 GetPasswordOfCurrentUser 稍稍改头换面了一下而已,因为这个『Cookie』等同于密码,用这个『Cookie』登录之后你就是用户本人了。

(译注:Windows 10 看上去已经有了这篇15年前的文章描述的功能了——设置—账户—登录选项—『更新或重启后,使用我的登录信息自动完成设备设置并重新打开我的应用』,但仅限于系统更新或由系统发起的设备配置,而不是像这篇文章说的那样可以由第三方程序使用,且如果本机加入了域或应用了组策略,则该功能不可用。点击这里查看官方说明。)